Google

C++ Portable Types Library (PTypes) Version 1.7


Top: Networking: Utilities

#include <pinet.h>

string     iptostring(ipaddress ip);
ipaddress  phostbyname(const string& name);
string     phostbyaddr(ipaddress ip);
string     phostcname(const string& name);

Many PTypes networking utility functions and class methods manipulate a new data type ipaddress - IPv4 (4-byte) internetwork address type. The objects of this type can be constructed either by explicitly specifying the 4 bytes separately (e.g. ipaddress(192, 168, 1, 1)) or by assigning another ipaddress. The objects of this type are mutually compatible with unsigned long type, however, you can not rely on the order of bytes if an ipaddress is converted to a unsigned long and vice versa. This implicit typecast is provided only for comparing an ipaddress value with 0 or ipnone (see Examples).

string iptostring(ipaddress ip) converts an IP address to a string, e.g. ipaddress(127.0.0.1) would be "127.0.0.1".

ipaddress phostbyname(const string& name) resolves a symbolic DNS name or a numeric IP addresses to ipaddress. On error this function returns ipnone.

string phostbyaddr(ipaddress ip) performs reverse DNS lookup for the given IP address. On error this function returns an empty string.

string phostcname(const string& name) returns the canonical name of the host. On error this function returns an empty string.

See also: ipstream, ipstmserver, Examples


PTypes home