rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Public Attributes | List of all members
rlIpAdr Class Reference

#include <rludpsocket.h>

Public Member Functions

 rlIpAdr ()
 
virtual ~rlIpAdr ()
 
int setAdr (const char *adr, int port)
 
int operator== (rlIpAdr &address1)
 

Public Attributes

struct sockaddr_in address
 

Detailed Description

class for encapsulating ip  addresses

Definition at line 40 of file rludpsocket.h.

Constructor & Destructor Documentation

rlIpAdr::rlIpAdr ( )

Definition at line 21 of file rludpsocket.cpp.

{
rlwsa(); // init sockets on windows
memset(&address,0,sizeof(address));
}
rlIpAdr::~rlIpAdr ( )
virtual

Definition at line 27 of file rludpsocket.cpp.

{
}

Member Function Documentation

int rlIpAdr::operator== ( rlIpAdr address1)

Definition at line 63 of file rludpsocket.cpp.

{
if(address.sin_family != address1.address.sin_family) return 0;
if(memcmp(&address.sin_addr,&address1.address.sin_addr,sizeof(address.sin_addr)) == 0) return 1;
return 0;
}
int rlIpAdr::setAdr ( const char *  adr,
int  port 
)

Definition at line 31 of file rludpsocket.cpp.

{
if(port < 0 || port >= 256*256) return -1;
struct in_addr IpAddress;
struct hostent *host;
memset(&IpAddress,0,sizeof(IpAddress));
memset(&address,0,sizeof(address));
host = gethostbyname(adr);
if(host == NULL)
{
// See if the host is specified in "dot address" form
IpAddress.s_addr = inet_addr(adr);
if(IpAddress.s_addr == INADDR_NONE)
{
::printf("rlIpAdr::setAdr() could not gethostbyname(%s)\n",adr);
return -1;
}
}
else
{
memcpy(&IpAddress,host->h_addr,host->h_length);
}
address.sin_family = AF_INET;
address.sin_port = htons((short) port);
address.sin_addr = IpAddress;
return 0;
}

Member Data Documentation

struct sockaddr_in rlIpAdr::address

Definition at line 47 of file rludpsocket.h.


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