Commit 2089c993 authored by Max Kellermann's avatar Max Kellermann

net/{Allocated,Static}SocketAddress: use IPv[46]Address::SetPort()

parent 77b5b415
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "config.h" #include "config.h"
#include "AllocatedSocketAddress.hxx" #include "AllocatedSocketAddress.hxx"
#include "IPv4Address.hxx"
#include "IPv6Address.hxx"
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include <string.h> #include <string.h>
...@@ -109,15 +111,15 @@ AllocatedSocketAddress::SetPort(unsigned port) noexcept ...@@ -109,15 +111,15 @@ AllocatedSocketAddress::SetPort(unsigned port) noexcept
switch (GetFamily()) { switch (GetFamily()) {
case AF_INET: case AF_INET:
{ {
auto *a = (struct sockaddr_in *)(void *)address; auto &a = *(IPv4Address *)(void *)address;
a->sin_port = htons(port); a.SetPort(port);
return true; return true;
} }
case AF_INET6: case AF_INET6:
{ {
auto *a = (struct sockaddr_in6 *)(void *)address; auto &a = *(IPv6Address *)(void *)address;
a->sin6_port = htons(port); a.SetPort(port);
return true; return true;
} }
} }
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "config.h" #include "config.h"
#include "StaticSocketAddress.hxx" #include "StaticSocketAddress.hxx"
#include "IPv4Address.hxx"
#include "IPv6Address.hxx"
#include "util/StringView.hxx" #include "util/StringView.hxx"
#include <algorithm> #include <algorithm>
...@@ -69,15 +71,15 @@ StaticSocketAddress::SetPort(unsigned port) noexcept ...@@ -69,15 +71,15 @@ StaticSocketAddress::SetPort(unsigned port) noexcept
switch (GetFamily()) { switch (GetFamily()) {
case AF_INET: case AF_INET:
{ {
auto &a = (struct sockaddr_in &)address; auto &a = *(IPv4Address *)(void *)&address;
a.sin_port = htons(port); a.SetPort(port);
return true; return true;
} }
case AF_INET6: case AF_INET6:
{ {
auto &a = (struct sockaddr_in6 &)address; auto &a = *(IPv6Address *)(void *)&address;
a.sin6_port = htons(port); a.SetPort(port);
return true; return true;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment