You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
770 B
C++
45 lines
770 B
C++
// SPDX-License-Identifier: BSD-2-Clause
|
|
// author: Max Kellermann <max.kellermann@gmail.com>
|
|
|
|
#include "StaticSocketAddress.hxx"
|
|
#include "IPv4Address.hxx"
|
|
#include "IPv6Address.hxx"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string.h>
|
|
|
|
StaticSocketAddress &
|
|
StaticSocketAddress::operator=(SocketAddress other) noexcept
|
|
{
|
|
size = std::min(other.GetSize(), GetCapacity());
|
|
memcpy(&address, other.GetAddress(), size);
|
|
return *this;
|
|
}
|
|
|
|
#ifdef HAVE_TCP
|
|
|
|
bool
|
|
StaticSocketAddress::SetPort(unsigned port) noexcept
|
|
{
|
|
switch (GetFamily()) {
|
|
case AF_INET:
|
|
{
|
|
auto &a = *(IPv4Address *)(void *)&address;
|
|
a.SetPort(port);
|
|
return true;
|
|
}
|
|
|
|
case AF_INET6:
|
|
{
|
|
auto &a = *(IPv6Address *)(void *)&address;
|
|
a.SetPort(port);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
#endif
|