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

Member Enumeration Documentation

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  };
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  };
Enumerator
TSF_SkipZoneId 
TSF_SkipPort 

Definition at line 83 of file C4NetIO.h.

Constructor & Destructor Documentation

C4NetIO::EndpointAddress::EndpointAddress ( )
inline

Definition at line 138 of file C4NetIO.h.

References Clear().

138 { Clear(); }

Here is the call graph for this function:

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

Definition at line 139 of file C4NetIO.h.

References SetAddress().

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

Here is the call graph for this function:

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

Definition at line 140 of file C4NetIO.h.

References SetPort().

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

Here is the call graph for this function:

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

Definition at line 141 of file C4NetIO.h.

References SetPort().

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

Here is the call graph for this function:

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

Definition at line 142 of file C4NetIO.h.

References SetAddress().

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

Here is the call graph for this function:

Member Function Documentation

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

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 336 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv6().

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

Here is the call graph for this function:

void C4NetIO::EndpointAddress::Clear ( )

Definition at line 231 of file C4NetIO.cpp.

References C4NetIO::HostAddress::Clear().

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

232 {
235 }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:526
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:136

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 613 of file C4NetIO.cpp.

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

614 {
615  if (!comp->isDeserializer())
616  {
618  comp->Value(val);
619  } else {
620  StdStrBuf val;
621  comp->Value(val);
622  SetAddress(val);
623  }
624 }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:599
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:

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

Definition at line 520 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().

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

Here is the caller graph for this function:

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

Definition at line 154 of file C4NetIO.h.

Referenced by C4Network2IO::doAutoAccept().

154 { 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 542 of file C4NetIO.cpp.

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

543 {
544  switch (gen.sa_family)
545  {
546  case AF_INET: return ntohs(v4.sin_port);
547  case AF_INET6: return ntohs(v6.sin6_port);
548  }
549  assert(!"Shouldn't reach this");
550  return IPPORT_NONE;
551 }
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:136

Here is the caller graph for this function:

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

Definition at line 296 of file C4NetIO.cpp.

Referenced by C4Network2Client::AddLocalAddrs(), 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:

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 }
bool C4NetIO::HostAddress::IsLoopback ( ) const
inherited

Definition at line 251 of file C4NetIO.cpp.

Referenced by C4NetIO::GetLocalAddresses().

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:

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

Definition at line 242 of file C4NetIO.cpp.

Referenced by 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:

bool C4NetIO::EndpointAddress::IsNull ( ) const

Definition at line 503 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().

504 {
505  return IsNullHost() && GetPort() == IPPORT_NONE;
506 }
bool IsNullHost() const
Definition: C4NetIO.h:163
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:136
uint16_t GetPort() const
Definition: C4NetIO.cpp:542

Here is the caller graph for this function:

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

Definition at line 163 of file C4NetIO.h.

References C4NetIO::HostAddress::IsNull().

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

Here is the call graph for this function:

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

Definition at line 270 of file C4NetIO.cpp.

References s.

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
C4NetIO::EndpointAddress::operator sockaddr ( ) const
inline

Definition at line 199 of file C4NetIO.h.

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

Definition at line 200 of file C4NetIO.h.

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

Definition at line 201 of file C4NetIO.h.

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

Definition at line 122 of file C4NetIO.h.

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

Definition at line 196 of file C4NetIO.h.

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

Definition at line 228 of file C4NetIO.cpp.

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

Definition at line 229 of file C4NetIO.cpp.

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

Definition at line 553 of file C4NetIO.cpp.

References C4NetIO::HostAddress::AsIPv6().

554 {
555  // Check for IPv4-mapped IPv6 addresses.
556  if (gen.sa_family != rhs.gen.sa_family)
557  return AsIPv6() == rhs.AsIPv6();
558  if (gen.sa_family == AF_INET)
559  return v4.sin_addr.s_addr == rhs.v4.sin_addr.s_addr;
560  if (gen.sa_family == AF_INET6)
561  return memcmp(&v6.sin6_addr, &rhs.v6.sin6_addr, sizeof(v6.sin6_addr)) == 0 &&
562  v6.sin6_scope_id == rhs.v6.sin6_scope_id;
563  assert(!"Shouldn't reach this");
564  return false;
565 }
C4NetIO::HostAddress AsIPv6() const
Definition: C4NetIO.cpp:303

Here is the call graph for this function:

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

Definition at line 567 of file C4NetIO.cpp.

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

Definition at line 364 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().

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:

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

Definition at line 485 of file C4NetIO.cpp.

References GetPort().

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

Here is the call graph for this function:

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 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:526
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 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:526
void C4NetIO::EndpointAddress::SetAddress ( const StdStrBuf addr,
AddressFamily  family = UnknownFamily 
)

Definition at line 419 of file C4NetIO.cpp.

References 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 }
const char * getData() const
Definition: StdBuf.h:442
void SetAddress(const sockaddr *addr)
Definition: C4NetIO.cpp:364
bool isNull() const
Definition: StdBuf.h:441
size_t getLength() const
Definition: StdBuf.h:445

Here is the call graph for this function:

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

Definition at line 536 of file C4NetIO.cpp.

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

537 {
538  if (GetPort() == IPPORT_NONE)
539  SetPort(port);
540 }
void SetPort(uint16_t port)
Definition: C4NetIO.cpp:526
static const uint16_t IPPORT_NONE
Definition: C4NetIO.h:136
uint16_t GetPort() const
Definition: C4NetIO.cpp:542

Here is the caller graph for this function:

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

Definition at line 346 of file C4NetIO.cpp.

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

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:

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

Definition at line 237 of file C4NetIO.cpp.

238 {
239  SetHost(&other.gen);
240 }
void SetHost(const sockaddr *addr)
Definition: C4NetIO.cpp:346
void C4NetIO::HostAddress::SetHost ( SpecialAddress  host)
inherited

Definition at line 376 of file C4NetIO.cpp.

References ControllerKeys::Any().

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 }

Here is the call graph for this function:

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

Definition at line 407 of file C4NetIO.cpp.

References StdStrBuf::getData().

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:

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 }
void C4NetIO::EndpointAddress::SetPort ( uint16_t  port)

Definition at line 526 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().

527 {
528  switch (gen.sa_family)
529  {
530  case AF_INET: v4.sin_port = htons(port); break;
531  case AF_INET6: v6.sin6_port = htons(port); break;
532  default: assert(!"Shouldn't reach this"); break;
533  }
534 }

Here is the caller graph for this function:

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

Definition at line 289 of file C4NetIO.cpp.

Referenced by 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:

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

Definition at line 599 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().

600 {
601  if (flags & TSF_SkipPort)
602  return HostAddress::ToString(flags);
603 
604  switch (GetFamily())
605  {
606  case IPv4: return FormatString("%s:%d", HostAddress::ToString(flags).getData(), GetPort());
607  case IPv6: return FormatString("[%s]:%d", HostAddress::ToString(flags).getData(), GetPort());
608  default: assert(!"Shouldn't reach this");
609  }
610  return StdStrBuf();
611 }
StdStrBuf ToString(int flags=0) const
Definition: C4NetIO.cpp:583
AddressFamily GetFamily() const
Definition: C4NetIO.cpp:520
uint16_t GetPort() const
Definition: C4NetIO.cpp:542
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

friend class EndpointAddressPtr
friend

Definition at line 209 of file C4NetIO.h.

Member Data Documentation

union { ... }
const uint16_t C4NetIO::EndpointAddress::IPPORT_NONE = 0
static

Definition at line 136 of file C4NetIO.h.

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


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