PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PIPSocket Class Referenceabstract

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

#include <ipsock.h>

Inheritance diagram for PIPSocket:
Collaboration diagram for PIPSocket:

Classes

class  Address
 A class describing an IP address. More...
 
class  AddressAndPort
 A class describing an IP address and port number combination. More...
 
class  InterfaceEntry
 Describe an interface table entry. More...
 
class  PortRange
 Class for handling a range of ports for local binding. More...
 
struct  QoS
 
class  RouteEntry
 Describe a route table entry. More...
 
class  RouteTableDetector
 Class for detector of Route Table changes. More...
 
class  sockaddr_wrapper
 

Public Member Functions

virtual bool InternalGetLocalAddress (AddressAndPort &addrAndPort)
 
virtual bool InternalGetPeerAddress (AddressAndPort &addrAndPort)
 
virtual bool InternalListen (const Address &bind, unsigned queueSize, WORD port, Reusability reuse)
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the URL to the stream as a string. More...
 
Overrides from class PSocket
virtual PBoolean Connect (const PString &address)
 Connect a socket to a remote host on the specified port number. More...
 
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. More...
 
virtual PBoolean Listen (const Address &bind, unsigned queueSize=5, WORD port=0, Reusability reuse=AddressIsExclusive)
 
Quality of Service

This describes in a platform and as protocol independent way as possible the quality of service.

How it produces, for example, DiffServ and RSVP is up to the underlying operating system.

When reading from a string, the codes "CS0" to "CS7" and "AF11", "AF12" etc, as defined by various RFC's, is supported to map to the correct DSCP values.

virtual bool SetQoS (const QoS &qos)
 Set the current Quality of Service. More...
 
const QoSGetQoS () const
 Get the current Quality of Service. More...
 
- Public Member Functions inherited from PSocket
virtual bool Read (void *ptr, PINDEX len)
 Low level read from the channel. More...
 
virtual bool Write (const void *buf, PINDEX len)
 Low level write to the channel. More...
 
 ~PSocket ()
 
PBoolean SetOption (int option, int value, int level=SOL_SOCKET)
 Set options on the socket. More...
 
PBoolean SetOption (int option, const void *valuePtr, PINDEX valueSize, int level=SOL_SOCKET)
 Set options on the socket. More...
 
PBoolean GetOption (int option, int &value, int level=SOL_SOCKET)
 Get options on the socket. More...
 
PBoolean GetOption (int option, void *valuePtr, PINDEX valueSize, int level=SOL_SOCKET)
 Get options on the socket. More...
 
virtual bool Read (Slice *slices, size_t sliceCount)
 Low level scattered read from the channel. More...
 
virtual bool Write (const Slice *slices, size_t sliceCount)
 Low level scattered write to the channel. More...
 
virtual PBoolean Accept (PSocket &socket)
 Open a socket to a remote host on the specified port number. More...
 
virtual PBoolean Shutdown (ShutdownValue option)
 Close one or both of the data streams associated with a socket. More...
 
virtual WORD GetPortByService (const PString &service) const
 Get the port number for the specified service name. More...
 
virtual PString GetServiceByPort (WORD port) const
 Get the service name from the port number. More...
 
void SetPort (WORD port)
 Set the port number for the channel. More...
 
void SetPort (const PString &service)
 Set the port number for the channel. More...
 
WORD GetPort () const
 Get the port the TCP socket channel object instance is using. More...
 
PString GetService () const
 Get a service name for the port number the TCP socket channel object instance is using. More...
 
- Public Member Functions inherited from PChannel
PBoolean SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError)
 Set error values to those specified. More...
 
virtual Comparison Compare (const PObject &obj) const
 Get the relative rank of the two strings. More...
 
virtual PINDEX HashFunction () const
 Calculate a hash value for use in sets and dictionaries. More...
 
virtual PBoolean IsOpen () const
 Determine if the channel is currently open. More...
 
virtual P_INT_PTR GetHandle () const
 Get the integer operating system handle for the channel. More...
 
FILE * FDOpen (const char *mode)
 Re-open the device using the stdio library. More...
 
virtual PChannelGetBaseReadChannel () const
 Get the base channel of channel indirection using PIndirectChannel. More...
 
virtual PChannelGetBaseWriteChannel () const
 Get the base channel of channel indirection using PIndirectChannel. More...
 
virtual bool CloseBaseReadChannel ()
 Close the base channel of channel indirection using PIndirectChannel. More...
 
virtual bool CloseBaseWriteChannel ()
 Close the base channel of channel indirection using PIndirectChannel. More...
 
void SetReadTimeout (const PTimeInterval &time)
 Set the timeout for read operations. More...
 
PTimeInterval GetReadTimeout () const
 Get the timeout for read operations. More...
 
virtual PINDEX GetLastReadCount () const
 Get the number of bytes read by the last Read() call. More...
 
virtual PINDEX SetLastReadCount (PINDEX count)
 
virtual int ReadChar ()
 Read a single character from the channel. More...
 
PBoolean ReadBlock (void *buf, PINDEX len)
 Read len bytes into the buffer from the channel. More...
 
PString ReadString (PINDEX len)
 Read len character into a string from the channel. More...
 
void SetWriteTimeout (const PTimeInterval &time)
 Set the timeout for write operations to complete. More...
 
PTimeInterval GetWriteTimeout () const
 Get the timeout for write operations to complete. More...
 
virtual PBoolean Write (const void *buf, PINDEX len, const void *)
 Low level write to the channel with marker. More...
 
virtual PINDEX GetLastWriteCount () const
 Get the number of bytes written by the last Write() call. More...
 
virtual PINDEX SetLastWriteCount (PINDEX count)
 
PBoolean WriteChar (int c)
 Write a single character to the channel. More...
 
PBoolean WriteString (const PString &str)
 Write a string to the channel. More...
 
 ~PChannel ()
 Close down the channel. More...
 
Errors GetErrorCode (ErrorGroup group=NumErrorGroups) const
 Get normalised error code. More...
 
int GetErrorNumber (ErrorGroup group=NumErrorGroups) const
 Get OS errro code. More...
 
virtual PString GetErrorText (ErrorGroup group=NumErrorGroups) const
 Get error message description. More...
 
virtual bool ReadAsync (AsyncContext &context)
 Begin an asynchronous read from channel. More...
 
virtual void OnReadComplete (AsyncContext &context)
 User callback function for when a ReadAsync() call has completed or timed out. More...
 
virtual bool WriteAsync (AsyncContext &context)
 Begin an asynchronous write from channel. More...
 
virtual void OnWriteComplete (AsyncContext &context)
 User callback function for when a WriteAsync() call has completed or timed out. More...
 
virtual PBoolean Close ()
 Close the channel, shutting down the link to the data source. More...
 
virtual bool SetLocalEcho (bool localEcho)
 Set local echo mode. More...
 
virtual bool FlowControl (const void *flowData)
 Flow Control information Pass data to the channel for flowControl determination. More...
 
PBoolean SetBufferSize (PINDEX newSize)
 Set the iostream buffer size for reads and writes. More...
 
PBoolean SendCommandString (const PString &command)
 Send a command meta-string. More...
 
void AbortCommandString ()
 Abort a command string that is in progress. 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 PObjectPTraceObjectInstance () const
 
virtual PObjectClone () 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 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 ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Member Functions

 PIPSocket ()
 Create a new Internet Protocol socket based on the port number specified. More...
 
- Protected Member Functions inherited from PSocket
 PSocket ()
 
virtual PBoolean ConvertOSError (P_INT_PTR libcReturnValue, ErrorGroup group=LastGeneralError)
 Convert an operating system error into platform independent error. More...
 
virtual PBoolean OpenSocket ()=0
 
virtual const char * GetProtocolName () const =0
 This function returns the protocol name for the socket type. More...
 
int os_close ()
 
int os_socket (int af, int type, int proto)
 
PBoolean os_connect (struct sockaddr *sin, socklen_t size)
 
PBoolean os_vread (Slice *slices, size_t sliceCount, int flags, struct sockaddr *from, socklen_t *fromlen)
 
PBoolean os_vwrite (const Slice *slices, size_t sliceCount, int flags, struct sockaddr *to, socklen_t tolen)
 
PBoolean os_accept (PSocket &listener, struct sockaddr *addr, socklen_t *size)
 
virtual int os_errno () const
 
- Protected Member Functions inherited from PChannel
 PChannel (const PChannel &)
 
PChanneloperator= (const PChannel &)
 
int ReadCharWithTimeout (PTimeInterval &timeout)
 Read a character with specified timeout. More...
 
PBoolean ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
 
bool CheckNotOpen ()
 
PBoolean PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
 
P_INT_PTR GetOSHandleAsInt () const
 
int PXClose ()
 
 PDECLARE_MUTEX (px_threadMutex)
 
 PDECLARE_MUTEX (px_writeMutex)
 
 PChannel ()
 Create the channel. More...
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

QoS m_qos
 
- Protected Attributes inherited from PSocket
WORD m_port
 Port to be used by the socket when opening the channel. More...
 
- Protected Attributes inherited from PChannel
PTimeInterval readTimeout
 Timeout for read operations. More...
 
PTimeInterval writeTimeout
 Timeout for write operations. More...
 
atomic< P_INT_PTRos_handle
 The operating system file handle return by standard open() function. More...
 
PThreadLocalStorage< Statusm_status [NumErrorGroups+1]
 
PXBlockType px_lastBlockType
 
PThreadpx_readThread
 
PThreadpx_writeThread
 
PThreadpx_selectThread [3]
 
PCriticalSection px_selectMutex [3]
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 
virtual PString GetName () const
 Get the platform and I/O channel type name of the channel. More...
 
virtual PBoolean OpenSocket (int ipAdressFamily=PF_INET)=0
 Open an IPv4 or IPv6 socket. More...
 
static int GetDefaultIpAddressFamily ()
 Set the default IP address familly. More...
 
static void SetDefaultIpAddressFamily (int ipAdressFamily)
 
static void SetDefaultIpAddressFamilyV4 ()
 
static const PIPSocket::AddressGetDefaultIpAny ()
 
static const PIPSocket::AddressGetInvalidAddress ()
 
static void SetSuppressCanonicalName (bool suppress)
 Set flag for suppress getting canonical name when doing lookup via hostname. More...
 
static bool GetSuppressCanonicalName ()
 Get flag for suppress getting canonical name when doing lookup via hostname. More...
 

New functions for class

PString GetLocalAddress () const
 Get the Internet Protocol address and port for the local host. More...
 
bool GetLocalAddress (Address &addr) const
 
bool GetLocalAddress (Address &addr, WORD &port) const
 
bool GetLocalAddress (AddressAndPort &addr) const
 
PString GetPeerAddress () const
 Get the Internet Protocol address for the peer host and port the socket is connected to. More...
 
bool GetPeerAddress (Address &addr) const
 
bool GetPeerAddress (Address &addr, WORD &port) const
 
bool GetPeerAddress (AddressAndPort &addr) const
 
PString GetLocalHostName ()
 Get the host name for the local host. More...
 
PString GetPeerHostName ()
 Get the host name for the peer host the socket is connected to. More...
 
 PARRAY (RouteTable, RouteEntry)
 
 PARRAY (InterfaceTable, InterfaceEntry)
 
 P_DECLARE_ENUM (QoSType, BackgroundQoS, BestEffortQoS, ExcellentEffortQoS, CriticalQoS, VideoQoS, VoiceQoS, ControlQoS)
 The types of QoS supported, based on IEEE P802.1p TrafficClass parameter. More...
 
static PString GetHostName ()
 Get the "official" host name for the host specified or if none, the host this process is running on. More...
 
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. More...
 
static PBoolean GetHostAddress (const PString &hostname, Address &addr)
 
static PStringArray GetHostAliases (const PString &hostname)
 Get the alias host names for the specified host. More...
 
static PStringArray GetHostAliases (const Address &addr)
 
static PBoolean IsLocalHost (const PString &hostname)
 Determine if the specified host is actually the local machine. More...
 
static void ClearNameCache ()
 Clear the name (DNS) cache. More...
 
static PBoolean GetRouteTable (RouteTable &table)
 Get the systems route table. More...
 
static RouteTableDetectorCreateRouteTableDetector ()
 Create an object that can wait for a change in the route table or active network interfaces. More...
 
static PBoolean GetInterfaceTable (InterfaceTable &table, PBoolean includeDown=false)
 Get a list of all interfaces. More...
 
static PString GetInterface (const Address &addr)
 Get the interface name for the specified local IP address. More...
 
static Address GetInterfaceAddress (const PString &ifName, unsigned version=4)
 Get the interface name for the specified local IP address. More...
 
static PString GetInterfaceMACAddress (const char *ifName=NULL)
 Get MAC address of interface. More...
 
static Address GetNetworkInterface (unsigned version=4)
 Get the address of the first interface to the "Internet". More...
 
static Address GetGatewayAddress (unsigned 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. More...
 
static PString GetGatewayInterface (unsigned 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. More...
 
static Address GetGatewayInterfaceAddress (unsigned version=4)
 Get the IP address for the interface that is being used as the gateway, that is, the interface that packets on the default route will be sent. More...
 
static Address GetRouteInterfaceAddress (const Address &remoteAddress)
 Get the interface address that will be used to reach the specified remote address. More...
 

Additional Inherited Members

- Public Types inherited from PSocket
enum  Reusability { CanReuseAddress, AddressIsExclusive }
 Flags to reuse of port numbers in Listen() function. More...
 
- Public Types inherited from PChannel
enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }
 
enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, Unavailable, NumNormalisedErrors
}
 Normalised error codes. More...
 
enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
 Error groups. More...
 
typedef PNotifierTemplate
< PChannel::AsyncContext & > 
AsyncNotifier
 
enum  ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 }
 
- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Static Public Member Functions inherited from PSocket
static int Select (PSocket &sock1, PSocket &sock2)
 Select a socket with available data. More...
 
static int Select (PSocket &sock1, PSocket &sock2, const PTimeInterval &timeout)
 Select a socket with available data. More...
 
static Errors Select (SelectList &read)
 Select a socket with available data. More...
 
static Errors Select (SelectList &read, const PTimeInterval &timeout)
 Select a socket with available data. More...
 
static Errors Select (SelectList &read, SelectList &write)
 Select a socket with available data. More...
 
static Errors Select (SelectList &read, SelectList &write, const PTimeInterval &timeout)
 Select a socket with available data. More...
 
static Errors Select (SelectList &read, SelectList &write, SelectList &except)
 Select a socket with available data. More...
 
static Errors Select (SelectList &read, SelectList &write, SelectList &except, const PTimeInterval &timeout)
 Select a socket with available data. More...
 
static WORD Host2Net (WORD v)
 Convert from host to network byte order. More...
 
static DWORD Host2Net (DWORD v)
 Convert from host to network byte order. More...
 
static WORD Net2Host (WORD v)
 Convert from network to host byte order. More...
 
static DWORD Net2Host (DWORD v)
 Convert from network to host byte order. More...
 
static WORD GetProtocolByName (const PString &name)
 Get the number of the protocol associated with the specified name. More...
 
static PString GetNameByProtocol (WORD proto)
 Get the name of the protocol number specified. More...
 
static WORD GetPortByService (const char *protocol, const PString &service)
 Get the port number for the specified service name. More...
 
static PString GetServiceByPort (const char *protocol, WORD port)
 Get the service name from the port number. More...
 
- Static Public Member Functions inherited from PChannel
static PString GetErrorText (Errors lastError, int osError=0)
 Get error message description. More...
 
- 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 PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (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...
 
- Static Public Attributes inherited from PSocket
static unsigned NoBufferRetryCount
 

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 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
addressAddress of remote machine to connect to.

Reimplemented from PSocket.

Reimplemented in PSocksUDPSocket, PSocksSocket, PTelnetSocket, and PUDPSocket.

virtual PBoolean PIPSocket::Connect ( const Address addr)
virtual
Parameters
addrAddress of remote machine to connect to.

Reimplemented in PSocksUDPSocket, and PSocksSocket.

virtual PBoolean PIPSocket::Connect ( WORD  localPort,
const Address addr 
)
virtual
Parameters
localPortLocal port number for connection.
addrAddress of remote machine to connect to.
virtual PBoolean PIPSocket::Connect ( const Address iface,
const Address addr 
)
virtual
Parameters
ifaceAddress of local interface to us.
addrAddress of remote machine to connect to.
virtual PBoolean PIPSocket::Connect ( const Address iface,
WORD  localPort,
const Address addr 
)
virtual
Parameters
ifaceAddress of local interface to us.
localPortLocal port number for connection.
addrAddress of remote machine to connect to.
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 const PIPSocket::Address& PIPSocket::GetDefaultIpAny ( )
static

Referenced by Listen().

static Address PIPSocket::GetGatewayAddress ( unsigned  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
versionIP version number
static PString PIPSocket::GetGatewayInterface ( unsigned  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.
Parameters
versionIP version number
static Address PIPSocket::GetGatewayInterfaceAddress ( unsigned  version = 4)
static

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

This Function can be used to Bind the Listener to only the default Packet route in DHCP Environs.

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

Returns
The Local Interface IP Address for Gatway Access.
Parameters
versionIP version number
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
addrVariable to receive hosts IP address.
static PBoolean PIPSocket::GetHostAddress ( const PString hostname,
Address addr 
)
static
Parameters
hostnameName of host to get address for. This may be either a domain name or an IP number in "dot" format.
addrVariable to receive 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
hostnameName of host to get address for. This may be either a domain name or an IP number in "dot" format.
static PStringArray PIPSocket::GetHostAliases ( const Address addr)
static
Parameters
addrHosts IP address.
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 PString PIPSocket::GetHostName ( const PString hostname)
static
Parameters
hostnameHosts IP address to get name for.
static PString PIPSocket::GetHostName ( const Address addr)
static
Parameters
addrHosts IP address to get name for.
static PString PIPSocket::GetInterface ( const Address addr)
static

Get the interface name for the specified local IP address.

Parameters
addrIP address of interface
static Address PIPSocket::GetInterfaceAddress ( const PString ifName,
unsigned  version = 4 
)
static

Get the interface name for the specified local IP address.

Parameters
ifNameName of interface
versionIP version number
static PString PIPSocket::GetInterfaceMACAddress ( const char *  ifName = NULL)
static

Get MAC address of interface.

Parameters
ifNameName of interface, NULL is any
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
tableinterface table
includeDownInclude interfaces that are down
static const PIPSocket::Address& PIPSocket::GetInvalidAddress ( )
static
PString PIPSocket::GetLocalAddress ( ) const

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

Returns
false (or empty string) if the IP number was not available.
bool PIPSocket::GetLocalAddress ( Address addr) const
Parameters
addrVariable to receive hosts IP address.
bool PIPSocket::GetLocalAddress ( Address addr,
WORD &  port 
) const
Parameters
addrVariable to receive peer hosts IP address.
portVariable to receive peer hosts port number.
bool PIPSocket::GetLocalAddress ( AddressAndPort addr) const
Parameters
addrVariable to receive hosts IP address and port.
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.

Implements PChannel.

static Address PIPSocket::GetNetworkInterface ( unsigned  version = 4)
static

Get the address of the first interface to the "Internet".

This searches the interfaces for one that has a "public" IP address and thus would be access to the Internet.

Returns
false if only loopback/private interfaces could be found.
Parameters
versionIP version number
PString PIPSocket::GetPeerAddress ( ) const

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.
bool PIPSocket::GetPeerAddress ( Address addr) const
Parameters
addrVariable to receive hosts IP address.
bool PIPSocket::GetPeerAddress ( Address addr,
WORD &  port 
) const
Parameters
addrVariable to receive peer hosts IP address.
portVariable to receive peer hosts port number.
bool PIPSocket::GetPeerAddress ( AddressAndPort addr) const
Parameters
addrVariable to receive hosts IP address and port.
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.
const QoS& PIPSocket::GetQoS ( ) const
inline

Get the current Quality of Service.

References m_qos.

static Address PIPSocket::GetRouteInterfaceAddress ( const 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.
Parameters
remoteAddressRemote address to route
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
tableRoute table
static bool PIPSocket::GetSuppressCanonicalName ( )
static

Get flag for suppress getting canonical name when doing lookup via hostname.

Some badly configured DNS servers can cause long delays when this feature is used.

virtual bool PIPSocket::InternalGetLocalAddress ( AddressAndPort addrAndPort)
virtual
virtual bool PIPSocket::InternalGetPeerAddress ( AddressAndPort addrAndPort)
virtual
virtual bool PIPSocket::InternalListen ( const Address bind,
unsigned  queueSize,
WORD  port,
Reusability  reuse 
)
virtual

Reimplemented in PTCPSocket, and PUDPSocket.

Referenced by Listen().

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
hostnameName of host to get address for. This may be either a domain name or an IP number in "dot" format.
virtual PBoolean PIPSocket::Listen ( unsigned  queueSize = 5,
WORD  port = 0,
Reusability  reuse = AddressIsExclusive 
)
inlinevirtual

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
queueSizeNumber of pending accepts that may be queued.
portPort number to use for the connection.
reuseCan/Cant listen more than once.

Reimplemented from PSocket.

Reimplemented in PSocksUDPSocket, and PSocksSocket.

References GetDefaultIpAny(), and InternalListen().

virtual PBoolean PIPSocket::Listen ( const Address bind,
unsigned  queueSize = 5,
WORD  port = 0,
Reusability  reuse = AddressIsExclusive 
)
inlinevirtual
Parameters
bindLocal interface address to bind to.
queueSizeNumber of pending accepts that may be queued.
portPort number to use for the connection.
reuseCan/Can't listen more than once.

References InternalListen().

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

Open an IPv4 or IPv6 socket.

Implemented in PTCPSocket, PUDPSocket, and PICMPSocket.

PIPSocket::P_DECLARE_ENUM ( QoSType  ,
BackgroundQoS  ,
BestEffortQoS  ,
ExcellentEffortQoS  ,
CriticalQoS  ,
VideoQoS  ,
VoiceQoS  ,
ControlQoS   
)

The types of QoS supported, based on IEEE P802.1p TrafficClass parameter.

PIPSocket::PARRAY ( RouteTable  ,
RouteEntry   
)
PIPSocket::PARRAY ( InterfaceTable  ,
InterfaceEntry   
)
virtual void PIPSocket::PrintOn ( ostream &  strm) const
virtual

Output the contents of the URL to the stream as a string.

Parameters
strmStream to print the object into.

Reimplemented from PObject.

static void PIPSocket::SetDefaultIpAddressFamily ( int  ipAdressFamily)
static
static void PIPSocket::SetDefaultIpAddressFamilyV4 ( )
static
virtual bool PIPSocket::SetQoS ( const QoS qos)
virtual

Set the current Quality of Service.

Parameters
qosNew quality of service specification
static void PIPSocket::SetSuppressCanonicalName ( bool  suppress)
static

Set flag for suppress getting canonical name when doing lookup via hostname.

Some badly configured DNS servers can cause long delays when this feature is used.

Member Data Documentation

QoS PIPSocket::m_qos
protected

Referenced by GetQoS().


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