--- gvpe/src/sockinfo.C 2011/03/24 21:52:49 1.25 +++ gvpe/src/sockinfo.C 2012/12/04 13:51:45 1.30 @@ -31,8 +31,14 @@ #include "config.h" +// for gethostbyname #include +// for inet_aton +#include +#include +#include + #include "gettext.h" #include "sockinfo.h" @@ -62,14 +68,16 @@ if (prot & PROTv4 && hostname) { - struct hostent *he = gethostbyname (hostname); + struct in_addr in; + struct hostent *he; - if (he - && he->h_addrtype == AF_INET && he->h_length == 4 && he->h_addr_list[0]) - { - //sa->sin_family = he->h_addrtype; - memcpy (&host, he->h_addr_list[0], 4); - } + if (inet_aton (hostname, &in)) + host = in.s_addr; + else if ((he = gethostbyname (hostname)) + && he->h_addrtype == AF_INET + && he->h_length == 4 + && he->h_addr_list[0]) + memcpy (&host, he->h_addr_list[0], 4); //sa->sin_family = he->h_addrtype; else slog (L_NOTICE, _("unable to resolve host '%s'"), hostname); } @@ -115,6 +123,12 @@ return hostport; } +bool +sockinfo::valid () const +{ + return (prot & THISNODE->protocols) && host; +} + sockinfo::operator const char *() const { in_addr ia = { host };