#include <IPvXAddress.h>
Storage is efficient: an object occupies size of an IPv6 address (128bits=16 bytes) plus a bool.
Public Member Functions | |
void | netPack (cCommBuffer *b) |
void | netUnpack (cCommBuffer *b) |
IPvXAddress () | |
IPvXAddress (const IPAddress &addr) | |
IPvXAddress (const IPv6Address &addr) | |
IPvXAddress (const char *addr) | |
IPvXAddress (const IPvXAddress &addr) | |
~IPvXAddress () | |
bool | isIPv6 () const |
IPAddress | get4 () const |
IPv6Address | get6 () const |
void | set (const IPAddress &addr) |
void | set (const IPv6Address &addr) |
void | set (const IPvXAddress &addr) |
void | set (const char *addr) |
IPvXAddress & | operator= (const IPAddress &addr) |
IPvXAddress & | operator= (const IPv6Address &addr) |
IPvXAddress & | operator= (const IPvXAddress &addr) |
bool | tryParse (const char *addr) |
std::string | str () const |
bool | isUnspecified () const |
bool | equals (const IPAddress &addr) const |
bool | equals (const IPv6Address &addr) const |
bool | equals (const IPvXAddress &addr) const |
bool | operator== (const IPAddress &addr) const |
bool | operator!= (const IPAddress &addr) const |
bool | operator== (const IPv6Address &addr) const |
bool | operator!= (const IPv6Address &addr) const |
bool | operator== (const IPvXAddress &addr) const |
bool | operator!= (const IPvXAddress &addr) const |
bool | operator< (const IPvXAddress &addr) const |
Protected Attributes | |
uint32 | d [4] |
bool | isv6 |
IPvXAddress::IPvXAddress | ( | ) | [inline] |
IPvXAddress::IPvXAddress | ( | const IPAddress & | addr | ) | [inline] |
IPvXAddress::IPvXAddress | ( | const IPv6Address & | addr | ) | [inline] |
IPvXAddress::IPvXAddress | ( | const char * | addr | ) | [inline] |
Accepts string representations suuported by IPAddress (dotted decimal notation) and IPv6Address (hex string with colons). Throws an error if the format is not recognized.
00065 {set(addr);}
IPvXAddress::IPvXAddress | ( | const IPvXAddress & | addr | ) | [inline] |
bool IPvXAddress::equals | ( | const IPvXAddress & | addr | ) | const [inline] |
bool IPvXAddress::equals | ( | const IPv6Address & | addr | ) | const [inline] |
bool IPvXAddress::equals | ( | const IPAddress & | addr | ) | const [inline] |
IPAddress IPvXAddress::get4 | ( | ) | const [inline] |
IPv6Address IPvXAddress::get6 | ( | ) | const [inline] |
Get IPv6 address. Throws exception if this is an IPv4 address.
00097 { 00098 if (!isv6) { 00099 if (d[0]==0) // allow null address to be returned as IPv6 00100 return IPv6Address(); 00101 throw new cException("IPvXAddress: cannot return IPv4 address %s as IPv6", str().c_str()); 00102 } 00103 return IPv6Address(d[0], d[1], d[2], d[3]); 00104 }
bool IPvXAddress::isUnspecified | ( | ) | const [inline] |
void IPvXAddress::netPack | ( | cCommBuffer * | b | ) |
void IPvXAddress::netUnpack | ( | cCommBuffer * | b | ) |
00095 { 00096 char t; 00097 doUnpacking(b, t); 00098 if(t == 4) 00099 doUnpacking(b, d, 1); 00100 else if(t== 6) 00101 doUnpacking(b, d, 4); 00102 }
bool IPvXAddress::operator!= | ( | const IPvXAddress & | addr | ) | const [inline] |
bool IPvXAddress::operator!= | ( | const IPv6Address & | addr | ) | const [inline] |
bool IPvXAddress::operator!= | ( | const IPAddress & | addr | ) | const [inline] |
bool IPvXAddress::operator< | ( | const IPvXAddress & | addr | ) | const [inline] |
IPvXAddress& IPvXAddress::operator= | ( | const IPvXAddress & | addr | ) | [inline] |
IPvXAddress& IPvXAddress::operator= | ( | const IPv6Address & | addr | ) | [inline] |
IPvXAddress& IPvXAddress::operator= | ( | const IPAddress & | addr | ) | [inline] |
bool IPvXAddress::operator== | ( | const IPvXAddress & | addr | ) | const [inline] |
bool IPvXAddress::operator== | ( | const IPv6Address & | addr | ) | const [inline] |
bool IPvXAddress::operator== | ( | const IPAddress & | addr | ) | const [inline] |
void IPvXAddress::set | ( | const char * | addr | ) | [inline] |
Accepts string representations supported by IPAddress (dotted decimal notation) and IPv6Address (hex string with colons). Throws an error if the format is not recognized.
00144 { 00145 if (!tryParse(addr)) 00146 throw new cRuntimeError("IPvXAddress: cannot interpret address string `%s'", addr); 00147 }
void IPvXAddress::set | ( | const IPvXAddress & | addr | ) | [inline] |
void IPvXAddress::set | ( | const IPv6Address & | addr | ) | [inline] |
Set to an IPv6 address.
00117 { 00118 if (addr.isUnspecified()) { 00119 // we always represent nulls as IPv4 null 00120 isv6 = false; d[0] = 0; 00121 return; 00122 } 00123 isv6 = true; 00124 uint32 *w = const_cast<IPv6Address&>(addr).words(); 00125 d[0] = w[0]; d[1] = w[1]; d[2] = w[2]; d[3] = w[3]; 00126 }
void IPvXAddress::set | ( | const IPAddress & | addr | ) | [inline] |
std::string IPvXAddress::str | ( | ) | const [inline] |
bool IPvXAddress::tryParse | ( | const char * | addr | ) |
Parses and assigns the given address and returns true if the string is recognized by IPAddress or IPv6Address, otherwise just returns false.
00023 { 00024 // try as IPv4 00025 if (IPAddress::isWellFormed(addr)) 00026 { 00027 set(IPAddress(addr)); 00028 return true; 00029 } 00030 00031 // try as IPv6 00032 IPv6Address ipv6; 00033 if (ipv6.tryParse(addr)) 00034 { 00035 set(ipv6); 00036 return true; 00037 } 00038 00039 // no luck 00040 return false; 00041 }
uint32 IPvXAddress::d[4] [protected] |
bool IPvXAddress::isv6 [protected] |