1 #ifndef _NET_ADDRESS_H_
2 #define _NET_ADDRESS_H_
6 #include <sys/socket.h>
7 #include <netinet/in.h>
41 virtual sockaddr *GetSockAddr()
const = 0;
47 virtual int GetSize()
const = 0;
75 memset(&sock_addr, 0,
sizeof(sock_addr));
77 sock_addr.sin_family = AF_INET;
85 memcpy(&sock_addr, &(address.
sock_addr),
sizeof(sock_addr));
95 memset(&sock_addr, 0,
sizeof(sock_addr));
97 sock_addr.sin_family = AF_INET;
98 sock_addr.sin_addr.s_addr = INADDR_ANY;
99 sock_addr.sin_port = htons((u_short)port);
109 memset(&sock_addr, 0,
sizeof(sock_addr));
114 if(inet_addr(path) == INADDR_NONE)
115 hp = gethostbyname(path);
117 addr = inet_addr(path);
118 hp = gethostbyaddr((
char *)&addr,
sizeof(addr), AF_INET);
122 sock_addr.sin_family = AF_INET;
123 sock_addr.sin_port = htons(port);
124 sock_addr.sin_addr.s_addr = *((
unsigned long *)hp->h_addr);
133 memcpy(&sock_addr, &(address.
sock_addr),
sizeof(sock_addr));
143 return (sockaddr *)&sock_addr;
152 return sizeof(sock_addr);
160 return inet_ntoa(sock_addr.sin_addr);
168 return ntohs(sock_addr.sin_port);
190 memset(&sock_addr, 0,
sizeof(sock_addr));
192 sock_addr.sun_family = AF_UNIX;
200 memcpy(&sock_addr, &(address.
sock_addr),
sizeof(sock_addr));
209 memset(&sock_addr, 0,
sizeof(sock_addr));
211 sock_addr.sun_family = AF_UNIX;
212 strncpy(sock_addr.sun_path, path,
sizeof(sock_addr.sun_path) - 1);
220 memcpy(&sock_addr, &(address.
sock_addr),
sizeof(sock_addr));
229 unlink(sock_addr.sun_path);
239 return (sockaddr *)&sock_addr;
248 return sizeof(sock_addr);
256 return sock_addr.sun_path;
virtual sockaddr * GetSockAddr() const
Overloaded from the base class to use the internal address structure.
Definition: address.h:141
UnixAddress & operator=(const UnixAddress &address)
Copy assignment.
Definition: address.h:218
string GetPath() const
Returns the address path.
Definition: address.h:254
virtual ~Address()
Empty destructor.
Definition: address.h:52
UnixAddress & Reset()
Removes the file associated to the UNIX address.
Definition: address.h:227
int GetPort() const
Returns the port number.
Definition: address.h:166
sockaddr_un sock_addr
Internal address structure.
Definition: address.h:182
UnixAddress(const char *path)
Initializes the address with given path.
Definition: address.h:207
sockaddr_in sock_addr
Internal address structure.
Definition: address.h:67
InetAddress(const char *path, int port)
Initializes the address with the given path and port.
Definition: address.h:107
Contains classes to easy the utilization of sockets, specially implemented for UNIX systems...
Definition: address.h:15
UnixAddress(const UnixAddress &address)
Copy constructor.
Definition: address.h:198
virtual int GetSize() const
Overloaded from the base class to use the internal address structure.
Definition: address.h:246
InetAddress(const InetAddress &address)
Copy constructor.
Definition: address.h:83
InetAddress & operator=(const InetAddress &address)
Copy assignment.
Definition: address.h:131
virtual sockaddr * GetSockAddr() const
Overloaded from the base class to use the internal address structure.
Definition: address.h:237
Class to identify and handle an UNIX address.
Definition: address.h:179
string GetPath() const
Returns the address path.
Definition: address.h:158
Abstract base class to wrap the sockaddr derived structures.
Definition: address.h:28
UnixAddress()
Initializes the address to zero.
Definition: address.h:188
virtual int GetSize() const
Overloaded from the base class to use the internal address structure.
Definition: address.h:150
Address()
Empty constructor.
Definition: address.h:34
Class to identify and handle an Internet address.
Definition: address.h:64
InetAddress(int port)
Initializes the address with given port.
Definition: address.h:93
InetAddress()
Initializes the address to zero.
Definition: address.h:73