PIPSocket::Address Class Reference

#include <ipsock.h>

Inheritance diagram for PIPSocket::Address:
PObject

List of all members.

Public Member Functions

Comparison Compare (const PObject &obj) const
 Compare two adresses for absolute (in)equality.
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
PString AsString (bool bracketIPv6=false) const
 Format an address as a string.
PBoolean FromString (const PString &str)
 Convert string to IP address. Returns PTrue if was a valid address.
 operator PString () const
 Format an address as a string.
 operator in_addr () const
 Return IPv4 address in network order.
 operator DWORD () const
 Return IPv4 address in network order.
BYTE Byte1 () const
 Return first byte of IPv4 address.
BYTE Byte2 () const
 Return second byte of IPv4 address.
BYTE Byte3 () const
 Return third byte of IPv4 address.
BYTE Byte4 () const
 Return fourth byte of IPv4 address.
BYTE operator[] (PINDEX idx) const
 Return specified byte of IPv4 or IPv6 address.
PINDEX GetSize () const
 Get the address length (will be either 4 or 16).
const char * GetPointer () const
 Get the pointer to IP address data.
unsigned GetVersion () const
 Get the version of the IP address being used.
PBoolean IsValid () const
 Check address 0.0.0.0 or ::.
PBoolean IsAny () const
PBoolean IsLoopback () const
 Check address 127.0.0.1 or ::1.
PBoolean IsBroadcast () const
 Check for Broadcast address 255.255.255.255.
PBoolean IsMulticast () const
 Check if address is multicast group.
PBoolean IsRFC1918 () const
Address constructors

 Address ()
 Create an IPv4 address with the default address: 127.0.0.1 (loopback).
 Address (const PString &dotNotation)
 Address (PINDEX len, const BYTE *bytes)
 Create an IPv4 or IPv6 address from 4 or 16 byte values.
 Address (BYTE b1, BYTE b2, BYTE b3, BYTE b4)
 Create an IP address from four byte values.
 Address (DWORD dw)
 Create an IPv4 address from a four byte value in network byte order.
 Address (const in_addr &addr)
 Create an IPv4 address from an in_addr structure.
 Address (const int ai_family, const int ai_addrlen, struct sockaddr *ai_addr)
Addressoperator= (const in_addr &addr)
 Copy an address from another IP v4 address.
Addressoperator= (const PString &dotNotation)
 Copy an address from a string.
Addressoperator= (DWORD dw)
 Copy an address from a four byte value in network order.

Static Public Member Functions

static const AddressGetLoopback (int version=4)
static const AddressGetAny (int version=4)
static const Address GetBroadcast (int version=4)

Protected Attributes

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

Friends

ostream & operator<< (ostream &s, const Address &a)
 Output IPv6 & IPv4 address as a string to the specified string.
istream & operator>> (istream &s, Address &a)
 Input IPv4 (not IPv6 yet!) address as a string from the specified string.

Detailed Description

A class describing an IP address.


Constructor & Destructor Documentation

PIPSocket::Address::Address (  ) 

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

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.

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

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.


Member Function Documentation

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 PIPSocketAddressAndPort::AsString().

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.

Comparison PIPSocket::Address::Compare ( const PObject obj  )  const [virtual]

Compare two adresses for absolute (in)equality.

Reimplemented from PObject.

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

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

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

static const Address& PIPSocket::Address::GetAny ( int  version = 4  )  [static]
static const Address PIPSocket::Address::GetBroadcast ( int  version = 4  )  [static]
static const Address& PIPSocket::Address::GetLoopback ( int  version = 4  )  [static]
const char* PIPSocket::Address::GetPointer (  )  const [inline]

Get the pointer to IP address data.

References v.

PINDEX PIPSocket::Address::GetSize (  )  const

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

unsigned PIPSocket::Address::GetVersion (  )  const [inline]

Get the version of the IP address being used.

References version.

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

Check for Broadcast address 255.255.255.255.

PBoolean PIPSocket::Address::IsLoopback (  )  const

Check address 127.0.0.1 or ::1.

PBoolean PIPSocket::Address::IsMulticast (  )  const

Check if address is multicast group.

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.

PBoolean PIPSocket::Address::IsValid (  )  const

Check address 0.0.0.0 or ::.

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.

bool PIPSocket::Address::operator!= ( int  i  )  const [inline]

References operator==().

bool PIPSocket::Address::operator!= ( DWORD  dw  )  const [inline]

References operator==().

bool PIPSocket::Address::operator!= ( in_addr &  addr  )  const [inline]

References operator==().

bool PIPSocket::Address::operator!= ( const Address addr  )  const [inline]

References Compare(), and PObject::EqualTo.

bool PIPSocket::Address::operator*= ( const Address addr  )  const [inline]

Compare two addresses for equivalence. This will return PTrue if the two addresses are equivalent even if they are IPV6 and IPV4.

References operator==().

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

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

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

Copy an address from a string.

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

Copy an address from another IP v4 address.

bool PIPSocket::Address::operator== ( int  i  )  const [inline]

References operator==().

Referenced by operator==().

bool PIPSocket::Address::operator== ( DWORD  dw  )  const
bool PIPSocket::Address::operator== ( in_addr &  addr  )  const
bool PIPSocket::Address::operator== ( const Address addr  )  const [inline]

References Compare(), and PObject::EqualTo.

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

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

Return specified byte of IPv4 or IPv6 address.


Friends And Related Function Documentation

ostream& operator<< ( ostream &  s,
const Address a 
) [friend]

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

istream& operator>> ( istream &  s,
Address a 
) [friend]

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


Member Data Documentation

union { ... } PIPSocket::Address::v [protected]

Runtime test of IP addresse type.

Referenced by GetPointer().

unsigned PIPSocket::Address::version [protected]

Referenced by GetVersion().


The documentation for this class was generated from the following file:
Generated on Fri May 28 07:32:34 2010 for PTLib by  doxygen 1.6.3