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)
 
EndpointAddressoperator= (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.

84  {
85  TSF_SkipZoneId = 1,
86  TSF_SkipPort = 2
87  };

Constructor & Destructor Documentation

◆ EndpointAddress() [1/5]

C4NetIO::EndpointAddress::EndpointAddress ( )
inline

Definition at line 139 of file C4NetIO.h.

139 { Clear(); }

References 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

References SetAddress().

Here is the call graph for this function:

◆ EndpointAddress() [3/5]

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

Definition at line 142 of file C4NetIO.h.

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

References SetPort().

Here is the call graph for this function:

◆ EndpointAddress() [4/5]

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

Definition at line 143 of file C4NetIO.h.

143 : HostAddress(addr) { SetPort(port); }

References SetPort().

Here is the call graph for this function:

◆ EndpointAddress() [5/5]

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

Definition at line 144 of file C4NetIO.h.

144 { SetAddress(addr); }

References SetAddress().

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.

342 {
344 }
uint16_t GetPort() const
Definition: C4NetIO.cpp:547
C4NetIO::HostAddress AsIPv4() const
Definition: C4NetIO.cpp:325

References C4NetIO::HostAddress::AsIPv4().

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

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.

337 {
339 }
C4NetIO::HostAddress AsIPv6() const
Definition: C4NetIO.cpp:303

References C4NetIO::HostAddress::AsIPv6().

Here is the call graph for this function:

◆ Clear()

void C4NetIO::EndpointAddress::Clear ( )

Definition at line 231 of file C4NetIO.cpp.

232 {
235 }
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137

References C4NetIO::HostAddress::Clear().

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

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.

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

References StdCompiler::isDeserializer(), and StdCompiler::Value().

Here is the call graph for this function:

◆ GetAddrLen()

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

Definition at line 526 of file C4NetIO.cpp.

527 {
528  return GetFamily() == IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
529 }
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520

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

Here is the caller graph for this function:

◆ GetFamily()

C4NetIO::HostAddress::AddressFamily C4NetIO::HostAddress::GetFamily ( ) const
inherited

Definition at line 520 of file C4NetIO.cpp.

521 {
522  return gen.sa_family == AF_INET ? IPv4 :
523  gen.sa_family == AF_INET6 ? IPv6 : UnknownFamily;
524 }

Referenced by C4NetIOTCP::Accept(), C4Network2Client::AddAddrFromPuncher(), C4NetIOUDP::BinAddr::BinAddr(), C4NetIOTCP::Bind(), C4NetIOTCP::Connect(), C4NetIOSimpleUDP::Execute(), C4Network2IO::HandlePuncherPacket(), C4NetIOSimpleUDP::InitBroadcast(), C4Network2IO::InitPuncher(), and std::hash< C4NetIO::addr_t >::operator()().

Here is the caller graph for this function:

◆ GetHost()

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

Definition at line 156 of file C4NetIO.h.

156 { return *this; } // HostAddress copy ctor slices off port information

Referenced by C4Network2IO::doAutoAccept().

Here is the caller graph for this function:

◆ GetPort()

uint16_t C4NetIO::EndpointAddress::GetPort ( ) const

Definition at line 547 of file C4NetIO.cpp.

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 }

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

Here is the caller graph for this function:

◆ GetScopeId()

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

Definition at line 296 of file C4NetIO.cpp.

297 {
298  if (gen.sa_family == AF_INET6)
299  return v6.sin6_scope_id;
300  return 0;
301 }

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

Here is the caller graph for this function:

◆ IsLocal()

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

Definition at line 260 of file C4NetIO.cpp.

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 }

◆ IsLoopback()

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

Definition at line 251 of file C4NetIO.cpp.

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 }

Referenced by C4NetIO::GetLocalAddresses().

Here is the caller graph for this function:

◆ IsMulticast()

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

Definition at line 242 of file C4NetIO.cpp.

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 }

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

Here is the caller graph for this function:

◆ IsNull()

bool C4NetIO::EndpointAddress::IsNull ( ) const

Definition at line 503 of file C4NetIO.cpp.

504 {
505  return IsNullHost() && GetPort() == IPPORT_NONE;
506 }
bool IsNullHost() const
Definition: C4NetIO.h:165

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

Here is the caller graph for this function:

◆ IsNullHost()

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

Definition at line 165 of file C4NetIO.h.

165 { return HostAddress::IsNull(); }
bool IsNull() const
Definition: C4NetIO.cpp:508

References C4NetIO::HostAddress::IsNull().

Here is the call graph for this function:

◆ IsPrivate()

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

Definition at line 270 of file C4NetIO.cpp.

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

References s.

◆ operator sockaddr()

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

Definition at line 201 of file C4NetIO.h.

201 { return gen; }

◆ operator sockaddr_in()

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

Definition at line 202 of file C4NetIO.h.

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

◆ operator sockaddr_in6()

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

Definition at line 203 of file C4NetIO.h.

203 { assert(gen.sa_family == AF_INET6); return v6; }

◆ operator!=() [1/2]

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

Definition at line 198 of file C4NetIO.h.

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

◆ operator!=() [2/2]

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

Definition at line 123 of file C4NetIO.h.

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

◆ operator&() [1/2]

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

Definition at line 229 of file C4NetIO.cpp.

229 { return EndpointAddressPtr(this); }
friend class EndpointAddressPtr
Definition: C4NetIO.h:211

◆ operator&() [2/2]

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

Definition at line 228 of file C4NetIO.cpp.

228 { return EndpointAddressPtr(const_cast<EndpointAddress*>(this)); }

◆ operator=()

EndpointAddress& C4NetIO::EndpointAddress::operator= ( const EndpointAddress other)
inline

Definition at line 141 of file C4NetIO.h.

141 { SetAddress(other); return *this; }

References SetAddress().

Here is the call graph for this function:

◆ operator==() [1/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 }

◆ operator==() [2/2]

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

Definition at line 558 of file C4NetIO.cpp.

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 }

References C4NetIO::HostAddress::AsIPv6().

Here is the call graph for this function:

◆ SetAddress() [1/5]

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

Definition at line 485 of file C4NetIO.cpp.

486 {
487  SetHost(addr);
488  SetPort(addr.GetPort());
489 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346

References GetPort().

Here is the call graph for this function:

◆ SetAddress() [2/5]

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

Definition at line 497 of file C4NetIO.cpp.

498 {
499  SetHost(host);
500  SetPort(port);
501 }

◆ SetAddress() [3/5]

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

Definition at line 364 of file C4NetIO.cpp.

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 }

Referenced by C4Network2Client::AddLocalAddrs(), C4Network2IRCClient::Connect(), EndpointAddress(), C4NetIOTCP::Socket::GetAddress(), C4Network2IODiscover::Init(), C4Network2IODiscoverClient::Init(), C4NetIOUDP::InitBroadcast(), C4Network2::InitPuncher(), C4NetIOUDP::BinAddr::operator C4NetIO::addr_t(), operator=(), C4AulDebug::SetAllowed(), and C4Network2Address::SetIP().

Here is the caller graph for this function:

◆ SetAddress() [4/5]

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

Definition at line 419 of file C4NetIO.cpp.

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 }
const char * getData() const
Definition: StdBuf.h:442
bool isNull() const
Definition: StdBuf.h:441
size_t getLength() const
Definition: StdBuf.h:445

References StdStrBuf::getData(), StdStrBuf::getLength(), and StdStrBuf::isNull().

Here is the call graph for this function:

◆ SetAddress() [5/5]

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

Definition at line 491 of file C4NetIO.cpp.

492 {
493  SetHost(host);
494  SetPort(port);
495 }

◆ SetDefaultPort()

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

Definition at line 541 of file C4NetIO.cpp.

542 {
543  if (GetPort() == IPPORT_NONE)
544  SetPort(port);
545 }

Referenced by C4Network2IRCClient::Connect(), and C4Network2::InitPuncher().

Here is the caller graph for this function:

◆ SetHost() [1/5]

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

Definition at line 237 of file C4NetIO.cpp.

238 {
239  SetHost(&other.gen);
240 }

◆ SetHost() [2/5]

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

Definition at line 346 of file C4NetIO.cpp.

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 }

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

Here is the caller graph for this function:

◆ SetHost() [3/5]

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

Definition at line 407 of file C4NetIO.cpp.

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 }

References StdStrBuf::getData().

Here is the call graph for this function:

◆ SetHost() [4/5]

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

Definition at line 376 of file C4NetIO.cpp.

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 }

References ControllerKeys::Any().

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.

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 }

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

Here is the caller graph for this function:

◆ SetScopeId()

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

Definition at line 289 of file C4NetIO.cpp.

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 }

Referenced by C4Network2Client::SendAddresses().

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.

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 FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:588

References FormatString(), and C4NetIO::HostAddress::ToString().

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

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 211 of file C4NetIO.h.

Member Data Documentation

◆ 

union { ... }

◆ IPPORT_NONE

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

Definition at line 137 of file C4NetIO.h.

Referenced by C4AulDebug::Init(), C4NetIOTCP::Init(), and C4NetIOTCP::Listen().


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