INET Framework for OMNeT++/OMNEST
|
#include <IPvXAddress.h>
Public Member Functions | |
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 |
int | wordCount () const |
const uint32 * | words () 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 |
Stores an IPv4 or an IPv6 address. This class should be used everywhere in transport layer and up, to guarantee IPv4/IPv6 transparence.
Storage is efficient: an object occupies size of an IPv6 address (128bits=16 bytes) plus a bool.
IPvXAddress::IPvXAddress | ( | ) | [inline] |
IPvXAddress::IPvXAddress | ( | const IPAddress & | addr | ) | [inline] |
Constructor for IPv4 addresses.
{set(addr);}
IPvXAddress::IPvXAddress | ( | const IPv6Address & | addr | ) | [inline] |
Constructor for IPv6 addresses.
{set(addr);}
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.
{set(addr);}
IPvXAddress::IPvXAddress | ( | const IPvXAddress & | addr | ) | [inline] |
Copy constructor.
{set(addr);}
IPvXAddress::~IPvXAddress | ( | ) | [inline] |
Destructor
{}
bool IPvXAddress::equals | ( | const IPAddress & | addr | ) | const [inline] |
bool IPvXAddress::equals | ( | const IPv6Address & | addr | ) | const [inline] |
Returns true if the two addresses are equal
{ uint32 *w = const_cast<IPv6Address&>(addr).words(); return isv6 && d[0]==w[0] && d[1]==w[1] && d[2]==w[2] && d[3]==w[3]; }
bool IPvXAddress::equals | ( | const IPvXAddress & | addr | ) | const [inline] |
IPAddress IPvXAddress::get4 | ( | ) | const [inline] |
Get IPv4 address. Throws exception if this is an IPv6 address.
Referenced by doPacking(), getLevel(), UDP::matchesSocket(), SCTPAssociation::pmStartPathManagement(), LDP::processMessageFromTCP(), SCTPPathVariables::SCTPPathVariables(), SCTP::sendAbortFromMain(), SCTPAssociation::sendInit(), IPTrafGen::sendPacket(), SCTP::sendShutdownCompleteFromMain(), PingApp::sendToICMP(), TCPSpoof::sendToIP(), tcp_old::TCPConnection::sendToIP(), TCPConnection::sendToIP(), and SCTPAssociation::sendToIP().
IPv6Address IPvXAddress::get6 | ( | ) | const [inline] |
Get IPv6 address. Throws exception if this is an IPv4 address.
Referenced by doPacking(), getLevel(), UDP::matchesSocket(), IPTrafGen::sendPacket(), PingApp::sendToICMP(), TCPSpoof::sendToIP(), tcp_old::TCPConnection::sendToIP(), TCPConnection::sendToIP(), and SCTPAssociation::sendToIP().
{ if (!isv6) { if (d[0]==0) // allow null address to be returned as IPv6 return IPv6Address(); throw cRuntimeError("IPvXAddress: cannot return IPv4 address %s as IPv6", str().c_str()); } return IPv6Address(d[0], d[1], d[2], d[3]); }
bool IPvXAddress::isIPv6 | ( | ) | const [inline] |
name Getters, setters Is this an IPv6 address?
Referenced by doPacking(), getLevel(), SCTPAssociation::sendInit(), IPTrafGen::sendPacket(), PingApp::sendToICMP(), TCPSpoof::sendToIP(), tcp_old::TCPConnection::sendToIP(), TCPConnection::sendToIP(), and SCTPAssociation::sendToIP().
{return isv6;}
bool IPvXAddress::isUnspecified | ( | ) | const [inline] |
name Comparison True if the structure has not been assigned any address yet.
Referenced by SCTP::addLocalAddress(), SCTP::addLocalAddressToAllRemoteAddresses(), tcp_old::TCP::addSockPair(), TCP::addSockPair(), UDP::bind(), UDPSocket::connect(), UDP::connect(), IPAddressResolver::getAddressFrom(), PingApp::handleMessage(), UDP::matchesSocket(), SCTPAssociation::process_ASSOCIATE(), tcp_old::TCPConnection::processTCPSegment(), TCPConnection::processTCPSegment(), UDPVideoStreamCli::requestStream(), UDPSocket::send(), SCTPAssociation::sendInit(), tcp_old::TCPConnection::sendSyn(), TCPConnection::sendSyn(), and IPAddressResolver::tryResolve().
bool IPvXAddress::operator!= | ( | const IPAddress & | addr | ) | const [inline] |
Returns !equals(addr).
{return !equals(addr);}
bool IPvXAddress::operator!= | ( | const IPv6Address & | addr | ) | const [inline] |
Returns !equals(addr).
{return !equals(addr);}
bool IPvXAddress::operator!= | ( | const IPvXAddress & | addr | ) | const [inline] |
Returns !equals(addr).
{return !equals(addr);}
bool IPvXAddress::operator< | ( | const IPvXAddress & | addr | ) | const [inline] |
IPvXAddress& IPvXAddress::operator= | ( | const IPAddress & | addr | ) | [inline] |
Assignment
{set(addr); return *this;}
IPvXAddress& IPvXAddress::operator= | ( | const IPv6Address & | addr | ) | [inline] |
Assignment
{set(addr); return *this;}
IPvXAddress& IPvXAddress::operator= | ( | const IPvXAddress & | addr | ) | [inline] |
Assignment
{set(addr); return *this;}
bool IPvXAddress::operator== | ( | const IPvXAddress & | addr | ) | const [inline] |
Returns equals(addr).
{return equals(addr);}
bool IPvXAddress::operator== | ( | const IPAddress & | addr | ) | const [inline] |
Returns equals(addr).
{return equals(addr);}
bool IPvXAddress::operator== | ( | const IPv6Address & | addr | ) | const [inline] |
Returns equals(addr).
{return equals(addr);}
void IPvXAddress::set | ( | const IPAddress & | addr | ) | [inline] |
Set to an IPv4 address.
Referenced by doUnpacking(), SCTP::findAssocForMessage(), and UDPSerializer::parse().
void IPvXAddress::set | ( | const IPv6Address & | addr | ) | [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.
{ if (!tryParse(addr)) throw cRuntimeError("IPvXAddress: cannot interpret address string `%s'", addr); }
void IPvXAddress::set | ( | const IPvXAddress & | addr | ) | [inline] |
std::string IPvXAddress::str | ( | ) | const [inline] |
Returns the string representation of the address (e.g. "152.66.86.92")
Referenced by tcp_old::TCP::addSockPair(), TCP::addSockPair(), operator<<(), SCTP::removeAssociation(), and SCTPPathVariables::SCTPPathVariables().
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.
Referenced by IPAddressResolver::tryResolve().
{ // try as IPv4 if (IPAddress::isWellFormed(addr)) { set(IPAddress(addr)); return true; } // try as IPv6 IPv6Address ipv6; if (ipv6.tryParse(addr)) { set(ipv6); return true; } // no luck return false; }
int IPvXAddress::wordCount | ( | ) | const [inline] |
Returns length of internal binary representation of address, (count of 32-bit unsigned integers.)
{return isv6 ? 4 : 1;}
const uint32* IPvXAddress::words | ( | ) | const [inline] |
Returns pointer to internal binary representation of address, four 32-bit unsigned integers.
{return d;}
uint32 IPvXAddress::d[4] [protected] |
Referenced by equals(), and operator<().
bool IPvXAddress::isv6 [protected] |
Referenced by equals(), and operator<().