OpenClonk
C4NetIO::EndpointAddress Struct Reference

#include <C4NetIO.h>

Inheritance diagram for C4NetIO::EndpointAddress:
[legend]
Collaboration diagram for C4NetIO::EndpointAddress:
[legend]

Classes

class  EndpointAddressPtr
 

Public Types

enum  AddressFamily { IPv6 = AF_INET6, IPv4 = AF_INET, UnknownFamily = 0 }
 
enum  SpecialAddress { Loopback, Any, AnyIPv4 }
 
enum  ToStringFlags { TSF_SkipZoneId = 1, TSF_SkipPort = 2 }
 

Public Member Functions

 EndpointAddress ()
 
 EndpointAddress (const EndpointAddress &other)
 
 EndpointAddress (const HostAddress &host, uint16_t port=IPPORT_NONE)
 
 EndpointAddress (HostAddress::SpecialAddress addr, uint16_t port=IPPORT_NONE)
 
 EndpointAddress (const StdStrBuf &addr)
 
StdStrBuf ToString (int flags=0) const
 
void Clear ()
 
void SetAddress (const sockaddr *addr)
 
void SetAddress (const EndpointAddress &other)
 
void SetAddress (HostAddress::SpecialAddress addr, uint16_t port=IPPORT_NONE)
 
void SetAddress (const HostAddress &host, uint16_t port=IPPORT_NONE)
 
void SetAddress (const StdStrBuf &addr, AddressFamily family=UnknownFamily)
 
HostAddress GetHost () const
 
EndpointAddress AsIPv6 () const
 
EndpointAddress AsIPv4 () const
 
void SetPort (uint16_t port)
 
void SetDefaultPort (uint16_t port)
 
uint16_t GetPort () const
 
bool IsNull () const
 
bool IsNullHost () const
 
const EndpointAddressPtr operator& () const
 
EndpointAddressPtr operator& ()
 
bool operator== (const EndpointAddress &rhs) const
 
bool operator!= (const EndpointAddress &rhs) const
 
 operator sockaddr () const
 
 operator sockaddr_in () const
 
 operator sockaddr_in6 () const
 
void CompileFunc (StdCompiler *comp)
 
AddressFamily GetFamily () const
 
size_t GetAddrLen () const
 
void SetScopeId (int scopeId)
 
int GetScopeId () const
 
void SetHost (const sockaddr *addr)
 
void SetHost (const HostAddress &host)
 
void SetHost (SpecialAddress host)
 
void SetHost (const StdStrBuf &host, AddressFamily family=UnknownFamily)
 
void SetHost (uint32_t host)
 
bool IsMulticast () const
 
bool IsLoopback () const
 
bool IsLocal () const
 
bool IsPrivate () const
 
bool operator== (const HostAddress &rhs) const
 
bool operator!= (const HostAddress &rhs) const
 

Static Public Attributes

static const uint16_t IPPORT_NONE = 0
 

Protected Attributes

union {
sockaddr gen
 
sockaddr_in v4
 
sockaddr_in6 v6
 
}; 
 

Friends

class EndpointAddressPtr
 

Detailed Description

Definition at line 135 of file C4NetIO.h.

Member Enumeration Documentation

◆ AddressFamily

Enumerator
IPv6 
IPv4 
UnknownFamily 

Definition at line 70 of file C4NetIO.h.

71  {
72  IPv6 = AF_INET6,
73  IPv4 = AF_INET,
74  UnknownFamily = 0
75  };

◆ SpecialAddress

Enumerator
Loopback 
Any 
AnyIPv4 

Definition at line 76 of file C4NetIO.h.

77  {
78  Loopback, // IPv6 localhost (::1)
79  Any, // IPv6 any-address (::)
80  AnyIPv4 // IPv4 any-address (0.0.0.0)
81  };

◆ ToStringFlags

Enumerator
TSF_SkipZoneId 
TSF_SkipPort 

Definition at line 83 of file C4NetIO.h.

Constructor & Destructor Documentation

◆ EndpointAddress() [1/5]

C4NetIO::EndpointAddress::EndpointAddress ( )
inline

Definition at line 139 of file C4NetIO.h.

References C4NetIO::HostAddress::Clear().

139 { Clear(); }
Here is the call graph for this function:

◆ EndpointAddress() [2/5]

C4NetIO::EndpointAddress::EndpointAddress ( const EndpointAddress other)
inline

Definition at line 140 of file C4NetIO.h.

140 : HostAddress() { SetAddress(other); }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364

◆ EndpointAddress() [3/5]

C4NetIO::EndpointAddress::EndpointAddress ( const HostAddress host,
uint16_t  port = IPPORT_NONE 
)
inline

Definition at line 141 of file C4NetIO.h.

141 : HostAddress(host) { SetPort(port); }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531

◆ EndpointAddress() [4/5]

C4NetIO::EndpointAddress::EndpointAddress ( HostAddress::SpecialAddress  addr,
uint16_t  port = IPPORT_NONE 
)
inline

Definition at line 142 of file C4NetIO.h.

142 : HostAddress(addr) { SetPort(port); }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531

◆ EndpointAddress() [5/5]

C4NetIO::EndpointAddress::EndpointAddress ( const StdStrBuf addr)
inlineexplicit

Definition at line 143 of file C4NetIO.h.

References C4NetIO::HostAddress::Clear(), C4NetIO::HostAddress::ToString(), and C4NetIO::HostAddress::UnknownFamily.

143 { SetAddress(addr); }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
Here is the call graph for this function:

Member Function Documentation

◆ AsIPv4()

C4NetIO::EndpointAddress C4NetIO::EndpointAddress::AsIPv4 ( ) const

Definition at line 341 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv4().

Referenced by C4Network2::OnPuncherConnect(), C4Network2Address::SetAddr(), and C4Network2Address::SetIP().

342 {
344 }
C4NetIO::HostAddress AsIPv4() const
Definition: C4NetIO.cpp:325
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AsIPv6()

C4NetIO::EndpointAddress C4NetIO::EndpointAddress::AsIPv6 ( ) const

Definition at line 336 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv6().

Referenced by C4NetIOUDP::Peer::SendDirect().

337 {
339 }
C4NetIO::HostAddress AsIPv6() const
Definition: C4NetIO.cpp:303
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Clear()

void C4NetIO::EndpointAddress::Clear ( )

Definition at line 231 of file C4NetIO.cpp.

References C4NetIO::HostAddress::Clear().

Referenced by C4NetIOTCP::Accept(), C4Network2Address::CompileFunc(), C4AulDebug::Listen(), C4Network2IO::OnDisconn(), and C4AulDebug::SetAllowed().

232 {
235 }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileFunc()

void C4NetIO::EndpointAddress::CompileFunc ( StdCompiler comp)

Definition at line 618 of file C4NetIO.cpp.

References StdCompiler::isDeserializer(), C4NetIO::HostAddress::ToString(), C4NetIO::HostAddress::TSF_SkipZoneId, and StdCompiler::Value().

619 {
620  if (!comp->isDeserializer())
621  {
623  comp->Value(val);
624  } else {
625  StdStrBuf val;
626  comp->Value(val);
627  SetAddress(val);
628  }
629 }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:604
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual bool isDeserializer()
Definition: StdCompiler.h:53
Here is the call graph for this function:

◆ GetAddrLen()

size_t C4NetIO::HostAddress::GetAddrLen ( ) const
inherited

Definition at line 526 of file C4NetIO.cpp.

References C4NetIO::HostAddress::GetFamily(), and C4NetIO::HostAddress::IPv4.

Referenced by C4NetIOTCP::Accept(), C4NetIOTCP::Bind(), C4NetIOTCP::Connect(), C4NetIO::HostAddress::HostAddress(), C4NetIOTCP::Listen(), C4NetIOSimpleUDP::Send(), and C4NetIO::HostAddress::ToString().

527 {
528  return GetFamily() == IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
529 }
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFamily()

◆ GetHost()

HostAddress C4NetIO::EndpointAddress::GetHost ( ) const
inline

Definition at line 155 of file C4NetIO.h.

References C4NetIO::HostAddress::AsIPv4(), C4NetIO::HostAddress::AsIPv6(), and C4NetIO::HostAddress::IsNull().

Referenced by C4Network2IO::doAutoAccept(), and C4AulDebug::Listen().

155 { return *this; } // HostAddress copy ctor slices off port information
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPort()

uint16_t C4NetIO::EndpointAddress::GetPort ( ) const

Definition at line 547 of file C4NetIO.cpp.

Referenced by C4Network2Client::AddAddrFromPuncher(), C4NetIOUDP::BinAddr::BinAddr(), C4Network2IOConnection::getPeerAddr(), C4Network2Address::getPort(), C4NetIOSimpleUDP::InitBroadcast(), C4NetIOUDP::InitBroadcast(), C4AulDebug::Listen(), C4NetIOUDP::Peer::OnRecv(), and SetAddress().

548 {
549  switch (gen.sa_family)
550  {
551  case AF_INET: return ntohs(v4.sin_port);
552  case AF_INET6: return ntohs(v6.sin6_port);
553  }
554  assert(!"Shouldn't reach this");
555  return IPPORT_NONE;
556 }
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
Here is the caller graph for this function:

◆ GetScopeId()

int C4NetIO::HostAddress::GetScopeId ( ) const
inherited

Definition at line 296 of file C4NetIO.cpp.

Referenced by C4Network2Client::AddLocalAddrs(), C4NetIO::HostAddress::HostAddress(), and C4Network2Client::SendAddresses().

297 {
298  if (gen.sa_family == AF_INET6)
299  return v6.sin6_scope_id;
300  return 0;
301 }
Here is the caller graph for this function:

◆ IsLocal()

bool C4NetIO::HostAddress::IsLocal ( ) const
inherited

Definition at line 260 of file C4NetIO.cpp.

Referenced by C4NetIO::HostAddress::HostAddress().

261 {
262  if (gen.sa_family == AF_INET6)
263  return IN6_IS_ADDR_LINKLOCAL(&v6.sin6_addr) != 0;
264  // We don't really care about local 169.256.0.0/16 addresses here as users will either have a
265  // router doing DHCP (which will prevent usage of these addresses) or have a network that
266  // doesn't care about IP and IPv6 link-local addresses will work.
267  return false;
268 }
Here is the caller graph for this function:

◆ IsLoopback()

bool C4NetIO::HostAddress::IsLoopback ( ) const
inherited

Definition at line 251 of file C4NetIO.cpp.

Referenced by C4NetIO::GetLocalAddresses(), and C4NetIO::HostAddress::HostAddress().

252 {
253  if (gen.sa_family == AF_INET6)
254  return IN6_IS_ADDR_LOOPBACK(&v6.sin6_addr) != 0;
255  if (gen.sa_family == AF_INET)
256  return (ntohl(v4.sin_addr.s_addr) >> 24) == 127;
257  return false;
258 }
Here is the caller graph for this function:

◆ IsMulticast()

bool C4NetIO::HostAddress::IsMulticast ( ) const
inherited

Definition at line 242 of file C4NetIO.cpp.

Referenced by C4NetIO::HostAddress::HostAddress(), C4NetIOSimpleUDP::InitBroadcast(), and C4NetIOUDP::InitBroadcast().

243 {
244  if (gen.sa_family == AF_INET6)
245  return IN6_IS_ADDR_MULTICAST(&v6.sin6_addr) != 0;
246  if (gen.sa_family == AF_INET)
247  return (ntohl(v4.sin_addr.s_addr) >> 24) == 239;
248  return false;
249 }
Here is the caller graph for this function:

◆ IsNull()

bool C4NetIO::EndpointAddress::IsNull ( ) const

Definition at line 503 of file C4NetIO.cpp.

Referenced by C4Network2::HandleConnRe(), C4NetIOUDP::InitBroadcast(), C4Network2::InitPuncher(), C4Network2Address::isIPNull(), C4Network2IO::IsPuncherAddr(), C4AulDebug::Listen(), C4Network2IO::OnConn(), C4Network2IO::SendPuncherPacket(), and C4AulDebug::SetAllowed().

504 {
505  return IsNullHost() && GetPort() == IPPORT_NONE;
506 }
bool IsNullHost() const
Definition: C4NetIO.h:164
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
Here is the caller graph for this function:

◆ IsNullHost()

bool C4NetIO::EndpointAddress::IsNullHost ( ) const
inline

Definition at line 164 of file C4NetIO.h.

References C4NetIO::HostAddress::IsNull().

164 { return HostAddress::IsNull(); }
bool IsNull() const
Definition: C4NetIO.cpp:508
Here is the call graph for this function:

◆ IsPrivate()

bool C4NetIO::HostAddress::IsPrivate ( ) const
inherited

Definition at line 270 of file C4NetIO.cpp.

References s.

Referenced by C4NetIO::HostAddress::HostAddress().

271 {
272  // IPv6 unique local address
273  if (gen.sa_family == AF_INET6)
274  return (v6.sin6_addr.s6_addr[0] & 0xfe) == 0xfc;
275  if (gen.sa_family == AF_INET)
276  {
277  uint32_t addr = ntohl(v4.sin_addr.s_addr);
278  uint32_t s = (addr >> 16) & 0xff;
279  switch (addr >> 24)
280  {
281  case 10: return true;
282  case 172: return s >= 16 && s <= 31;
283  case 192: return s == 168;
284  }
285  }
286  return false;
287 }
#define s
Here is the caller graph for this function:

◆ operator sockaddr()

C4NetIO::EndpointAddress::operator sockaddr ( ) const
inline

Definition at line 200 of file C4NetIO.h.

200 { return gen; }

◆ operator sockaddr_in()

C4NetIO::EndpointAddress::operator sockaddr_in ( ) const
inline

Definition at line 201 of file C4NetIO.h.

201 { assert(gen.sa_family == AF_INET); return v4; }

◆ operator sockaddr_in6()

C4NetIO::EndpointAddress::operator sockaddr_in6 ( ) const
inline

Definition at line 202 of file C4NetIO.h.

References CompileFunc().

202 { assert(gen.sa_family == AF_INET6); return v6; }
Here is the call graph for this function:

◆ operator!=() [1/2]

bool C4NetIO::HostAddress::operator!= ( const HostAddress rhs) const
inlineinherited

Definition at line 123 of file C4NetIO.h.

123 { return !(*this == rhs); }

◆ operator!=() [2/2]

bool C4NetIO::EndpointAddress::operator!= ( const EndpointAddress rhs) const
inline

Definition at line 197 of file C4NetIO.h.

197 { return !(*this == rhs); }

◆ operator&() [1/2]

const EndpointAddressPtr C4NetIO::EndpointAddress::operator & ( ) const

Referenced by C4NetIO::HostAddress::Clear().

Here is the caller graph for this function:

◆ operator&() [2/2]

EndpointAddressPtr C4NetIO::EndpointAddress::operator & ( )

◆ operator==() [1/2]

bool C4NetIO::HostAddress::operator== ( const HostAddress rhs) const
inherited

Definition at line 558 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv6().

Referenced by C4NetIO::HostAddress::HostAddress(), and C4NetIO::EndpointAddress::EndpointAddressPtr::operator sockaddr_in6 *().

559 {
560  // Check for IPv4-mapped IPv6 addresses.
561  if (gen.sa_family != rhs.gen.sa_family)
562  return AsIPv6() == rhs.AsIPv6();
563  if (gen.sa_family == AF_INET)
564  return v4.sin_addr.s_addr == rhs.v4.sin_addr.s_addr;
565  if (gen.sa_family == AF_INET6)
566  return memcmp(&v6.sin6_addr, &rhs.v6.sin6_addr, sizeof(v6.sin6_addr)) == 0 &&
567  v6.sin6_scope_id == rhs.v6.sin6_scope_id;
568  assert(!"Shouldn't reach this");
569  return false;
570 }
C4NetIO::HostAddress AsIPv6() const
Definition: C4NetIO.cpp:303
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator==() [2/2]

bool C4NetIO::EndpointAddress::operator== ( const EndpointAddress rhs) const

Definition at line 572 of file C4NetIO.cpp.

573 {
574  if (!HostAddress::operator==(rhs)) return false;
575  if (gen.sa_family == AF_INET)
576  {
577  return v4.sin_port == rhs.v4.sin_port;
578  }
579  else if (gen.sa_family == AF_INET6)
580  {
581  return v6.sin6_port == rhs.v6.sin6_port &&
582  v6.sin6_scope_id == rhs.v6.sin6_scope_id;
583  }
584  assert(!"Shouldn't reach this");
585  return false;
586 }

◆ SetAddress() [1/5]

void C4NetIO::EndpointAddress::SetAddress ( const sockaddr *  addr)

Definition at line 364 of file C4NetIO.cpp.

Referenced by C4Network2Client::AddLocalAddrs(), C4NetIOTCP::Socket::GetAddress(), C4NetIOUDP::InitBroadcast(), C4Network2::InitPuncher(), C4NetIOUDP::BinAddr::operator C4NetIO::addr_t(), C4AulDebug::SetAllowed(), and C4Network2Address::SetIP().

365 {
366  switch (addr->sa_family)
367  {
368  case AF_INET: memcpy(&v4, addr, sizeof(v4)); break;
369  case AF_INET6: memcpy(&v6, addr, sizeof(v6)); break;
370  default:
371  assert(!"Unexpected address family");
372  memcpy(&gen, addr, sizeof(gen)); break;
373  }
374 }
Here is the caller graph for this function:

◆ SetAddress() [2/5]

void C4NetIO::EndpointAddress::SetAddress ( const EndpointAddress other)

Definition at line 485 of file C4NetIO.cpp.

References GetPort(), and C4NetIO::HostAddress::SetHost().

486 {
487  SetHost(addr);
488  SetPort(addr.GetPort());
489 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
Here is the call graph for this function:

◆ SetAddress() [3/5]

void C4NetIO::EndpointAddress::SetAddress ( HostAddress::SpecialAddress  addr,
uint16_t  port = IPPORT_NONE 
)

Definition at line 491 of file C4NetIO.cpp.

References C4NetIO::HostAddress::SetHost().

492 {
493  SetHost(host);
494  SetPort(port);
495 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
Here is the call graph for this function:

◆ SetAddress() [4/5]

void C4NetIO::EndpointAddress::SetAddress ( const HostAddress host,
uint16_t  port = IPPORT_NONE 
)

Definition at line 497 of file C4NetIO.cpp.

References C4NetIO::HostAddress::SetHost().

498 {
499  SetHost(host);
500  SetPort(port);
501 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
Here is the call graph for this function:

◆ SetAddress() [5/5]

void C4NetIO::EndpointAddress::SetAddress ( const StdStrBuf addr,
AddressFamily  family = UnknownFamily 
)

Definition at line 419 of file C4NetIO.cpp.

References C4NetIO::HostAddress::Clear(), StdStrBuf::getData(), StdStrBuf::getLength(), and StdStrBuf::isNull().

420 {
421  Clear();
422 
423  if (addr.isNull()) return;
424 
425  const char *begin = addr.getData();
426  const char *end = begin + addr.getLength();
427 
428  const char *ab = begin;
429  const char *ae = end;
430 
431  const char *pb = end;
432  const char *pe = end;
433 
434  bool isIPv6 = false;
435 
436  // If addr begins with [, it's an IPv6 address
437  if (ab[0] == '[')
438  {
439  ++ab; // skip bracket
440  const char *cbracket = std::find(ab, ae, ']');
441  if (cbracket == ae)
442  // No closing bracket found: invalid
443  return;
444  ae = cbracket++;
445  if (cbracket != end && cbracket[0] == ':')
446  {
447  // port number given
448  pb = ++cbracket;
449  if (pb == end)
450  // Trailing colon: invalid
451  return;
452  }
453  isIPv6 = true;
454  }
455  // If there's more than 1 colon in the address, it's IPv6
456  else if (std::count(ab, ae, ':') > 1)
457  {
458  isIPv6 = true;
459  }
460  // It's probably not IPv6, but look for a port specification
461  else
462  {
463  const char *colon = std::find(ab, ae, ':');
464  if (colon != ae)
465  {
466  ae = colon;
467  pb = colon + 1;
468  if (pb == end)
469  // Trailing colon: invalid
470  return;
471  }
472  }
473 
474  addrinfo hints = addrinfo();
475  hints.ai_family = family;
476  //hints.ai_flags = AI_NUMERICHOST;
477  addrinfo *addresses = nullptr;
478  if (getaddrinfo(std::string(ab, ae).c_str(), pb != end ? std::string(pb, pe).c_str() : nullptr, &hints, &addresses) != 0)
479  // GAI failed
480  return;
481  SetAddress(addresses->ai_addr);
482  freeaddrinfo(addresses);
483 }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
bool isNull() const
Definition: StdBuf.h:441
const char * getData() const
Definition: StdBuf.h:442
size_t getLength() const
Definition: StdBuf.h:445
Here is the call graph for this function:

◆ SetDefaultPort()

void C4NetIO::EndpointAddress::SetDefaultPort ( uint16_t  port)

Definition at line 541 of file C4NetIO.cpp.

Referenced by C4Network2::InitPuncher().

542 {
543  if (GetPort() == IPPORT_NONE)
544  SetPort(port);
545 }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:531
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
Here is the caller graph for this function:

◆ SetHost() [1/5]

void C4NetIO::HostAddress::SetHost ( const sockaddr *  addr)
inherited

Definition at line 346 of file C4NetIO.cpp.

Referenced by C4NetIO::GetLocalAddresses(), C4NetIO::HostAddress::HostAddress(), SetAddress(), and C4NetIO::HostAddress::SetHost().

347 {
348  // Copy all but port number
349  if (addr->sa_family == AF_INET6)
350  {
351  v6.sin6_family = ((const sockaddr_in6*)addr)->sin6_family;
352  v6.sin6_flowinfo = ((const sockaddr_in6*)addr)->sin6_flowinfo;
353  memcpy(&v6.sin6_addr, &((const sockaddr_in6*)addr)->sin6_addr, sizeof(v6.sin6_addr));
354  v6.sin6_scope_id = ((const sockaddr_in6*)addr)->sin6_scope_id;
355  }
356  else if (addr->sa_family == AF_INET)
357  {
358  v4.sin_family = ((const sockaddr_in*)addr)->sin_family;
359  v4.sin_addr.s_addr = ((const sockaddr_in*)addr)->sin_addr.s_addr;
360  memset(&v4.sin_zero, 0, sizeof(v4.sin_zero));
361  }
362 }
Here is the caller graph for this function:

◆ SetHost() [2/5]

void C4NetIO::HostAddress::SetHost ( const HostAddress host)
inherited

Definition at line 237 of file C4NetIO.cpp.

References C4NetIO::HostAddress::SetHost().

238 {
239  SetHost(&other.gen);
240 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
Here is the call graph for this function:

◆ SetHost() [3/5]

void C4NetIO::HostAddress::SetHost ( SpecialAddress  host)
inherited

Definition at line 376 of file C4NetIO.cpp.

References C4NetIO::HostAddress::Any, C4NetIO::HostAddress::AnyIPv4, and C4NetIO::HostAddress::Loopback.

377 {
378  switch (addr)
379  {
380  case Any:
381  v6.sin6_family = AF_INET6;
382  memset(&v6.sin6_addr, 0, sizeof(v6.sin6_addr));
383  v6.sin6_flowinfo = 0;
384  v6.sin6_scope_id = 0;
385  break;
386  case AnyIPv4:
387  v4.sin_family = AF_INET;
388  v4.sin_addr.s_addr = 0;
389  memset(&v4.sin_zero, 0, sizeof(v4.sin_zero));
390  break;
391  case Loopback:
392  v6.sin6_family = AF_INET6;
393  memset(&v6.sin6_addr, 0, sizeof(v6.sin6_addr)); v6.sin6_addr.s6_addr[15] = 1;
394  v6.sin6_flowinfo = 0;
395  v6.sin6_scope_id = 0;
396  break;
397  }
398 }

◆ SetHost() [4/5]

void C4NetIO::HostAddress::SetHost ( const StdStrBuf host,
AddressFamily  family = UnknownFamily 
)
inherited

Definition at line 407 of file C4NetIO.cpp.

References StdStrBuf::getData(), and C4NetIO::HostAddress::SetHost().

408 {
409  addrinfo hints = addrinfo();
410  hints.ai_family = family;
411  addrinfo *addresses = nullptr;
412  if (getaddrinfo(addr.getData(), nullptr, &hints, &addresses) != 0)
413  // GAI failed
414  return;
415  SetHost(addresses->ai_addr);
416  freeaddrinfo(addresses);
417 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
Here is the call graph for this function:

◆ SetHost() [5/5]

void C4NetIO::HostAddress::SetHost ( uint32_t  host)
inherited

Definition at line 400 of file C4NetIO.cpp.

401 {
402  v4.sin_family = AF_INET;
403  v4.sin_addr.s_addr = v4addr;
404  memset(&v4.sin_zero, 0, sizeof(v4.sin_zero));
405 }

◆ SetPort()

void C4NetIO::EndpointAddress::SetPort ( uint16_t  port)

Definition at line 531 of file C4NetIO.cpp.

Referenced by C4Network2Client::AddAddrFromPuncher(), C4Network2Client::AddLocalAddrs(), C4Network2Client::DoTCPSimultaneousOpen(), C4NetIOSimpleUDP::Init(), C4NetIOUDP::InitBroadcast(), C4NetIOTCP::Listen(), C4Network2IODiscoverClient::OnPacket(), C4NetIOUDP::BinAddr::operator C4NetIO::addr_t(), and C4Network2Address::SetPort().

532 {
533  switch (gen.sa_family)
534  {
535  case AF_INET: v4.sin_port = htons(port); break;
536  case AF_INET6: v6.sin6_port = htons(port); break;
537  default: assert(!"Shouldn't reach this"); break;
538  }
539 }
Here is the caller graph for this function:

◆ SetScopeId()

void C4NetIO::HostAddress::SetScopeId ( int  scopeId)
inherited

Definition at line 289 of file C4NetIO.cpp.

Referenced by C4NetIO::HostAddress::HostAddress(), and C4Network2Client::SendAddresses().

290 {
291  if (gen.sa_family != AF_INET6) return;
292  if (IN6_IS_ADDR_LINKLOCAL(&v6.sin6_addr) != 0)
293  v6.sin6_scope_id = scopeId;
294 }
Here is the caller graph for this function:

◆ ToString()

StdStrBuf C4NetIO::EndpointAddress::ToString ( int  flags = 0) const

Definition at line 604 of file C4NetIO.cpp.

References FormatString(), C4NetIO::HostAddress::GetFamily(), C4NetIO::HostAddress::IPv4, C4NetIO::HostAddress::IPv6, C4NetIO::HostAddress::ToString(), and C4NetIO::HostAddress::TSF_SkipPort.

Referenced by C4Network2IO::ConnectWithSocket(), C4NetIOUDP::DoCheck(), C4Network2Client::DoTCPSimultaneousOpen(), C4Network2::HandleConn(), C4Network2::HandleConnRe(), C4Network2IO::HandlePacket(), C4AulDebug::Listen(), C4StartupNetDlg::OnBtnRecord(), C4Network2IO::OnConn(), C4Network2::OnConnect(), C4Network2::OnConnectFail(), C4Network2IO::OnDisconn(), C4Network2::OnDisconnect(), C4Network2IO::OnPacket(), C4Network2Address::toString(), C4NetIOUDP::BinAddr::ToString(), and C4Network2ClientDlg::UpdateText().

605 {
606  if (flags & TSF_SkipPort)
607  return HostAddress::ToString(flags);
608 
609  switch (GetFamily())
610  {
611  case IPv4: return FormatString("%s:%d", HostAddress::ToString(flags).getData(), GetPort());
612  case IPv6: return FormatString("[%s]:%d", HostAddress::ToString(flags).getData(), GetPort());
613  default: assert(!"Shouldn't reach this");
614  }
615  return StdStrBuf();
616 }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:588
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ EndpointAddressPtr

friend class EndpointAddressPtr
friend

Definition at line 210 of file C4NetIO.h.

Member Data Documentation

◆ @68

union { ... }

◆ IPPORT_NONE

const uint16_t C4NetIO::EndpointAddress::IPPORT_NONE = 0
static

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