OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
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
 
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

Enumerator
IPv6 
IPv4 
UnknownFamily 

Definition at line 71 of file C4NetIO.h.

72  {
73  IPv6 = AF_INET6,
74  IPv4 = AF_INET,
75  UnknownFamily = 0
76  };
Enumerator
Loopback 
Any 
AnyIPv4 

Definition at line 77 of file C4NetIO.h.

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

Definition at line 84 of file C4NetIO.h.

Constructor & Destructor Documentation

C4NetIO::EndpointAddress::EndpointAddress ( )
inline

Definition at line 139 of file C4NetIO.h.

References Clear().

139 { Clear(); }

Here is the call graph for this function:

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

Definition at line 140 of file C4NetIO.h.

References SetAddress().

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

Here is the call graph for this function:

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

Definition at line 141 of file C4NetIO.h.

References SetPort().

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

Here is the call graph for this function:

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

Definition at line 142 of file C4NetIO.h.

References SetPort().

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

Here is the call graph for this function:

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

Definition at line 143 of file C4NetIO.h.

References SetAddress().

143 { SetAddress(addr); }
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:370

Here is the call graph for this function:

Member Function Documentation

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

Definition at line 347 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv4().

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

348 {
350 }
C4NetIO::HostAddress AsIPv4() const
Definition: C4NetIO.cpp:331
uint16_t GetPort() const
Definition: C4NetIO.cpp:548

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 342 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv6().

343 {
345 }
C4NetIO::HostAddress AsIPv6() const
Definition: C4NetIO.cpp:309
uint16_t GetPort() const
Definition: C4NetIO.cpp:548

Here is the call graph for this function:

void C4NetIO::EndpointAddress::Clear ( )

Definition at line 237 of file C4NetIO.cpp.

References C4NetIO::HostAddress::Clear().

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

238 {
241 }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:532
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:

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

Definition at line 619 of file C4NetIO.cpp.

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

620 {
621  if (!comp->isDeserializer())
622  {
624  comp->Value(val);
625  } else {
626  StdStrBuf val;
627  comp->Value(val);
628  SetAddress(val);
629  }
630 }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:605
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:370
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63

Here is the call graph for this function:

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

Definition at line 526 of file C4NetIO.cpp.

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

527 {
528  return gen.sa_family == AF_INET ? IPv4 :
529  gen.sa_family == AF_INET6 ? IPv6 : UnknownFamily;
530 }

Here is the caller graph for this function:

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

Definition at line 155 of file C4NetIO.h.

Referenced by C4Network2IO::doAutoAccept().

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

Here is the caller graph for this function:

uint16_t C4NetIO::EndpointAddress::GetPort ( ) const

Definition at line 548 of file C4NetIO.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 302 of file C4NetIO.cpp.

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

303 {
304  if (gen.sa_family == AF_INET6)
305  return v6.sin6_scope_id;
306  return 0;
307 }

Here is the caller graph for this function:

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

Definition at line 266 of file C4NetIO.cpp.

267 {
268  if (gen.sa_family == AF_INET6)
269  return IN6_IS_ADDR_LINKLOCAL(&v6.sin6_addr) != 0;
270  // We don't really care about local 169.256.0.0/16 addresses here as users will either have a
271  // router doing DHCP (which will prevent usage of these addresses) or have a network that
272  // doesn't care about IP and IPv6 link-local addresses will work.
273  return false;
274 }
bool C4NetIO::HostAddress::IsLoopback ( ) const
inherited

Definition at line 257 of file C4NetIO.cpp.

Referenced by C4NetIO::GetLocalAddresses().

258 {
259  if (gen.sa_family == AF_INET6)
260  return IN6_IS_ADDR_LOOPBACK(&v6.sin6_addr) != 0;
261  if (gen.sa_family == AF_INET)
262  return (ntohl(v4.sin_addr.s_addr) >> 24) == 127;
263  return false;
264 }

Here is the caller graph for this function:

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

Definition at line 248 of file C4NetIO.cpp.

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

249 {
250  if (gen.sa_family == AF_INET6)
251  return IN6_IS_ADDR_MULTICAST(&v6.sin6_addr) != 0;
252  if (gen.sa_family == AF_INET)
253  return (ntohl(v4.sin_addr.s_addr) >> 24) == 239;
254  return false;
255 }

Here is the caller graph for this function:

bool C4NetIO::EndpointAddress::IsNull ( ) const

Definition at line 509 of file C4NetIO.cpp.

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

510 {
511  return IsNullHost() && GetPort() == IPPORT_NONE;
512 }
bool IsNullHost() const
Definition: C4NetIO.h:164
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
uint16_t GetPort() const
Definition: C4NetIO.cpp:548

Here is the caller graph for this function:

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:514

Here is the call graph for this function:

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

Definition at line 276 of file C4NetIO.cpp.

References s.

277 {
278  // IPv6 unique local address
279  if (gen.sa_family == AF_INET6)
280  return (v6.sin6_addr.s6_addr[0] & 0xfe) == 0xfc;
281  if (gen.sa_family == AF_INET)
282  {
283  uint32_t addr = ntohl(v4.sin_addr.s_addr);
284  uint32_t s = (addr >> 16) & 0xff;
285  switch (addr >> 24)
286  {
287  case 10: return true;
288  case 172: return s >= 16 && s <= 31;
289  case 192: return s == 168;
290  }
291  }
292  return false;
293 }
#define s
C4NetIO::EndpointAddress::operator sockaddr ( ) const
inline

Definition at line 200 of file C4NetIO.h.

200 { return gen; }
C4NetIO::EndpointAddress::operator sockaddr_in ( ) const
inline

Definition at line 201 of file C4NetIO.h.

201 { assert(gen.sa_family == AF_INET); return v4; }
C4NetIO::EndpointAddress::operator sockaddr_in6 ( ) const
inline

Definition at line 202 of file C4NetIO.h.

202 { assert(gen.sa_family == AF_INET6); return v6; }
bool C4NetIO::HostAddress::operator!= ( const HostAddress rhs) const
inlineinherited

Definition at line 123 of file C4NetIO.h.

123 { return !(*this == rhs); }
bool C4NetIO::EndpointAddress::operator!= ( const EndpointAddress rhs) const
inline

Definition at line 197 of file C4NetIO.h.

197 { return !(*this == rhs); }
const C4NetIO::EndpointAddress::EndpointAddressPtr C4NetIO::EndpointAddress::operator& ( ) const

Definition at line 234 of file C4NetIO.cpp.

234 { return EndpointAddressPtr(const_cast<EndpointAddress*>(this)); }
friend class EndpointAddressPtr
Definition: C4NetIO.h:210
C4NetIO::EndpointAddress::EndpointAddressPtr C4NetIO::EndpointAddress::operator& ( )

Definition at line 235 of file C4NetIO.cpp.

235 { return EndpointAddressPtr(this); }
friend class EndpointAddressPtr
Definition: C4NetIO.h:210
bool C4NetIO::HostAddress::operator== ( const HostAddress rhs) const
inherited

Definition at line 559 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv6().

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

Here is the call graph for this function:

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

Definition at line 573 of file C4NetIO.cpp.

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

Definition at line 370 of file C4NetIO.cpp.

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

371 {
372  switch (addr->sa_family)
373  {
374  case AF_INET: memcpy(&v4, addr, sizeof(v4)); break;
375  case AF_INET6: memcpy(&v6, addr, sizeof(v6)); break;
376  default:
377  assert(!"Unexpected address family");
378  memcpy(&gen, addr, sizeof(gen)); break;
379  }
380 }

Here is the caller graph for this function:

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

Definition at line 491 of file C4NetIO.cpp.

References GetPort().

492 {
493  SetHost(addr);
494  SetPort(addr.GetPort());
495 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:352
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:532

Here is the call graph for this function:

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

Definition at line 497 of file C4NetIO.cpp.

498 {
499  SetHost(host);
500  SetPort(port);
501 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:352
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:532
void C4NetIO::EndpointAddress::SetAddress ( const HostAddress host,
uint16_t  port = IPPORT_NONE 
)

Definition at line 503 of file C4NetIO.cpp.

504 {
505  SetHost(host);
506  SetPort(port);
507 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:352
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:532
void C4NetIO::EndpointAddress::SetAddress ( const StdStrBuf addr,
AddressFamily  family = UnknownFamily 
)

Definition at line 425 of file C4NetIO.cpp.

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

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

Here is the call graph for this function:

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

Definition at line 542 of file C4NetIO.cpp.

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

543 {
544  if (GetPort() == IPPORT_NONE)
545  SetPort(port);
546 }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:532
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:137
uint16_t GetPort() const
Definition: C4NetIO.cpp:548

Here is the caller graph for this function:

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

Definition at line 352 of file C4NetIO.cpp.

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

353 {
354  // Copy all but port number
355  if (addr->sa_family == AF_INET6)
356  {
357  v6.sin6_family = ((const sockaddr_in6*)addr)->sin6_family;
358  v6.sin6_flowinfo = ((const sockaddr_in6*)addr)->sin6_flowinfo;
359  memcpy(&v6.sin6_addr, &((const sockaddr_in6*)addr)->sin6_addr, sizeof(v6.sin6_addr));
360  v6.sin6_scope_id = ((const sockaddr_in6*)addr)->sin6_scope_id;
361  }
362  else if (addr->sa_family == AF_INET)
363  {
364  v4.sin_family = ((const sockaddr_in*)addr)->sin_family;
365  v4.sin_addr.s_addr = ((const sockaddr_in*)addr)->sin_addr.s_addr;
366  memset(&v4.sin_zero, 0, sizeof(v4.sin_zero));
367  }
368 }

Here is the caller graph for this function:

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

Definition at line 243 of file C4NetIO.cpp.

244 {
245  SetHost(&other.gen);
246 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:352
void C4NetIO::HostAddress::SetHost ( SpecialAddress  host)
inherited

Definition at line 382 of file C4NetIO.cpp.

References ControllerKeys::Any().

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

Here is the call graph for this function:

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

Definition at line 413 of file C4NetIO.cpp.

References StdStrBuf::getData().

414 {
415  addrinfo hints = addrinfo();
416  hints.ai_family = family;
417  addrinfo *addresses = nullptr;
418  if (getaddrinfo(addr.getData(), nullptr, &hints, &addresses) != 0)
419  // GAI failed
420  return;
421  SetHost(addresses->ai_addr);
422  freeaddrinfo(addresses);
423 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:352

Here is the call graph for this function:

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

Definition at line 406 of file C4NetIO.cpp.

407 {
408  v4.sin_family = AF_INET;
409  v4.sin_addr.s_addr = v4addr;
410  memset(&v4.sin_zero, 0, sizeof(v4.sin_zero));
411 }
void C4NetIO::EndpointAddress::SetPort ( uint16_t  port)

Definition at line 532 of file C4NetIO.cpp.

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

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

Here is the caller graph for this function:

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

Definition at line 295 of file C4NetIO.cpp.

Referenced by C4Network2Client::SendAddresses().

296 {
297  if (gen.sa_family != AF_INET6) return;
298  if (IN6_IS_ADDR_LINKLOCAL(&v6.sin6_addr) != 0)
299  v6.sin6_scope_id = scopeId;
300 }

Here is the caller graph for this function:

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

Definition at line 605 of file C4NetIO.cpp.

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

Referenced by C4Network2IO::Connect(), C4Network2HTTPClient::Execute(), C4Network2::HandleConn(), C4Network2::HandleConnRe(), C4Network2IO::HandlePacket(), C4Network2IO::OnConn(), C4Network2::OnConnect(), C4Network2::OnConnectFail(), C4Network2IO::OnDisconn(), C4Network2::OnDisconnect(), C4Network2IO::OnPacket(), C4Network2Address::toString(), and C4Network2ClientDlg::UpdateText().

606 {
607  if (flags & TSF_SkipPort)
608  return HostAddress::ToString(flags);
609 
610  switch (GetFamily())
611  {
612  case IPv4: return FormatString("%s:%d", HostAddress::ToString(flags).getData(), GetPort());
613  case IPv6: return FormatString("[%s]:%d", HostAddress::ToString(flags).getData(), GetPort());
614  default: assert(!"Shouldn't reach this");
615  }
616  return StdStrBuf();
617 }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:589
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:526
uint16_t GetPort() const
Definition: C4NetIO.cpp:548
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class EndpointAddressPtr
friend

Definition at line 210 of file C4NetIO.h.

Member Data Documentation

union { ... }
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: