OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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 2272 of file C4NetIO.cpp.

Constructor & Destructor Documentation

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

Definition at line 2275 of file C4NetIO.cpp.

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

2276  {
2277  switch (addr.GetFamily())
2278  {
2280  {
2281  type = 1;
2282  auto addr4 = static_cast<const sockaddr_in*>(&addr);
2283  static_assert(sizeof(v4) == sizeof(addr4->sin_addr), "unexpected IPv4 address size");
2284  memcpy(&v4, &addr4->sin_addr, sizeof(v4));
2285  break;
2286  }
2288  {
2289  type = 2;
2290  auto addr6 = static_cast<const sockaddr_in6*>(&addr);
2291  static_assert(sizeof(v6) == sizeof(addr6->sin6_addr), "unexpected IPv6 address size");
2292  memcpy(&v6, &addr6->sin6_addr, sizeof(v6));
2293  break;
2294  }
2295  default:
2296  assert(!"Unexpected address family");
2297  }
2298  port = addr.GetPort();
2299  }
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520
uint16_t GetPort() const
Definition: C4NetIO.cpp:542

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 2301 of file C4NetIO.cpp.

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

2302  {
2303  C4NetIO::addr_t result;
2304  switch (type)
2305  {
2306  case 1:
2307  {
2308  sockaddr_in addr4 = sockaddr_in();
2309  addr4.sin_family = AF_INET;
2310  memcpy(&addr4.sin_addr, &v4, sizeof(v4));
2311  result.SetAddress(reinterpret_cast<sockaddr*>(&addr4));
2312  break;
2313  }
2314  case 2:
2315  {
2316  sockaddr_in6 addr6 = sockaddr_in6();
2317  addr6.sin6_family = AF_INET6;
2318  memcpy(&addr6.sin6_addr, &v6, sizeof(v6));
2319  result.SetAddress(reinterpret_cast<sockaddr*>(&addr6));
2320  break;
2321  }
2322  default:
2323  assert(!"Invalid address type");
2324  }
2325  result.SetPort(port);
2326  return result;
2327  }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:526

Here is the call graph for this function:

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

Definition at line 2329 of file C4NetIO.cpp.

References C4NetIO::EndpointAddress::ToString().

2330  {
2331  return static_cast<C4NetIO::addr_t>(*this).ToString();
2332  }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:599

Here is the call graph for this function:

Member Data Documentation

union { ... }
uint16_t C4NetIOUDP::BinAddr::port

Definition at line 2334 of file C4NetIO.cpp.

Referenced by BinAddr(), and operator C4NetIO::addr_t().

uint8_t C4NetIOUDP::BinAddr::type {0}

Definition at line 2335 of file C4NetIO.cpp.

Referenced by BinAddr(), and operator C4NetIO::addr_t().


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