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 @@
#include "config.h"
#include "AllocatedSocketAddress.hxx"
#include "IPv4Address.hxx"
#include "IPv6Address.hxx"
#include "util/StringView.hxx"
#include <string.h>
......@@ -109,15 +111,15 @@ AllocatedSocketAddress::SetPort(unsigned port) noexcept
switch (GetFamily()) {
case AF_INET:
{
auto *a = (struct sockaddr_in *)(void *)address;
a->sin_port = htons(port);
auto &a = *(IPv4Address *)(void *)address;
a.SetPort(port);
return true;
}
case AF_INET6:
{
auto *a = (struct sockaddr_in6 *)(void *)address;
a->sin6_port = htons(port);
auto &a = *(IPv6Address *)(void *)address;
a.SetPort(port);
return true;
}
}
......
......@@ -29,6 +29,8 @@
#include "config.h"
#include "StaticSocketAddress.hxx"
#include "IPv4Address.hxx"
#include "IPv6Address.hxx"
#include "util/StringView.hxx"
#include <algorithm>
......@@ -69,15 +71,15 @@ StaticSocketAddress::SetPort(unsigned port) noexcept
switch (GetFamily()) {
case AF_INET:
{
auto &a = (struct sockaddr_in &)address;
a.sin_port = htons(port);
auto &a = *(IPv4Address *)(void *)&address;
a.SetPort(port);
return true;
}
case AF_INET6:
{
auto &a = (struct sockaddr_in6 &)address;
a.sin6_port = htons(port);
auto &a = *(IPv6Address *)(void *)&address;
a.SetPort(port);
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