PIPSocket::Address Class Reference

A class describing an IP address. More...

`#include <ipsock.h>`

Inheritance diagram for PIPSocket::Address:

## 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) 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...
PBoolean | IsValid () const
| Check address 0.0.0.0 or ::. More...
PBoolean | IsAny () const
PBoolean | IsLoopback () const
| Check address 127.0.0.1 or ::1. More...
PBoolean | IsBroadcast () const
| Check for Broadcast address 255.255.255.255. More...
PBoolean | IsMulticast () const
| Check if address is multicast group. More...
PBoolean | IsRFC1918 () const
| Check if the remote address is a private address. More...
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)
| 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
virtual | ~PObject ()
virtual PObject * | Clone () const
| Create a copy of the class on the heap. 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 const char * | GetClass (unsigned ancestor=0) const
| Get the current dynamic type of the object instance. More...
PBoolean | IsClass (const char *cls) const
virtual PBoolean | InternalIsDescendant (const char *clsName) const
| Determine if the dynamic type of the current instance is a descendent of the specified class. 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 (int version=4)
static const Address & | GetAny (int version=4)
static const Address | GetBroadcast (int version=4)
Static Public Member Functions inherited from PObject
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
| Internal function caled from CompareObjectMemoryDirect() More...
static const char * | Class ()
| Get the name of the class as a C string. More...

## Protected Attributes

union {
in_addr four
} | v
| Runtime test of IP addresse type. More...
unsigned | version

## 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...

## Detailed Description

A class describing an IP address.

## Constructor & Destructor Documentation

## Address() [1/7]

PIPSocket::Address::Address | ( |  | ) |

Create an IPv4 address with the default address: 127.0.0.1 (loopback).

## Address() [2/7]

PIPSocket::Address::Address | ( | const PString & | dotNotation | ) |

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.

## Address() [3/7]

PIPSocket::Address::Address | ( | PINDEX | len,
|  | const BYTE * | bytes
| ) |  |

Create an IPv4 or IPv6 address from 4 or 16 byte values.

## Address() [4/7]

PIPSocket::Address::Address | ( | BYTE | b1,
|  | BYTE | b2,
|  | BYTE | b3,
|  | BYTE | b4
| ) |  |

Create an IP address from four byte values.

## Address() [5/7]

PIPSocket::Address::Address | ( | DWORD | dw | ) |

Create an IPv4 address from a four byte value in network byte order.

## Address() [6/7]

PIPSocket::Address::Address | ( | const in_addr & | addr | ) |

Create an IPv4 address from an in_addr structure.

## Address() [7/7]

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.

## Member Function Documentation

## AsString()

PString PIPSocket::Address::AsString | ( | bool | bracketIPv6 = `false` | ) | const

Format an address as a string.

Parameters

  bracketIPv6 | An IPv6 address is enclosed in []'s

Referenced by operator*=().

## Byte1()

BYTE PIPSocket::Address::Byte1 | ( |  | ) | const

Return first byte of IPv4 address.

Referenced by operator*=().

## Byte2()

BYTE PIPSocket::Address::Byte2 | ( |  | ) | const

Return second byte of IPv4 address.

Referenced by operator*=().

## Byte3()

BYTE PIPSocket::Address::Byte3 | ( |  | ) | const

Return third byte of IPv4 address.

Referenced by operator*=().

## Byte4()

BYTE PIPSocket::Address::Byte4 | ( |  | ) | const

Return fourth byte of IPv4 address.

Referenced by operator*=().

## Compare()

Comparison PIPSocket::Address::Compare | ( | const PObject & | obj | ) | const

virtual

Compare two adresses for absolute (in)equality.

Reimplemented from PObject.

Referenced by operator!=(), and operator==().

## FromString()

PBoolean PIPSocket::Address::FromString | ( | const PString & | str | ) |

Convert string to IP address. Returns true if was a valid address.

Referenced by operator*=().

## GetAny()

static const Address& PIPSocket::Address::GetAny | ( | int | version = `4` | ) |

static

Referenced by GetVersion().

## GetBroadcast()

static const Address PIPSocket::Address::GetBroadcast | ( | int | version = `4` | ) |

static

Referenced by GetVersion().

## GetLoopback()

static const Address& PIPSocket::Address::GetLoopback | ( | int | version = `4` | ) |

static

Referenced by GetVersion().

## GetPointer()

const char* PIPSocket::Address::GetPointer | ( |  | ) | const

inline

Get the pointer to IP address data.

References v.

## GetSize()

PINDEX PIPSocket::Address::GetSize | ( |  | ) | const

Get the address length (will be either 4 or 16).

Referenced by operator*=().

## GetVersion()

unsigned PIPSocket::Address::GetVersion | ( |  | ) | const

inline

Get the version of the IP address being used.

References GetAny(), GetBroadcast(), GetLoopback(), IsAny(), IsBroadcast(), IsLoopback(), IsMulticast(), IsRFC1918(), IsValid(), and version.

## IsAny()

PBoolean PIPSocket::Address::IsAny | ( |  | ) | const

Referenced by GetVersion().

## IsBroadcast()

PBoolean PIPSocket::Address::IsBroadcast | ( |  | ) | const

Check for Broadcast address 255.255.255.255.

Referenced by GetVersion().

## IsLoopback()

PBoolean PIPSocket::Address::IsLoopback | ( |  | ) | const

Check address 127.0.0.1 or ::1.

Referenced by GetVersion().

## IsMulticast()

PBoolean PIPSocket::Address::IsMulticast | ( |  | ) | const

Check if address is multicast group.

Referenced by GetVersion().

## IsRFC1918()

PBoolean PIPSocket::Address::IsRFC1918 | ( |  | ) | const

Check if the remote address is a private address.

For IPV4 this is specified RFC 1918 as the following ranges:

- 10.0.0.0 - 10.255.255.255.255
- 172.16.0.0 - 172.31.255.255
- 192.168.0.0 - 192.168.255.255

For IPV6 this is specified as any address having "1111 1110 1" for the first nine bits.

Referenced by GetVersion().

## IsValid()

PBoolean PIPSocket::Address::IsValid | ( |  | ) | const

Check address 0.0.0.0 or ::.

Referenced by GetVersion().

## operator DWORD()

PIPSocket::Address::operator DWORD | ( |  | ) | const

Return IPv4 address in network order.

## operator in_addr()

PIPSocket::Address::operator in_addr | ( |  | ) | const

Return IPv4 address in network order.

## operator PString()

PIPSocket::Address::operator PString | ( |  | ) | const

Format an address as a string.

## operator!=() [1/4]

bool PIPSocket::Address::operator!= | ( | const Address & | addr | ) | const

inline

References Compare(), PObject::EqualTo, and operator==().

Referenced by operator!=().

## operator!=() [2/4]

bool PIPSocket::Address::operator!= | ( | in_addr & | addr | ) | const

inline

References operator==().

## operator!=() [3/4]

bool PIPSocket::Address::operator!= | ( | DWORD | dw | ) | const

inline

References operator!=(), and operator==().

## operator!=() [4/4]

bool PIPSocket::Address::operator!= | ( | int | i | ) | const

inline

References operator*=(), and operator==().

## operator*=()

bool PIPSocket::Address::operator*= | ( | const Address & | addr | ) | const

inline

Compare two addresses for equivalence.

This will return true if the two addresses are equivalent even if they are IPV6 and IPV4.

References AsString(), Byte1(), Byte2(), Byte3(), Byte4(), FromString(), GetSize(), operator==(), and operator[]().

Referenced by operator!=().

## operator=() [1/3]

Address& PIPSocket::Address::operator= | ( | const in_addr & | addr | ) |

Copy an address from another IP v4 address.

## operator=() [2/3]

Address& PIPSocket::Address::operator= | ( | const PString & | dotNotation | ) |

Copy an address from a string.

## operator=() [3/3]

Address& PIPSocket::Address::operator= | ( | DWORD | dw | ) |

Copy an address from a four byte value in network order.

## operator==() [1/4]

bool PIPSocket::Address::operator== | ( | const Address & | addr | ) | const

inline

References Compare(), and PObject::EqualTo.

Referenced by operator!=(), and operator*=().

## operator==() [2/4]

bool PIPSocket::Address::operator== | ( | in_addr & | addr | ) | const

## operator==() [3/4]

bool PIPSocket::Address::operator== | ( | DWORD | dw | ) | const

## operator==() [4/4]

bool PIPSocket::Address::operator== | ( | int | i | ) | const

inline

References operator==().

Referenced by operator==().

## operator[]()

BYTE PIPSocket::Address::operator[] | ( | PINDEX | idx | ) | const

Return specified byte of IPv4 or IPv6 address.

Referenced by operator*=().

## Friends And Related Function Documentation

## operator<<

ostream& operator<< | ( | ostream & | s,
|  | const Address & | a
| ) |  |

friend

Output IPv6 & IPv4 address as a string to the specified string.

## operator>>

istream& operator>> | ( | istream & | s,
|  | Address & | a
| ) |  |

friend

Input IPv4 (not IPv6 yet!) address as a string from the specified string.

## Member Data Documentation

## four

in_addr PIPSocket::Address::four

## v

union { ... } PIPSocket::Address::v

Runtime test of IP addresse type.

Referenced by GetPointer().

## version

unsigned PIPSocket::Address::version

protected

Referenced by GetVersion().

The documentation for this class was generated from the following file:

- ipsock.h