… | |
… | |
29 | covered work. |
29 | covered work. |
30 | */ |
30 | */ |
31 | |
31 | |
32 | #include "config.h" |
32 | #include "config.h" |
33 | |
33 | |
|
|
34 | // for gethostbyname |
34 | #include <netdb.h> |
35 | #include <netdb.h> |
|
|
36 | |
|
|
37 | // for inet_aton |
|
|
38 | #include <sys/socket.h> |
|
|
39 | #include <netinet/in.h> |
|
|
40 | #include <arpa/inet.h> |
35 | |
41 | |
36 | #include "gettext.h" |
42 | #include "gettext.h" |
37 | |
43 | |
38 | #include "sockinfo.h" |
44 | #include "sockinfo.h" |
39 | #include "slog.h" |
45 | #include "slog.h" |
… | |
… | |
60 | port = htons (port_); |
66 | port = htons (port_); |
61 | |
67 | |
62 | if (prot & PROTv4 |
68 | if (prot & PROTv4 |
63 | && hostname) |
69 | && hostname) |
64 | { |
70 | { |
|
|
71 | struct in_addr in; |
|
|
72 | struct hostent *he; |
|
|
73 | |
|
|
74 | if (inet_aton (hostname, &in)) |
|
|
75 | { |
|
|
76 | host = in.s_addr; |
|
|
77 | } |
65 | struct hostent *he = gethostbyname (hostname); |
78 | else if ((he = gethostbyname (hostname)) |
66 | |
79 | && he->h_addrtype == AF_INET |
67 | if (he |
80 | && he->h_length == 4 |
68 | && he->h_addrtype == AF_INET && he->h_length == 4 && he->h_addr_list[0]) |
81 | && he->h_addr_list[0]) |
69 | { |
82 | { |
70 | //sa->sin_family = he->h_addrtype; |
83 | //sa->sin_family = he->h_addrtype; |
71 | memcpy (&host, he->h_addr_list[0], 4); |
84 | memcpy (&host, he->h_addr_list[0], 4); |
72 | } |
85 | } |
73 | else |
86 | else |
… | |
… | |
113 | sprintf (hostport, "%.15s", inet_ntoa (ia)); |
126 | sprintf (hostport, "%.15s", inet_ntoa (ia)); |
114 | |
127 | |
115 | return hostport; |
128 | return hostport; |
116 | } |
129 | } |
117 | |
130 | |
|
|
131 | bool |
|
|
132 | sockinfo::valid () const |
|
|
133 | { |
|
|
134 | return (prot & THISNODE->protocols) && host; |
|
|
135 | } |
|
|
136 | |
118 | sockinfo::operator const char *() const |
137 | sockinfo::operator const char *() const |
119 | { |
138 | { |
120 | in_addr ia = { host }; |
139 | in_addr ia = { host }; |
121 | |
140 | |
122 | sprintf (hostport, "%s/%.15s:%d", strprotocol (prot), inet_ntoa (ia), ntohs (port) & 0xffff); |
141 | sprintf (hostport, "%s/%.15s:%d", strprotocol (prot), inet_ntoa (ia), ntohs (port) & 0xffff); |