OpenClonk
C4NetIOUDP::BinAddr Struct Reference

Public Member Functions

 BinAddr ()=default
 
 BinAddr (const C4NetIO::addr_t &addr)
 
 operator C4NetIO::addr_t () const
 
StdStrBuf ToString () const
 

Public Attributes

uint16_t port
 
uint8_t type {0}
 
union {
uint8_t v4 [4]
 
uint8_t v6 [16]
 
}; 
 

Detailed Description

Definition at line 2334 of file C4NetIO.cpp.

Constructor & Destructor Documentation

◆ BinAddr() [1/2]

C4NetIOUDP::BinAddr::BinAddr ( )
default

◆ BinAddr() [2/2]

C4NetIOUDP::BinAddr::BinAddr ( const C4NetIO::addr_t addr)
inline

Definition at line 2337 of file C4NetIO.cpp.

References C4NetIO::HostAddress::GetFamily(), C4NetIO::EndpointAddress::GetPort(), C4NetIO::HostAddress::IPv4, and C4NetIO::HostAddress::IPv6.

2338  {
2339  switch (addr.GetFamily())
2340  {
2342  {
2343  type = 1;
2344  auto addr4 = static_cast<const sockaddr_in*>(&addr);
2345  static_assert(sizeof(v4) == sizeof(addr4->sin_addr), "unexpected IPv4 address size");
2346  memcpy(&v4, &addr4->sin_addr, sizeof(v4));
2347  break;
2348  }
2350  {
2351  type = 2;
2352  auto addr6 = static_cast<const sockaddr_in6*>(&addr);
2353  static_assert(sizeof(v6) == sizeof(addr6->sin6_addr), "unexpected IPv6 address size");
2354  memcpy(&v6, &addr6->sin6_addr, sizeof(v6));
2355  break;
2356  }
2357  default:
2358  assert(!"Unexpected address family");
2359  }
2360  port = addr.GetPort();
2361  }
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520
Here is the call graph for this function:

Member Function Documentation

◆ operator C4NetIO::addr_t()

C4NetIOUDP::BinAddr::operator C4NetIO::addr_t ( ) const
inline

Definition at line 2363 of file C4NetIO.cpp.

References C4NetIO::EndpointAddress::SetAddress(), and C4NetIO::EndpointAddress::SetPort().

2364  {
2365  C4NetIO::addr_t result;
2366  switch (type)
2367  {
2368  case 1:
2369  {
2370  sockaddr_in addr4 = sockaddr_in();
2371  addr4.sin_family = AF_INET;
2372  memcpy(&addr4.sin_addr, &v4, sizeof(v4));
2373  result.SetAddress(reinterpret_cast<sockaddr*>(&addr4));
2374  break;
2375  }
2376  case 2:
2377  {
2378  sockaddr_in6 addr6 = sockaddr_in6();
2379  addr6.sin6_family = AF_INET6;
2380  memcpy(&addr6.sin6_addr, &v6, sizeof(v6));
2381  result.SetAddress(reinterpret_cast<sockaddr*>(&addr6));
2382  break;
2383  }
2384  default:
2385  assert(!"Invalid address type");
2386  }
2387  result.SetPort(port);
2388  return result;
2389  }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
Here is the call graph for this function:

◆ ToString()

StdStrBuf C4NetIOUDP::BinAddr::ToString ( ) const
inline

Definition at line 2391 of file C4NetIO.cpp.

References C4NetIO::EndpointAddress::ToString().

2392  {
2393  return static_cast<C4NetIO::addr_t>(*this).ToString();
2394  }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:604
Here is the call graph for this function:

Member Data Documentation

◆ @65

union { ... }

◆ port

uint16_t C4NetIOUDP::BinAddr::port

Definition at line 2396 of file C4NetIO.cpp.

◆ type

uint8_t C4NetIOUDP::BinAddr::type {0}

Definition at line 2397 of file C4NetIO.cpp.


The documentation for this struct was generated from the following file: