Provides an operating system agnostic description of an IP address and port number. More...
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) |
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.
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
| NDSocketAddress::NDSocketAddress | ( | ) |
Do not use the constructor, see NDCore::createSocketAddress()
| NDSocketAddress::~NDSocketAddress | ( | ) |
This is the preferred way of deleting this object!
| void NDSocketAddress::clear | ( | void | ) |
Resets address to zeros
| NDSocketAddress::AddrIPV4 NDSocketAddress::getAddressInt | ( | void | ) | const |
Gets the IP address as an NDSocketAddress::AddrIPV4.
| 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.
| NDSocketAddress::PortID NDSocketAddress::getPort | ( | void | ) | const |
Gets 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.
| str | Null terminated ASCII string of hostname/IP |
| void NDSocketAddress::setAddressInt | ( | AddrIPV4 | ipaddr | ) |
Sets the IP address.
| ipaddr | The IP address as a 32-bit unsigned int (in native machine endianness, not as a char array) |
| 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.
| void NDSocketAddress::setPort | ( | PortID | port | ) |
Sets the port number
| port | IP port number |
1.6.1