NDSocketAddress Class Reference

Provides an operating system agnostic description of an IP address and port number. More...

List of all members.

Public Types

typedef uint16_t PortID
 IPv4 socket port number.
typedef uint32_t AddrIPV4
 IPv4 IP address in uint32_t format.

Public Member Functions

 NDSocketAddress ()
 Do not use the constructor, see NDCore::createSocketAddress().
 ~NDSocketAddress ()
void clear (void)
 Resets address to zeros.
void setPort (PortID port)
 Sets the port number.
PortID getPort (void) const
 Gets the port number.
void setAddressInt (AddrIPV4 ipaddr)
 Sets the IP address.
NDResult setAddress (const char *str)
 Sets the IP address (not port) given a name.
NDResult setLocalAddress (void)
 Sets the IP address (not port) to the local address.
AddrIPV4 getAddressInt (void) const
 Gets the IP address as an integer.
const char * getAddressStr (void) const
 Gets the IP address as a character string.

Static Public Member Functions

static void * operator new (size_t s)
static void operator delete (void *p)

Detailed Description

Provides an operating system agnostic description of an IP address and port number.

Represents a network socket address, using IPv4 address and port number.

Use NDCore::createSocketAddres() to allocate.

Use "delete" to deallocate.


Member Typedef Documentation

IPv4 IP address in uint32_t format

This in in host-byte-order, as an unsigned 32-bit int, so you don't have to worry about converting to network byte order.

For example, 0x7F000001 is the localhost address 127.0.0.1

IPv4 port number

This is the port number of a socket address in host-byte-order


Constructor & Destructor Documentation

NDSocketAddress::NDSocketAddress (  ) 

Do not use the constructor, see NDCore::createSocketAddress()

NDSocketAddress::~NDSocketAddress (  ) 

This is the preferred way of deleting this object!


Member Function Documentation

void NDSocketAddress::clear ( void   ) 

Resets address to zeros

Returns:
(void)
NDSocketAddress::AddrIPV4 NDSocketAddress::getAddressInt ( void   )  const

Gets the IP address as an NDSocketAddress::AddrIPV4.

Returns:
IP address
const char * NDSocketAddress::getAddressStr ( void   )  const

Gets the IP address as a character string. This string will have the dotted-quad format "A.B.C.D" and will be represented in decimal form. For example "127.0.0.1"

This function returns a const char* internal to the object, and is subject to change. Ideally, one would use the result immediately (as in a printf call, etc), or copy it to a local buffer for further use.

Returns:
char pointer to null terminated string
NDSocketAddress::PortID NDSocketAddress::getPort ( void   )  const

Gets the port number

Returns:
The port number
NDResult NDSocketAddress::setAddress ( const char *  str  ) 

Sets the IP address (not port) given a name

The name string is an ASCII string containing either ASCII IP address, or a hostname that can be resolved.

Parameters:
str Null terminated ASCII string of hostname/IP
Returns:
NDRES_OK if successful
NDRES_NULL_POINTER if *str==NULL
NDRES_NOT_FOUND if str fails to resolve
void NDSocketAddress::setAddressInt ( AddrIPV4  ipaddr  ) 

Sets the IP address.

Parameters:
ipaddr The IP address as a 32-bit unsigned int (in native machine endianness, not as a char array)
Returns:
(void)
NDResult NDSocketAddress::setLocalAddress ( void   ) 

Sets the IP address (not port) to the local address.

This does not set the loca address to the localhost (127.0.0.1) address, rather it attempts to resolve the real local address of the host.

This routine uses the first 'real' address returned by the operating system.

For computers with multiple IP addresses (multiple interfaces, multihomed, etc), this process will depend on the order of addresses returned by the operating system, and may be non-deterministic.

Returns:
NDRES_OK if resolution appears successful
NDRES_NOT_FOUND on failure
void NDSocketAddress::setPort ( PortID  port  ) 

Sets the port number

Parameters:
port IP port number
Returns:
(void)

Generated on Wed Jul 21 18:14:48 2010 for nd2 by  doxygen 1.6.1