class NetworkAddress

Class which implements a network address

Public Fields

static const int getHostLookupFailed
value if host lookup failed
static const int getHostLookupOK
value if host lookup succeeded

Public Methods

static int getHostByName(const char* hostName, struct hostent* hEnt, char* buf, int buflen, int* thrErrno)
Mutexes the gethostbyname(), return 0 when successful
string getHostName()
get hostname in the form "lab1.vovida.com"
u_int32_t getIp4Address()
return the IP4 address packed as an unsigned int, in network byte order
string getIpName()
get IP address as a string in the form "192.168.4.5"
int getPort()
get the port
void getSockAddr(struct sockaddr & socka)
return the address in a sockaddr
static u_int32_t hashIpPort( const u_int32_t ipAddress, const int port )
hash function, uses last 2 bytes of ip address + 2 bytes of port
u_int32_t hashIpPort( )
hash function, uses last 2 bytes of ip address + 2 bytes of port the bits 15-0 of ipaddress (Bigendian) becomes the Most Significant Byte(MSB) of hashkey, bits 15-0 of port becomes LSB of hashkey
static u_int32_t hashIpPort( const string& theAddress, const string& port )
hash function, uses last 2 bytes of ip address + 2 bytes of port
NetworkAddress( int port = -1 )
default constructor. The host is initially set to localhost.
NetworkAddress( string hostName, int port = -1 )
The host hostName can be in the same form as passed to setHostName()
friend bool operator != (const NetworkAddress & xAddress, const NetworkAddress & yAddress )
compare two IP addresses
friend bool operator < (const NetworkAddress & xAddress, const NetworkAddress & yAddress )
compare two IP addresses
friend bool operator == (const NetworkAddress & xAddress, const NetworkAddress & yAddress )
compare two IP addresses
operator string()
convert to string - returns same as getHostName
friend ostream& operator<< ( ostream & xStream, const NetworkAddress& rxObj )
printing operator -- calls print() fn.
NetworkAddress& operator=( const NetworkAddress& x )
assignment operator =
ostream& print( ostream & xStr )
printing operator. This should be replaced w/ Vocal::IO:Writer
void setHostName( const string& theAddress )
takes IP or DNS with optional ":port" syntax
void setPort( int port )
set port

Private Methods

bool is_valid_ip_addr(const string& ip_addr)
Check if parameter is a valid IP address

Documentation

Class which implements a network address. includes functionality to look up network addresses from hostnames or ip addresses as strings.
NetworkAddress( int port = -1 )
default constructor. The host is initially set to localhost.

NetworkAddress( string hostName, int port = -1 )
The host hostName can be in the same form as passed to setHostName()

void setHostName( const string& theAddress )
takes IP or DNS with optional ":port" syntax. Examples:

lab1.vovida.com
192.168.4.5
lab1.vovoda.com:80
192.168.4.5:6000

void setPort( int port )
set port

string getHostName()
get hostname in the form "lab1.vovida.com"

string getIpName()
get IP address as a string in the form "192.168.4.5"

u_int32_t getIp4Address()
return the IP4 address packed as an unsigned int, in network byte order

void getSockAddr(struct sockaddr & socka)
return the address in a sockaddr. This value is assigned
Parameters:
socka - returned address

int getPort()
get the port

friend bool operator < (const NetworkAddress & xAddress, const NetworkAddress & yAddress )
compare two IP addresses

friend bool operator == (const NetworkAddress & xAddress, const NetworkAddress & yAddress )
compare two IP addresses

friend bool operator != (const NetworkAddress & xAddress, const NetworkAddress & yAddress )
compare two IP addresses

operator string()
convert to string - returns same as getHostName

friend ostream& operator<< ( ostream & xStream, const NetworkAddress& rxObj )
printing operator -- calls print() fn.

NetworkAddress& operator=( const NetworkAddress& x )
assignment operator =

ostream& print( ostream & xStr )
printing operator. This should be replaced w/ Vocal::IO:Writer

u_int32_t hashIpPort( )
hash function, uses last 2 bytes of ip address + 2 bytes of port the bits 15-0 of ipaddress (Bigendian) becomes the Most Significant Byte(MSB) of hashkey, bits 15-0 of port becomes LSB of hashkey

static u_int32_t hashIpPort( const string& theAddress, const string& port )
hash function, uses last 2 bytes of ip address + 2 bytes of port

static u_int32_t hashIpPort( const u_int32_t ipAddress, const int port )
hash function, uses last 2 bytes of ip address + 2 bytes of port

static int getHostByName(const char* hostName, struct hostent* hEnt, char* buf, int buflen, int* thrErrno)
Mutexes the gethostbyname(), return 0 when successful

static const int getHostLookupFailed
value if host lookup failed

static const int getHostLookupOK
value if host lookup succeeded

bool is_valid_ip_addr(const string& ip_addr)
Check if parameter is a valid IP address


This class has no child classes.

alphabetic index hierarchy of classes


generated by doc++