rllib  1
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::rlIpAdr ( )

Definition at line 21 of file rludpsocket.cpp.

22 {
23  rlwsa(); // init sockets on windows
24  memset(&address,0,sizeof(address));
25 }
struct sockaddr_in address
Definition: rludpsocket.h:47
int rlwsa()
Definition: rlsocket.cpp:68

◆ ~rlIpAdr()

rlIpAdr::~rlIpAdr ( )
virtual

Definition at line 27 of file rludpsocket.cpp.

28 {
29 }

Member Function Documentation

◆ operator==()

int rlIpAdr::operator== ( rlIpAdr address1)

Definition at line 63 of file rludpsocket.cpp.

64 {
65  if(address.sin_family != address1.address.sin_family) return 0;
66  if(memcmp(&address.sin_addr,&address1.address.sin_addr,sizeof(address.sin_addr)) == 0) return 1;
67  return 0;
68 }
struct sockaddr_in address
Definition: rludpsocket.h:47

◆ setAdr()

int rlIpAdr::setAdr ( const char *  adr,
int  port 
)

Definition at line 31 of file rludpsocket.cpp.

32 {
33  if(port < 0 || port >= 256*256) return -1;
34  struct in_addr IpAddress;
35  struct hostent *host;
36 
37  memset(&IpAddress,0,sizeof(IpAddress));
38  memset(&address,0,sizeof(address));
39 
40  host = gethostbyname(adr);
41  if(host == NULL)
42  {
43  // See if the host is specified in "dot address" form
44  IpAddress.s_addr = inet_addr(adr);
45  if(IpAddress.s_addr == INADDR_NONE)
46  {
47  ::printf("rlIpAdr::setAdr() could not gethostbyname(%s)\n",adr);
48  return -1;
49  }
50  }
51  else
52  {
53  memcpy(&IpAddress,host->h_addr,host->h_length);
54  }
55 
56  address.sin_family = AF_INET;
57  address.sin_port = htons((short) port);
58  address.sin_addr = IpAddress;
59 
60  return 0;
61 }
struct sockaddr_in address
Definition: rludpsocket.h:47

Member Data Documentation

◆ address

struct sockaddr_in rlIpAdr::address

Definition at line 47 of file rludpsocket.h.


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