OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4NetIOUDP::BinAddr Struct Reference

Public Member Functions

 BinAddr ()
 
 BinAddr (const C4NetIO::addr_t &addr)
 
 operator C4NetIO::addr_t () const
 

Public Attributes

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

Detailed Description

Definition at line 2294 of file C4NetIO.cpp.

Constructor & Destructor Documentation

C4NetIOUDP::BinAddr::BinAddr ( )
inline

Definition at line 2296 of file C4NetIO.cpp.

2296 : type(0) {}
C4NetIOUDP::BinAddr::BinAddr ( const C4NetIO::addr_t addr)
inline

Definition at line 2297 of file C4NetIO.cpp.

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

2298  {
2299  switch (addr.GetFamily())
2300  {
2302  {
2303  type = 1;
2304  auto addr4 = static_cast<const sockaddr_in*>(&addr);
2305  static_assert(sizeof(v4) == sizeof(addr4->sin_addr), "unexpected IPv4 address size");
2306  memcpy(&v4, &addr4->sin_addr, sizeof(v4));
2307  break;
2308  }
2310  {
2311  type = 2;
2312  auto addr6 = static_cast<const sockaddr_in6*>(&addr);
2313  static_assert(sizeof(v6) == sizeof(addr6->sin6_addr), "unexpected IPv6 address size");
2314  memcpy(&v6, &addr6->sin6_addr, sizeof(v6));
2315  break;
2316  }
2317  default:
2318  assert(!"Unexpected address family");
2319  }
2320  port = addr.GetPort();
2321  }
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:526
uint16_t GetPort() const
Definition: C4NetIO.cpp:548

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 2323 of file C4NetIO.cpp.

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

2324  {
2325  C4NetIO::addr_t result;
2326  switch (type)
2327  {
2328  case 1:
2329  {
2330  sockaddr_in addr4 = sockaddr_in();
2331  addr4.sin_family = AF_INET;
2332  memcpy(&addr4.sin_addr, &v4, sizeof(v4));
2333  result.SetAddress(reinterpret_cast<sockaddr*>(&addr4));
2334  break;
2335  }
2336  case 2:
2337  {
2338  sockaddr_in6 addr6 = sockaddr_in6();
2339  addr6.sin6_family = AF_INET6;
2340  memcpy(&addr6.sin6_addr, &v6, sizeof(v6));
2341  result.SetAddress(reinterpret_cast<sockaddr*>(&addr6));
2342  break;
2343  }
2344  default:
2345  assert(!"Invalid address type");
2346  }
2347  result.SetPort(port);
2348  return result;
2349  }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:370
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:532

Here is the call graph for this function:

Member Data Documentation

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

Definition at line 2351 of file C4NetIO.cpp.

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

uint8_t C4NetIOUDP::BinAddr::type

Definition at line 2352 of file C4NetIO.cpp.

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


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