net/{Allocated,Static}SocketAddress: use IPv[46]Address::SetPort()
This commit is contained in:
parent
77b5b4158c
commit
2089c99348
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue