17 # include <winsock2.h>
21 # include <sys/socket.h>
23 # include <sys/utsname.h>
77 ::memcpy ((
void*) &
m_address, (
const void*) address_,
sizeof(
SA_IN));
86 ::memcpy ((
void*) &
m_address, (
const void*) address_,
sizeof(
SA_IN));
113 const u_int HOSTNAMELEN = 64;
114 char buf[HOSTNAMELEN];
115 if (gethostname (buf, HOSTNAMELEN) == 0) {
120 if ( (r = s.find(
':')) > 0 ) {
121 host = s.substr(0, r);
122 sPort = s.substr(r+1);
124 else if ( (r = s.find(
'@')) > 0 ) {
125 sPort = s.substr(0, r);
126 host = s.substr(r+1);
143 struct servent* sp = NULL;
145 if ((l = strtol (s_.c_str(), (
char**) NULL, 10))) {
146 return htons ((
unsigned short int) l);
149 if ((sp = getservbyname (s_.c_str(), (p_==
TCP ?
"tcp" :
"udp")))) {
163 struct hostent* hp = 0;
165 if (strlen (host_) == 0) {
166 m_address.sin_addr.s_addr = htonl(INADDR_ANY);
170 if ((hp = gethostbyname (host_)) == NULL) {
173 EL((
ASSAERR,
"gethostbyname (\"%s\") failed\n", host_));
176 memcpy ((
char*) &
m_address.sin_addr, hp->h_addr_list[0], hp->h_length);
187 if (
m_address.sin_addr.s_addr == htonl(INADDR_ANY)) {
191 struct hostent* hentry;
192 hentry = gethostbyaddr ((
const char*) &
m_address.sin_addr,
195 if (hentry == NULL) {
198 EL((
ASSAERR,
"gethostbyaddr() failed\n"));
201 return hentry->h_name;
212 "AF_INET" :
"AF_UNIX"));
239 struct utsname myname;
240 struct hostent* hptr = NULL;
244 slen =
sizeof (myname.nodename) - 1;
245 GetComputerNameA (myname.nodename, &slen);
247 if (::uname (&myname) < 0) {
253 if ((hptr = ::gethostbyname (myname.nodename)) == NULL) {
255 EL((
ADDRESS,
"gethostbyname (%s) failed\n", myname.nodename));
259 char** pptr = hptr->h_aliases;
260 while (*pptr != NULL) {
261 aliases_.push_back (*pptr);
An incapsulation of TCP/UDP Internet Protocol socket address structure.
#define EL(X)
A macro for writing error message to the Logger.
#define DL(X)
A macro for writing debug message to the Logger.
virtual void dump()
Dump object state to the log file.
void setstate(addrstate flag_)
Set state of the Address object.
void init()
Perform initialization common to all ctors.
string getHostName()
Return host name.
void dump()
Dump the address content to log file.
static string get_fully_qualified_domain_name(vector< string > &aliases_)
Return fully-qualified host name.
INETAddress()
Default constructor.
int getServiceByName(string serv_, Protocol prot_=TCP)
Lookup port by its service name found in /etc/services.
int getPort() const
Return port.
void createHostPort(const char *host_, int port_)
Makes socket address out of host name and port.
SA_IN m_address
Internet address structure sockaddr_in.
static string m_fqdn_cache
Cached fully-qualified domain name.
@ ADDRESS
Class Address & friends messages
@ ASSAERR
ASSA and system errors