diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-22 22:45:27 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-22 22:45:27 +0000 |
commit | 9adc6ced4fcab4d8a068874c55d5f563ce9e62f9 (patch) | |
tree | 586266ceaeff8f26c8f08b24b2ad0df1630097e6 | |
parent | 448f0241e06e7df2003b7f8afcf01e7406762b4e (diff) | |
download | busybox-w32-9adc6ced4fcab4d8a068874c55d5f563ce9e62f9.tar.gz busybox-w32-9adc6ced4fcab4d8a068874c55d5f563ce9e62f9.tar.bz2 busybox-w32-9adc6ced4fcab4d8a068874c55d5f563ce9e62f9.zip |
ping6: stop using xgethostbyname2, remove it from libbb.
-rw-r--r-- | include/libbb.h | 14 | ||||
-rw-r--r-- | libbb/Kbuild | 1 | ||||
-rw-r--r-- | libbb/xconnect.c | 27 | ||||
-rw-r--r-- | libbb/xgethostbyname2.c | 23 | ||||
-rw-r--r-- | networking/ping.c | 5 | ||||
-rw-r--r-- | networking/ping6.c | 44 |
6 files changed, 62 insertions, 52 deletions
diff --git a/include/libbb.h b/include/libbb.h index e41993796..1a5ce24ad 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -316,15 +316,21 @@ int xconnect_stream(const len_and_sockaddr *lsa); | |||
316 | * (depending on host), but in theory nothing prevents e.g. | 316 | * (depending on host), but in theory nothing prevents e.g. |
317 | * UNIX socket address being returned, IPX sockaddr etc... */ | 317 | * UNIX socket address being returned, IPX sockaddr etc... */ |
318 | len_and_sockaddr* host2sockaddr(const char *host, int port); | 318 | len_and_sockaddr* host2sockaddr(const char *host, int port); |
319 | #if ENABLE_FEATURE_IPV6 | ||
320 | /* Same, useful if you want to force family (e.g. IPv6) */ | ||
321 | len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af); | ||
322 | #endif | ||
319 | /* Assign sin[6]_port member if the socket is of corresponding type, | 323 | /* Assign sin[6]_port member if the socket is of corresponding type, |
320 | * otherwise no-op. Useful for ftp. | 324 | * otherwise no-op. Useful for ftp. |
321 | * NB: does NOT do htons() internally, just direct assignment. */ | 325 | * NB: does NOT do htons() internally, just direct assignment. */ |
322 | void set_nport(len_and_sockaddr *lsa, unsigned port); | 326 | void set_nport(len_and_sockaddr *lsa, unsigned port); |
323 | /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ | 327 | /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ |
324 | int get_nport(len_and_sockaddr *lsa); | 328 | int get_nport(len_and_sockaddr *lsa); |
325 | /* Reverse DNS */ | 329 | /* Reverse DNS. Returns NULL on failure. */ |
326 | char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen); | 330 | char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen); |
327 | /* This one deosn't fall back to dotted IP and do not append :PORTNUM */ | 331 | /* This one doesn't append :PORTNUM */ |
332 | char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen); | ||
333 | /* This one also doesn't fall back to dotted IP (returns NULL) */ | ||
328 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen); | 334 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen); |
329 | /* inet_[ap]ton on steroids */ | 335 | /* inet_[ap]ton on steroids */ |
330 | char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen); | 336 | char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen); |
@@ -334,8 +340,8 @@ char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen) | |||
334 | //int xconnect_tcp_v4(struct sockaddr_in *s_addr); | 340 | //int xconnect_tcp_v4(struct sockaddr_in *s_addr); |
335 | // users: traceroute.c hostname.c ifconfig.c ping.c | 341 | // users: traceroute.c hostname.c ifconfig.c ping.c |
336 | struct hostent *xgethostbyname(const char *name); | 342 | struct hostent *xgethostbyname(const char *name); |
337 | // ping6 is the only user - convert to new API | 343 | //// ping6 is the only user - convert to new API |
338 | struct hostent *xgethostbyname2(const char *name, int af); | 344 | //struct hostent *xgethostbyname2(const char *name, int af); |
339 | 345 | ||
340 | 346 | ||
341 | extern char *xstrdup(const char *s); | 347 | extern char *xstrdup(const char *s); |
diff --git a/libbb/Kbuild b/libbb/Kbuild index 1e6b5fea7..a53b17f44 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
@@ -92,7 +92,6 @@ lib-y += xconnect.o | |||
92 | lib-y += xfuncs.o | 92 | lib-y += xfuncs.o |
93 | lib-y += xgetcwd.o | 93 | lib-y += xgetcwd.o |
94 | lib-y += xgethostbyname.o | 94 | lib-y += xgethostbyname.o |
95 | lib-y += xgethostbyname2.o | ||
96 | lib-y += xreadlink.o | 95 | lib-y += xreadlink.o |
97 | 96 | ||
98 | # conditionally compiled objects: | 97 | # conditionally compiled objects: |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 188837e36..61fe7fd6c 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -114,7 +114,10 @@ void set_nport(len_and_sockaddr *lsa, unsigned port) | |||
114 | /* host: "1.2.3.4[:port]", "www.google.com[:port]" | 114 | /* host: "1.2.3.4[:port]", "www.google.com[:port]" |
115 | * port: if neither of above specifies port # | 115 | * port: if neither of above specifies port # |
116 | */ | 116 | */ |
117 | static len_and_sockaddr* str2sockaddr(const char *host, int port, int ai_flags) | 117 | static len_and_sockaddr* str2sockaddr( |
118 | const char *host, int port, | ||
119 | USE_FEATURE_IPV6(sa_family_t af,) | ||
120 | int ai_flags) | ||
118 | { | 121 | { |
119 | int rc; | 122 | int rc; |
120 | len_and_sockaddr *r; // = NULL; | 123 | len_and_sockaddr *r; // = NULL; |
@@ -147,9 +150,10 @@ static len_and_sockaddr* str2sockaddr(const char *host, int port, int ai_flags) | |||
147 | } | 150 | } |
148 | 151 | ||
149 | memset(&hint, 0 , sizeof(hint)); | 152 | memset(&hint, 0 , sizeof(hint)); |
150 | /* hint.ai_family = AF_UNSPEC; - zero anyway */ | ||
151 | #if !ENABLE_FEATURE_IPV6 | 153 | #if !ENABLE_FEATURE_IPV6 |
152 | hint.ai_family = AF_INET; /* do not try to find IPv6 */ | 154 | hint.ai_family = AF_INET; /* do not try to find IPv6 */ |
155 | #else | ||
156 | hint.ai_family = af; | ||
153 | #endif | 157 | #endif |
154 | /* Needed. Or else we will get each address thrice (or more) | 158 | /* Needed. Or else we will get each address thrice (or more) |
155 | * for each possible socket type (tcp,udp,raw...): */ | 159 | * for each possible socket type (tcp,udp,raw...): */ |
@@ -165,15 +169,25 @@ static len_and_sockaddr* str2sockaddr(const char *host, int port, int ai_flags) | |||
165 | freeaddrinfo(result); | 169 | freeaddrinfo(result); |
166 | return r; | 170 | return r; |
167 | } | 171 | } |
172 | #if !ENABLE_FEATURE_IPV6 | ||
173 | #define str2sockaddr(host, port, af, ai_flags) str2sockaddr(host, port, ai_flags) | ||
174 | #endif | ||
175 | |||
176 | #if ENABLE_FEATURE_IPV6 | ||
177 | len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af) | ||
178 | { | ||
179 | return str2sockaddr(host, port, af, 0); | ||
180 | } | ||
181 | #endif | ||
168 | 182 | ||
169 | len_and_sockaddr* host2sockaddr(const char *host, int port) | 183 | len_and_sockaddr* host2sockaddr(const char *host, int port) |
170 | { | 184 | { |
171 | return str2sockaddr(host, port, 0); | 185 | return str2sockaddr(host, port, AF_UNSPEC, 0); |
172 | } | 186 | } |
173 | 187 | ||
174 | static len_and_sockaddr* dotted2sockaddr(const char *host, int port) | 188 | static len_and_sockaddr* dotted2sockaddr(const char *host, int port) |
175 | { | 189 | { |
176 | return str2sockaddr(host, port, NI_NUMERICHOST); | 190 | return str2sockaddr(host, port, AF_UNSPEC, NI_NUMERICHOST); |
177 | } | 191 | } |
178 | 192 | ||
179 | int xsocket_stream(len_and_sockaddr **lsap) | 193 | int xsocket_stream(len_and_sockaddr **lsap) |
@@ -282,6 +296,11 @@ char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) | |||
282 | return sockaddr2str(sa, salen, 0); | 296 | return sockaddr2str(sa, salen, 0); |
283 | } | 297 | } |
284 | 298 | ||
299 | char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen) | ||
300 | { | ||
301 | return sockaddr2str(sa, salen, IGNORE_PORT); | ||
302 | } | ||
303 | |||
285 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen) | 304 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen) |
286 | { | 305 | { |
287 | return sockaddr2str(sa, salen, NI_NAMEREQD | IGNORE_PORT); | 306 | return sockaddr2str(sa, salen, NI_NAMEREQD | IGNORE_PORT); |
diff --git a/libbb/xgethostbyname2.c b/libbb/xgethostbyname2.c index 83d538669..7af2f75fb 100644 --- a/libbb/xgethostbyname2.c +++ b/libbb/xgethostbyname2.c | |||
@@ -1,22 +1 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | /* TO DELETE */ | |
2 | /* | ||
3 | * Mini xgethostbyname2 implementation. | ||
4 | * | ||
5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
6 | */ | ||
7 | |||
8 | #include <netdb.h> | ||
9 | #include "libbb.h" | ||
10 | |||
11 | |||
12 | #ifdef CONFIG_FEATURE_IPV6 | ||
13 | struct hostent *xgethostbyname2(const char *name, int af) | ||
14 | { | ||
15 | struct hostent *retval; | ||
16 | |||
17 | if ((retval = gethostbyname2(name, af)) == NULL) | ||
18 | bb_herror_msg_and_die("%s", name); | ||
19 | |||
20 | return retval; | ||
21 | } | ||
22 | #endif | ||
diff --git a/networking/ping.c b/networking/ping.c index 91708d282..fc2de456a 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -97,7 +97,7 @@ static void ping(const char *host) | |||
97 | } | 97 | } |
98 | 98 | ||
99 | signal(SIGALRM, noresp); | 99 | signal(SIGALRM, noresp); |
100 | alarm(5); /* give the host 5000ms to respond */ | 100 | alarm(5); /* give the host 5000ms to respond */ |
101 | /* listen for replies */ | 101 | /* listen for replies */ |
102 | while (1) { | 102 | while (1) { |
103 | struct sockaddr_in from; | 103 | struct sockaddr_in from; |
@@ -118,7 +118,8 @@ static void ping(const char *host) | |||
118 | break; | 118 | break; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | if (ENABLE_FEATURE_CLEAN_UP) close(pingsock); | 121 | if (ENABLE_FEATURE_CLEAN_UP) |
122 | close(pingsock); | ||
122 | printf("%s is alive!\n", hostname); | 123 | printf("%s is alive!\n", hostname); |
123 | } | 124 | } |
124 | 125 | ||
diff --git a/networking/ping6.c b/networking/ping6.c index a92387e79..ccb19b2b5 100644 --- a/networking/ping6.c +++ b/networking/ping6.c | |||
@@ -48,7 +48,7 @@ static void ping(const char *host); | |||
48 | 48 | ||
49 | /* simple version */ | 49 | /* simple version */ |
50 | 50 | ||
51 | static struct hostent *h; | 51 | //static struct hostent *h; |
52 | 52 | ||
53 | static void noresp(int ign) | 53 | static void noresp(int ign) |
54 | { | 54 | { |
@@ -58,6 +58,7 @@ static void noresp(int ign) | |||
58 | 58 | ||
59 | static void ping(const char *host) | 59 | static void ping(const char *host) |
60 | { | 60 | { |
61 | len_and_sockaddr *lsa;// | ||
61 | struct sockaddr_in6 pingaddr; | 62 | struct sockaddr_in6 pingaddr; |
62 | struct icmp6_hdr *pkt; | 63 | struct icmp6_hdr *pkt; |
63 | int pingsock, c; | 64 | int pingsock, c; |
@@ -66,11 +67,12 @@ static void ping(const char *host) | |||
66 | 67 | ||
67 | pingsock = create_icmp6_socket(); | 68 | pingsock = create_icmp6_socket(); |
68 | 69 | ||
69 | memset(&pingaddr, 0, sizeof(pingaddr)); | 70 | //memset(&pingaddr, 0, sizeof(pingaddr)); |
70 | 71 | //pingaddr.sin6_family = AF_INET6; | |
71 | pingaddr.sin6_family = AF_INET6; | 72 | //h = xgethostbyname2(host, AF_INET6); |
72 | h = xgethostbyname2(host, AF_INET6); | 73 | //memcpy(&pingaddr.sin6_addr, h->h_addr, sizeof(pingaddr.sin6_addr)); |
73 | memcpy(&pingaddr.sin6_addr, h->h_addr, sizeof(pingaddr.sin6_addr)); | 74 | lsa = host_and_af2sockaddr(host, 0, AF_INET6); |
75 | pingaddr = lsa->sin6; | ||
74 | 76 | ||
75 | pkt = (struct icmp6_hdr *) packet; | 77 | pkt = (struct icmp6_hdr *) packet; |
76 | memset(pkt, 0, sizeof(packet)); | 78 | memset(pkt, 0, sizeof(packet)); |
@@ -88,7 +90,7 @@ static void ping(const char *host) | |||
88 | } | 90 | } |
89 | 91 | ||
90 | signal(SIGALRM, noresp); | 92 | signal(SIGALRM, noresp); |
91 | alarm(5); /* give the host 5000ms to respond */ | 93 | alarm(5); /* give the host 5000ms to respond */ |
92 | /* listen for replies */ | 94 | /* listen for replies */ |
93 | while (1) { | 95 | while (1) { |
94 | struct sockaddr_in6 from; | 96 | struct sockaddr_in6 from; |
@@ -107,7 +109,8 @@ static void ping(const char *host) | |||
107 | break; | 109 | break; |
108 | } | 110 | } |
109 | } | 111 | } |
110 | if (ENABLE_FEATURE_CLEAN_UP) close(pingsock); | 112 | if (ENABLE_FEATURE_CLEAN_UP) |
113 | close(pingsock); | ||
111 | printf("%s is alive!\n", h->h_name); | 114 | printf("%s is alive!\n", h->h_name); |
112 | } | 115 | } |
113 | 116 | ||
@@ -141,7 +144,8 @@ static int myid; | |||
141 | static unsigned long tmin = ULONG_MAX, tmax, tsum; | 144 | static unsigned long tmin = ULONG_MAX, tmax, tsum; |
142 | static char rcvd_tbl[MAX_DUP_CHK / 8]; | 145 | static char rcvd_tbl[MAX_DUP_CHK / 8]; |
143 | 146 | ||
144 | static struct hostent *hostent; | 147 | //static struct hostent *hostent; |
148 | char *hostname; | ||
145 | 149 | ||
146 | static void sendping(int); | 150 | static void sendping(int); |
147 | static void pingstats(int); | 151 | static void pingstats(int); |
@@ -161,7 +165,7 @@ static void pingstats(int junk) | |||
161 | 165 | ||
162 | signal(SIGINT, SIG_IGN); | 166 | signal(SIGINT, SIG_IGN); |
163 | 167 | ||
164 | printf("\n--- %s ping statistics ---\n", hostent->h_name); | 168 | printf("\n--- %s ping statistics ---\n", hostname); |
165 | printf("%lu packets transmitted, ", ntransmitted); | 169 | printf("%lu packets transmitted, ", ntransmitted); |
166 | printf("%lu packets received, ", nreceived); | 170 | printf("%lu packets received, ", nreceived); |
167 | if (nrepeats) | 171 | if (nrepeats) |
@@ -314,6 +318,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit | |||
314 | extern int BUG_bad_offsetof_icmp6_cksum(void); | 318 | extern int BUG_bad_offsetof_icmp6_cksum(void); |
315 | static void ping(const char *host) | 319 | static void ping(const char *host) |
316 | { | 320 | { |
321 | len_and_sockaddr *lsa;// | ||
317 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; | 322 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
318 | char buf[INET6_ADDRSTRLEN]; | 323 | char buf[INET6_ADDRSTRLEN]; |
319 | int sockopt; | 324 | int sockopt; |
@@ -324,14 +329,15 @@ static void ping(const char *host) | |||
324 | 329 | ||
325 | pingsock = create_icmp6_socket(); | 330 | pingsock = create_icmp6_socket(); |
326 | 331 | ||
327 | memset(&pingaddr, 0, sizeof(pingaddr)); | 332 | //memset(&pingaddr, 0, sizeof(pingaddr)); |
328 | 333 | //pingaddr.sin6_family = AF_INET6; | |
329 | pingaddr.sin6_family = AF_INET6; | 334 | //hostent = xgethostbyname2(host, AF_INET6); |
330 | hostent = xgethostbyname2(host, AF_INET6); | 335 | //if (hostent->h_addrtype != AF_INET6) |
331 | if (hostent->h_addrtype != AF_INET6) | 336 | // bb_error_msg_and_die("unknown address type; only AF_INET6 is currently supported"); |
332 | bb_error_msg_and_die("unknown address type; only AF_INET6 is currently supported"); | 337 | //memcpy(&pingaddr.sin6_addr, hostent->h_addr, sizeof(pingaddr.sin6_addr)); |
333 | 338 | lsa = host_and_af2sockaddr(host, 0, AF_INET6); | |
334 | memcpy(&pingaddr.sin6_addr, hostent->h_addr, sizeof(pingaddr.sin6_addr)); | 339 | hostname = xmalloc_sockaddr2host_noport(&lsa->sa, lsa->len); |
340 | pingaddr = lsa->sin6; | ||
335 | 341 | ||
336 | #ifdef ICMP6_FILTER | 342 | #ifdef ICMP6_FILTER |
337 | { | 343 | { |
@@ -367,7 +373,7 @@ static void ping(const char *host) | |||
367 | pingaddr.sin6_scope_id = if_index; | 373 | pingaddr.sin6_scope_id = if_index; |
368 | 374 | ||
369 | printf("PING %s (%s): %d data bytes\n", | 375 | printf("PING %s (%s): %d data bytes\n", |
370 | hostent->h_name, | 376 | hostname, |
371 | inet_ntop(AF_INET6, &pingaddr.sin6_addr, | 377 | inet_ntop(AF_INET6, &pingaddr.sin6_addr, |
372 | buf, sizeof(buf)), | 378 | buf, sizeof(buf)), |
373 | datalen); | 379 | datalen); |