|
PTLib
Version 2.18.8
|
A class describing an IP address. More...
#include <ipsock.h>


Public Member Functions | |
| Comparison | Compare (const PObject &obj) const |
| Compare two adresses for absolute (in)equality. More... | |
| bool | operator== (const Address &addr) const |
| bool | operator!= (const Address &addr) const |
| bool | operator== (in_addr &addr) const |
| bool | operator!= (in_addr &addr) const |
| bool | operator== (DWORD dw) const |
| bool | operator!= (DWORD dw) const |
| bool | operator== (int i) const |
| bool | operator!= (int i) const |
| bool | operator*= (const Address &addr) const |
| Compare two addresses for equivalence. More... | |
| PString | AsString (bool bracketIPv6=false, bool excludeScope=false) const |
| Format an address as a string. More... | |
| PBoolean | FromString (const PString &str) |
| Convert string to IP address. Returns true if was a valid address. More... | |
| operator PString () const | |
| Format an address as a string. More... | |
| operator in_addr () const | |
| Return IPv4 address in network order. More... | |
| operator DWORD () const | |
| Return IPv4 address in network order. More... | |
| BYTE | Byte1 () const |
| Return first byte of IPv4 address. More... | |
| BYTE | Byte2 () const |
| Return second byte of IPv4 address. More... | |
| BYTE | Byte3 () const |
| Return third byte of IPv4 address. More... | |
| BYTE | Byte4 () const |
| Return fourth byte of IPv4 address. More... | |
| BYTE | operator[] (PINDEX idx) const |
| Return specified byte of IPv4 or IPv6 address. More... | |
| PINDEX | GetSize () const |
| Get the address length (will be either 4 or 16). More... | |
| const char * | GetPointer () const |
| Get the pointer to IP address data. More... | |
| unsigned | GetVersion () const |
| Get the version of the IP address being used. More... | |
| bool | IsValid () const |
| Check for illegal address. More... | |
| bool | IsAny () const |
| Check address 0.0.0.0 or ::. More... | |
| bool | IsLoopback () const |
| Check address 127.0.0.1 or ::1. More... | |
| bool | IsBroadcast () const |
| Check for Broadcast address 255.255.255.255. More... | |
| bool | IsMulticast () const |
| Check if address is multicast group. More... | |
| bool | IsSubNet (const Address &network, const Address &mask) const |
| Check if this address is within the sub-net. More... | |
| bool | IsPrivate () const |
| Check if the remote address is a private address. More... | |
| P_DEPRECATED bool | IsRFC1918 () const |
Address constructors | |
| Address () | |
| Create an IPv4 address with the default address: 127.0.0.1 (loopback). More... | |
| Address (const PString &dotNotation) | |
| Create an IP address from string notation, eg dot notation x.x.x.x. More... | |
| Address (PINDEX len, const BYTE *bytes, int scope=0) | |
| Create an IPv4 or IPv6 address from 4 or 16 byte values. More... | |
| Address (BYTE b1, BYTE b2, BYTE b3, BYTE b4) | |
| Create an IP address from four byte values. More... | |
| Address (DWORD dw) | |
| Create an IPv4 address from a four byte value in network byte order. More... | |
| Address (const in_addr &addr) | |
| Create an IPv4 address from an in_addr structure. More... | |
| Address (const int ai_family, const int ai_addrlen, struct sockaddr *ai_addr) | |
| Create an IP (v4 or v6) address from a sockaddr (sockaddr_in, sockaddr_in6 or sockaddr_in6_old) structure. More... | |
| Address & | operator= (const in_addr &addr) |
| Copy an address from another IP v4 address. More... | |
| Address & | operator= (const PString &dotNotation) |
| Copy an address from a string. More... | |
| Address & | operator= (DWORD dw) |
| Copy an address from a four byte value in network order. More... | |
Public Member Functions inherited from PObject | |
| __inline unsigned | GetTraceContextIdentifier () const |
| Get PTRACE context identifier. More... | |
| __inline void | SetTraceContextIdentifier (unsigned id) |
| __inline void | SetTraceContextIdentifier (const PObject &obj) |
| __inline void | SetTraceContextIdentifier (const PObject *obj) |
| __inline void | CopyTraceContextIdentifier (PObject &obj) const |
| __inline void | CopyTraceContextIdentifier (PObject *obj) const |
| virtual | ~PObject () |
| __inline const char * | GetClass () const |
| __inline bool | IsClass (const char *name) const |
| __inline const PObject * | PTraceObjectInstance () const |
| virtual PObject * | Clone () const |
| Create a copy of the class on the heap. More... | |
| template<class CLS > | |
| CLS * | CloneAs () const |
| As for Clone() but converts to specified type. More... | |
| virtual PINDEX | HashFunction () const |
This function yields a hash value required by the PDictionary class. More... | |
| virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
| Determine the byte wise comparison of two objects. More... | |
| bool | operator== (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator!= (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator< (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator> (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator<= (const PObject &obj) const |
| Compare the two objects. More... | |
| bool | operator>= (const PObject &obj) const |
| Compare the two objects. More... | |
| virtual void | PrintOn (ostream &strm) const |
| Output the contents of the object to the stream. More... | |
| virtual void | ReadFrom (istream &strm) |
| Input the contents of the object from the stream. More... | |
Static Public Member Functions | |
| static const Address & | GetLoopback (unsigned version=4) |
| static const Address & | GetAny (unsigned version=4) |
| static const Address | GetBroadcast (unsigned version=4) |
Static Public Member Functions inherited from PObject | |
| static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
| static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
| static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
| static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
| static __inline const char * | Class () |
| static __inline const PObject * | PTraceObjectInstance (const char *) |
| static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
| template<typename T > | |
| static Comparison | Compare2 (T v1, T v2) |
| Compare two types, returning Comparison type. More... | |
| static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
| Internal function caled from CompareObjectMemoryDirect() More... | |
Protected Attributes | |
| union { | |
| in_addr m_four | |
| } | m_v |
| Runtime test of IP addresse type. More... | |
| unsigned | m_version |
| int | m_scope6 |
Protected Attributes inherited from PObject | |
| unsigned | m_traceContextIdentifier |
Friends | |
| ostream & | operator<< (ostream &s, const Address &a) |
| Output IPv6 & IPv4 address as a string to the specified string. More... | |
| istream & | operator>> (istream &s, Address &a) |
| Input IPv4 (not IPv6 yet!) address as a string from the specified string. More... | |
Additional Inherited Members | |
Public Types inherited from PObject | |
| enum | Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 } |
Result of the comparison operation performed by the Compare() function. More... | |
Protected Member Functions inherited from PObject | |
| PObject () | |
| Constructor for PObject, made protected so cannot ever create one on its own. More... | |
A class describing an IP address.
| PIPSocket::Address::Address | ( | ) |
Create an IPv4 address with the default address: 127.0.0.1 (loopback).
|
explicit |
Create an IP address from string notation, eg dot notation x.x.x.x.
for IPv4, or colon notation x:x:x::xxx for IPv6.
| PIPSocket::Address::Address | ( | PINDEX | len, |
| const BYTE * | bytes, | ||
| int | scope = 0 |
||
| ) |
Create an IPv4 or IPv6 address from 4 or 16 byte values.
| PIPSocket::Address::Address | ( | BYTE | b1, |
| BYTE | b2, | ||
| BYTE | b3, | ||
| BYTE | b4 | ||
| ) |
Create an IP address from four byte values.
| PIPSocket::Address::Address | ( | DWORD | dw | ) |
Create an IPv4 address from a four byte value in network byte order.
| PIPSocket::Address::Address | ( | const in_addr & | addr | ) |
Create an IPv4 address from an in_addr structure.
| PIPSocket::Address::Address | ( | const int | ai_family, |
| const int | ai_addrlen, | ||
| struct sockaddr * | ai_addr | ||
| ) |
Create an IP (v4 or v6) address from a sockaddr (sockaddr_in, sockaddr_in6 or sockaddr_in6_old) structure.
| PString PIPSocket::Address::AsString | ( | bool | bracketIPv6 = false, |
| bool | excludeScope = false |
||
| ) | const |
Format an address as a string.
| bracketIPv6 | An IPv6 address is enclosed in []'s |
| excludeScope | An IPv6 address includes xxx for scope ID |
| BYTE PIPSocket::Address::Byte1 | ( | ) | const |
Return first byte of IPv4 address.
| BYTE PIPSocket::Address::Byte2 | ( | ) | const |
Return second byte of IPv4 address.
| BYTE PIPSocket::Address::Byte3 | ( | ) | const |
Return third byte of IPv4 address.
| BYTE PIPSocket::Address::Byte4 | ( | ) | const |
Return fourth byte of IPv4 address.
|
virtual |
Compare two adresses for absolute (in)equality.
Reimplemented from PObject.
Referenced by operator!=(), and operator==().
Convert string to IP address. Returns true if was a valid address.
|
static |
|
static |
|
static |
|
inline |
Get the pointer to IP address data.
References m_v.
| PINDEX PIPSocket::Address::GetSize | ( | ) | const |
Get the address length (will be either 4 or 16).
|
inline |
Get the version of the IP address being used.
References m_version.
| bool PIPSocket::Address::IsAny | ( | ) | const |
Check address 0.0.0.0 or ::.
| bool PIPSocket::Address::IsBroadcast | ( | ) | const |
Check for Broadcast address 255.255.255.255.
| bool PIPSocket::Address::IsLoopback | ( | ) | const |
Check address 127.0.0.1 or ::1.
| bool PIPSocket::Address::IsMulticast | ( | ) | const |
Check if address is multicast group.
| bool PIPSocket::Address::IsPrivate | ( | ) | const |
Check if the remote address is a private address.
For IPV4 this is specified as the following ranges:
For IPV6 this is specified as any address having "1111 1110 1" for the first nine bits.
Referenced by IsRFC1918().
|
inline |
References IsPrivate().
Check if this address is within the sub-net.
|
inline |
Check for illegal address.
References m_version.
Referenced by PIPSocket::AddressAndPort::IsValid().
| PIPSocket::Address::operator DWORD | ( | ) | const |
Return IPv4 address in network order.
| PIPSocket::Address::operator in_addr | ( | ) | const |
Return IPv4 address in network order.
| PIPSocket::Address::operator PString | ( | ) | const |
Format an address as a string.
|
inline |
References Compare(), and PObject::EqualTo.
|
inline |
References operator==().
|
inline |
References operator==().
|
inline |
References operator==().
|
inline |
Compare two addresses for equivalence.
This will return true if the two addresses are equivalent even if they are IPV6 and IPV4.
References operator==().
| Address& PIPSocket::Address::operator= | ( | const in_addr & | addr | ) |
Copy an address from another IP v4 address.
Copy an address from a string.
| Address& PIPSocket::Address::operator= | ( | DWORD | dw | ) |
Copy an address from a four byte value in network order.
|
inline |
References Compare(), and PObject::EqualTo.
Referenced by operator!=(), and operator*=().
| bool PIPSocket::Address::operator== | ( | in_addr & | addr | ) | const |
| bool PIPSocket::Address::operator== | ( | DWORD | dw | ) | const |
|
inline |
References operator==().
Referenced by operator==().
| BYTE PIPSocket::Address::operator[] | ( | PINDEX | idx | ) | const |
Return specified byte of IPv4 or IPv6 address.
|
friend |
Output IPv6 & IPv4 address as a string to the specified string.
If the stream flag hex is set, then an IPv6 address is surrounded by square brackets []. If the stream flag fixed is set, the an IPv6 address will have the scope ID (xxx) suppressed.
|
friend |
Input IPv4 (not IPv6 yet!) address as a string from the specified string.
| in_addr PIPSocket::Address::m_four |
|
protected |
| union { ... } PIPSocket::Address::m_v |
Runtime test of IP addresse type.
Referenced by GetPointer().
|
protected |
Referenced by GetVersion(), and IsValid().