net/{Allocated,Static}SocketAddress: use IPv[46]Address::SetPort()
This commit is contained in:
@@ -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
|
|||||||
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 @@
|
|||||||
|
|
||||||
#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
|
|||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user