PIPSocket Class Reference

This class describes a type of socket that will communicate using the Internet Protocol. More...

#include <ipsock.h>

Inheritance diagram for PIPSocket:

PSocket PChannel PObject PIPDatagramSocket PTCPSocket PICMPSocket PUDPSocket PSocksSocket PTelnetSocket PSocksUDPSocket PSTUNUDPSocket PSocks4Socket PSocks5Socket List of all members.
virtual PString GetName () const
 Get the platform and I/O channel type name of the channel.
virtual PBoolean OpenSocket (int ipAdressFamily=PF_INET)=0
 Open an IPv4 or IPv6 socket.
static int GetDefaultIpAddressFamily ()
 Set the default IP address familly.
static void SetDefaultIpAddressFamily (int ipAdressFamily)
static void SetDefaultIpAddressFamilyV4 ()
static PIPSocket::Address GetDefaultIpAny ()

New functions for class

virtual PString GetLocalAddress ()
 Get the Internet Protocol address and port for the local host.
virtual PBoolean GetLocalAddress (Address &addr)
virtual PBoolean GetLocalAddress (PIPSocketAddressAndPort &addr)
virtual PBoolean GetLocalAddress (Address &addr, WORD &port)
virtual PString GetPeerAddress ()
 Get the Internet Protocol address for the peer host and port the socket is connected to.
virtual PBoolean GetPeerAddress (Address &addr)
virtual PBoolean GetPeerAddress (PIPSocketAddressAndPort &addr)
virtual PBoolean GetPeerAddress (Address &addr, WORD &port)
PString GetLocalHostName ()
 Get the host name for the local host.
PString GetPeerHostName ()
 Get the host name for the peer host the socket is connected to.
 PARRAY (RouteTable, RouteEntry)
 PARRAY (InterfaceTable, InterfaceEntry)
PBoolean SetCaptureReceiveToAddress ()
 Set flag to capture interface address for incoming packets.
PIPSocket::Address GetLastReceiveToAddress () const
 Return the interface address of the last incoming packet.
static PString GetHostName ()
 Get the "official" host name for the host specified or if none, the host this process is running on.
static PString GetHostName (const PString &hostname)
static PString GetHostName (const Address &addr)
static PBoolean GetHostAddress (Address &addr)
 Get the Internet Protocol address for the specified host, or if none specified, for the host this process is running on.
static PBoolean GetHostAddress (const PString &hostname, Address &addr)
static PStringArray GetHostAliases (const PString &hostname)
 Get the alias host names for the specified host.
static PStringArray GetHostAliases (const Address &addr)
static PBoolean IsLocalHost (const PString &hostname)
 Determine if the specified host is actually the local machine.
static void ClearNameCache ()
 Clear the name (DNS) cache.
static PBoolean GetGatewayAddress (Address &addr, int version=4)
 Get the IP address that is being used as the gateway, that is, the computer that packets on the default route will be sent.
static PString GetGatewayInterface (int version=4)
 Get the name for the interface that is being used as the gateway, that is, the interface that packets on the default route will be sent.
static PIPSocket::Address GetRouteInterfaceAddress (PIPSocket::Address remoteAddress)
 Get the interface address that will be used to reach the specified remote address.
static PBoolean GetRouteTable (RouteTable &table)
 Get the systems route table.
static RouteTableDetectorCreateRouteTableDetector ()
 Create an object that can wait for a change in the route table or active network interfaces.
static PBoolean GetInterfaceTable (InterfaceTable &table, PBoolean includeDown=false)
 Get a list of all interfaces.
static PBoolean GetNetworkInterface (PIPSocket::Address &addr)
 Get the address of an interface that corresponds to a real network.

Public Member Functions

Overrides from class PSocket
virtual PBoolean Connect (const PString &address)
 Connect a socket to a remote host on the specified port number.
virtual PBoolean Connect (const Address &addr)
virtual PBoolean Connect (WORD localPort, const Address &addr)
virtual PBoolean Connect (const Address &iface, const Address &addr)
virtual PBoolean Connect (const Address &iface, WORD localPort, const Address &addr)
virtual PBoolean Listen (unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
 Listen on a socket for a remote host on the specified port number.
virtual PBoolean Listen (const Address &bind, unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)

Protected Member Functions

 PIPSocket ()
 Create a new Internet Protocol socket based on the port number specified.

Classes

class  Address
 A class describing an IP address. More...
class  InterfaceEntry
 Describe an interface table entry. More...
class  RouteEntry
 Describe a route table entry. More...
class  RouteTableDetector
 Class for detector of Route Table changes. More...

Detailed Description

This class describes a type of socket that will communicate using the Internet Protocol.

If P_HAS_IPV6 is not set, IPv4 only is supported. If P_HAS_IPV6 is set, both IPv4 and IPv6 adresses are supported, with IPv4 as default. This allows to transparently use IPv4, IPv6 or Dual stack operating systems.


Constructor & Destructor Documentation

PIPSocket::PIPSocket (  )  [protected]

Create a new Internet Protocol socket based on the port number specified.


Member Function Documentation

static void PIPSocket::ClearNameCache (  )  [static]

Clear the name (DNS) cache.

virtual PBoolean PIPSocket::Connect ( const Address iface,
WORD  localPort,
const Address addr 
) [virtual]

Parameters:
iface  Address of local interface to us.
localPort  Local port number for connection.
addr  Address of remote machine to connect to.

virtual PBoolean PIPSocket::Connect ( const Address iface,
const Address addr 
) [virtual]

Parameters:
iface  Address of local interface to us.
addr  Address of remote machine to connect to.

virtual PBoolean PIPSocket::Connect ( WORD  localPort,
const Address addr 
) [virtual]

Parameters:
localPort  Local port number for connection.
addr  Address of remote machine to connect to.

virtual PBoolean PIPSocket::Connect ( const Address addr  )  [virtual]

Parameters:
addr  Address of remote machine to connect to.

virtual PBoolean PIPSocket::Connect ( const PString address  )  [virtual]

Connect a socket to a remote host on the specified port number.

This is typically used by the client or initiator of a communications channel. This connects to a "listening" socket at the other end of the communications channel.

The port number as defined by the object instance construction or the PIPSocket::SetPort() function.

Returns:
true if the channel was successfully connected to the remote host.
Parameters:
address  Address of remote machine to connect to.

Reimplemented from PSocket.

Reimplemented in PUDPSocket, PSocksSocket, PSocksUDPSocket, and PTelnetSocket.

static RouteTableDetector* PIPSocket::CreateRouteTableDetector (  )  [static]

Create an object that can wait for a change in the route table or active network interfaces.

If the platform does not support this mechanism then a fake class is created using PSyncPoint to wait for the specified amount of time.

Returns:
Pointer to some object, never returns NULL.

static int PIPSocket::GetDefaultIpAddressFamily (  )  [static]

Set the default IP address familly.

Needed as lot of IPv6 stack are not able to receive IPv4 packets in IPv6 sockets They are not RFC 2553, chapter 7.3, compliant. As a consequence, when opening a socket to listen to port 1720 (for example) from any remot host one must decide whether this is an IPv4 or an IPv6 socket...

static PIPSocket::Address PIPSocket::GetDefaultIpAny (  )  [static]

static PBoolean PIPSocket::GetGatewayAddress ( Address addr,
int  version = 4 
) [static]

Get the IP address that is being used as the gateway, that is, the computer that packets on the default route will be sent.

The string returned may be used in the Connect() function to open that interface.

Note that the driver does not need to be open for this function to work.

Returns:
true if there was a gateway.
Parameters:
addr  Variable to receive the IP address.
version  IP version number

static PString PIPSocket::GetGatewayInterface ( int  version = 4  )  [static]

Get the name for the interface that is being used as the gateway, that is, the interface that packets on the default route will be sent.

The string returned may be used in the Connect() function to open that interface.

Note that the driver does not need to be open for this function to work.

Returns:
String name of the gateway device, or empty string if there is none.

static PBoolean PIPSocket::GetHostAddress ( const PString hostname,
Address addr 
) [static]

Parameters:
hostname  Name of host to get address for. This may be either a domain name or an IP number in "dot" format.
addr  Variable to receive hosts IP address.

static PBoolean PIPSocket::GetHostAddress ( Address addr  )  [static]

Get the Internet Protocol address for the specified host, or if none specified, for the host this process is running on.

Returns:
true if the IP number was returned.
Parameters:
addr  Variable to receive hosts IP address.

static PStringArray PIPSocket::GetHostAliases ( const Address addr  )  [static]

Parameters:
addr  Hosts IP address.

static PStringArray PIPSocket::GetHostAliases ( const PString hostname  )  [static]

Get the alias host names for the specified host.

This includes all DNS names, CNAMEs, names in the local hosts file and IP numbers (as "dot" format strings) for the host.

Returns:
Array of strings for each alias for the host.
Parameters:
hostname  Name of host to get address for. This may be either a domain name or an IP number in "dot" format.

static PString PIPSocket::GetHostName ( const Address addr  )  [static]

Parameters:
addr  Hosts IP address to get name for.

static PString PIPSocket::GetHostName ( const PString hostname  )  [static]

Parameters:
hostname  Hosts IP address to get name for.

static PString PIPSocket::GetHostName (  )  [static]

Get the "official" host name for the host specified or if none, the host this process is running on.

The host may be specified as an IP number or a hostname alias and is resolved to the canonical form.

Returns:
Name of the host or IP number of host.

static PBoolean PIPSocket::GetInterfaceTable ( InterfaceTable &  table,
PBoolean  includeDown = false 
) [static]

Get a list of all interfaces.

Returns:
true if the interface table is returned, false if an error occurs.
Parameters:
table  interface table
includeDown  Include interfaces that are down

PIPSocket::Address PIPSocket::GetLastReceiveToAddress (  )  const [inline]

Return the interface address of the last incoming packet.

virtual PBoolean PIPSocket::GetLocalAddress ( Address addr,
WORD &  port 
) [virtual]

Parameters:
addr  Variable to receive peer hosts IP address.
port  Variable to receive peer hosts port number.

virtual PBoolean PIPSocket::GetLocalAddress ( PIPSocketAddressAndPort addr  )  [virtual]

Parameters:
addr  Variable to receive hosts IP address and port.

virtual PBoolean PIPSocket::GetLocalAddress ( Address addr  )  [virtual]

Parameters:
addr  Variable to receive hosts IP address.

virtual PString PIPSocket::GetLocalAddress (  )  [virtual]

Get the Internet Protocol address and port for the local host.

Returns:
false (or empty string) if the IP number was not available.

PString PIPSocket::GetLocalHostName (  ) 

Get the host name for the local host.

Returns:
Name of the host, or an empty string if an error occurs.

virtual PString PIPSocket::GetName (  )  const [virtual]

Get the platform and I/O channel type name of the channel.

For an IP socket this returns the host name of the peer the socket is connected to, followed by the socket number it is connected to.

Returns:
The name of the channel.

Reimplemented from PChannel.

static PBoolean PIPSocket::GetNetworkInterface ( PIPSocket::Address addr  )  [static]

Get the address of an interface that corresponds to a real network.

Returns:
false if only loopback interfaces could be found, else true.

virtual PBoolean PIPSocket::GetPeerAddress ( Address addr,
WORD &  port 
) [virtual]

Parameters:
addr  Variable to receive peer hosts IP address.
port  Variable to receive peer hosts port number.

virtual PBoolean PIPSocket::GetPeerAddress ( PIPSocketAddressAndPort addr  )  [virtual]

Parameters:
addr  Variable to receive hosts IP address and port.

virtual PBoolean PIPSocket::GetPeerAddress ( Address addr  )  [virtual]

Parameters:
addr  Variable to receive hosts IP address.

virtual PString PIPSocket::GetPeerAddress (  )  [virtual]

Get the Internet Protocol address for the peer host and port the socket is connected to.

Returns:
false (or empty string) if the IP number was not available.

PString PIPSocket::GetPeerHostName (  ) 

Get the host name for the peer host the socket is connected to.

Returns:
Name of the host, or an empty string if an error occurs.

static PIPSocket::Address PIPSocket::GetRouteInterfaceAddress ( PIPSocket::Address  remoteAddress  )  [static]

Get the interface address that will be used to reach the specified remote address.

Uses longest prefix match when multiple matching interfaces are found.

Returns:
Network interface address.

static PBoolean PIPSocket::GetRouteTable ( RouteTable &  table  )  [static]

Get the systems route table.

Returns:
true if the route table is returned, false if an error occurs.
Parameters:
table  Route table

static PBoolean PIPSocket::IsLocalHost ( const PString hostname  )  [static]

Determine if the specified host is actually the local machine.

This can be any of the host aliases or multi-homed IP numbers or even the special number 127.0.0.1 for the loopback device.

Returns:
true if the host is the local machine.
Parameters:
hostname  Name of host to get address for. This may be either a domain name or an IP number in "dot" format.

virtual PBoolean PIPSocket::Listen ( const Address bind,
unsigned  queueSize = 5,
WORD  port = 0,
Reusability  reuse = AddressIsExclusive 
) [virtual]

Parameters:
bind  Local interface address to bind to.
queueSize  Number of pending accepts that may be queued.
port  Port number to use for the connection.
reuse  Can/Can't listen more than once.

virtual PBoolean PIPSocket::Listen ( unsigned  queueSize = 5,
WORD  port = 0,
Reusability  reuse = AddressIsExclusive 
) [virtual]

Listen on a socket for a remote host on the specified port number.

This may be used for server based applications. A "connecting" socket begins a connection by initiating a connection to this socket. An active socket of this type is then used to generate other "accepting" sockets which establish a two way communications channel with the "connecting" socket.

If the port parameter is zero then the port number as defined by the object instance construction or the PIPSocket::SetPort() function.

For the UDP protocol, the queueSize parameter is ignored.

Returns:
true if the channel was successfully opened.
Parameters:
queueSize  Number of pending accepts that may be queued.
port  Port number to use for the connection.
reuse  Can/Cant listen more than once.

Reimplemented in PTCPSocket, PSocksSocket, and PSocksUDPSocket.

virtual PBoolean PIPSocket::OpenSocket ( int  ipAdressFamily = PF_INET  )  [pure virtual]

Open an IPv4 or IPv6 socket.

Implemented in PICMPSocket, PTCPSocket, and PUDPSocket.

PIPSocket::PARRAY ( InterfaceTable  ,
InterfaceEntry   
)

PIPSocket::PARRAY ( RouteTable  ,
RouteEntry   
)

PBoolean PIPSocket::SetCaptureReceiveToAddress (  )  [inline]

Set flag to capture interface address for incoming packets.

Returns:
true if host is able to capture incoming address, else false

static void PIPSocket::SetDefaultIpAddressFamily ( int  ipAdressFamily  )  [static]

static void PIPSocket::SetDefaultIpAddressFamilyV4 (  )  [static]


The documentation for this class was generated from the following file:
Generated on Fri Oct 14 01:44:12 2011 for PTLib by  doxygen 1.4.7