diff options
-rw-r--r-- | include/libbb.h | 14 | ||||
-rw-r--r-- | ipsvd/tcpudp.c | 14 | ||||
-rw-r--r-- | libbb/xconnect.c | 38 | ||||
-rw-r--r-- | libbb/xfuncs.c | 9 | ||||
-rw-r--r-- | loginutils/getty.c | 12 | ||||
-rw-r--r-- | networking/dnsd.c | 2 | ||||
-rw-r--r-- | networking/ftpgetput.c | 2 | ||||
-rw-r--r-- | networking/inetd.c | 3 | ||||
-rw-r--r-- | networking/nc_bloaty.c | 12 | ||||
-rw-r--r-- | networking/netstat.c | 4 | ||||
-rw-r--r-- | networking/nslookup.c | 7 | ||||
-rw-r--r-- | networking/ping.c | 4 | ||||
-rw-r--r-- | networking/tftp.c | 2 | ||||
-rw-r--r-- | networking/traceroute.c | 2 | ||||
-rw-r--r-- | networking/udhcp/common.h | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcprelay.c | 9 | ||||
-rw-r--r-- | networking/udhcp/packet.c | 7 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 42 | ||||
-rw-r--r-- | networking/wget.c | 2 | ||||
-rw-r--r-- | runit/runsv.c | 9 | ||||
-rw-r--r-- | util-linux/mount.c | 2 |
23 files changed, 95 insertions, 107 deletions
diff --git a/include/libbb.h b/include/libbb.h index 52bc33940..651c48ba1 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -241,6 +241,7 @@ extern char *bb_get_last_path_component(char *path); | |||
241 | 241 | ||
242 | int ndelay_on(int fd); | 242 | int ndelay_on(int fd); |
243 | int ndelay_off(int fd); | 243 | int ndelay_off(int fd); |
244 | void xdup2(int, int); | ||
244 | void xmove_fd(int, int); | 245 | void xmove_fd(int, int); |
245 | 246 | ||
246 | 247 | ||
@@ -288,8 +289,7 @@ ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to, | |||
288 | * time out. Linux does not allow multiple live binds on same ip:port | 289 | * time out. Linux does not allow multiple live binds on same ip:port |
289 | * regardless of SO_REUSEADDR (unlike some other flavors of Unix). | 290 | * regardless of SO_REUSEADDR (unlike some other flavors of Unix). |
290 | * Turn it on before you call bind(). */ | 291 | * Turn it on before you call bind(). */ |
291 | //TODO: it seems like in Linux this never fails. Change to void, eliminate error checks | 292 | void setsockopt_reuseaddr(int fd); /* On Linux this never fails. */ |
292 | int setsockopt_reuseaddr(int fd); | ||
293 | int setsockopt_broadcast(int fd); | 293 | int setsockopt_broadcast(int fd); |
294 | /* NB: returns port in host byte order */ | 294 | /* NB: returns port in host byte order */ |
295 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port); | 295 | unsigned bb_lookup_port(const char *port, const char *protocol, unsigned default_port); |
@@ -360,14 +360,14 @@ void set_nport(len_and_sockaddr *lsa, unsigned port); | |||
360 | /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ | 360 | /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ |
361 | int get_nport(const struct sockaddr *sa); | 361 | int get_nport(const struct sockaddr *sa); |
362 | /* Reverse DNS. Returns NULL on failure. */ | 362 | /* Reverse DNS. Returns NULL on failure. */ |
363 | char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen); | 363 | char* xmalloc_sockaddr2host(const struct sockaddr *sa); |
364 | /* This one doesn't append :PORTNUM */ | 364 | /* This one doesn't append :PORTNUM */ |
365 | char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen); | 365 | char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa); |
366 | /* This one also doesn't fall back to dotted IP (returns NULL) */ | 366 | /* This one also doesn't fall back to dotted IP (returns NULL) */ |
367 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen); | 367 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa); |
368 | /* inet_[ap]ton on steroids */ | 368 | /* inet_[ap]ton on steroids */ |
369 | char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen); | 369 | char* xmalloc_sockaddr2dotted(const struct sockaddr *sa); |
370 | char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen); | 370 | char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa); |
371 | // "old" (ipv4 only) API | 371 | // "old" (ipv4 only) API |
372 | // users: traceroute.c hostname.c - use _list_ of all IPs | 372 | // users: traceroute.c hostname.c - use _list_ of all IPs |
373 | struct hostent *xgethostbyname(const char *name); | 373 | struct hostent *xgethostbyname(const char *name); |
diff --git a/ipsvd/tcpudp.c b/ipsvd/tcpudp.c index 492808a6b..e46b3c60e 100644 --- a/ipsvd/tcpudp.c +++ b/ipsvd/tcpudp.c | |||
@@ -258,7 +258,7 @@ int tcpudpsvd_main(int argc, char **argv) | |||
258 | #endif | 258 | #endif |
259 | 259 | ||
260 | if (verbose) { | 260 | if (verbose) { |
261 | char *addr = xmalloc_sockaddr2dotted(&lsa->sa, sa_len); | 261 | char *addr = xmalloc_sockaddr2dotted(&lsa->sa); |
262 | printf("%s: info: listening on %s", applet_name, addr); | 262 | printf("%s: info: listening on %s", applet_name, addr); |
263 | free(addr); | 263 | free(addr); |
264 | #ifndef SSLSVD | 264 | #ifndef SSLSVD |
@@ -302,7 +302,7 @@ int tcpudpsvd_main(int argc, char **argv) | |||
302 | if (max_per_host) { | 302 | if (max_per_host) { |
303 | /* Drop connection immediately if cur_per_host > max_per_host | 303 | /* Drop connection immediately if cur_per_host > max_per_host |
304 | * (minimizing load under SYN flood) */ | 304 | * (minimizing load under SYN flood) */ |
305 | remote_ip = xmalloc_sockaddr2dotted_noport(&remote.sa, sa_len); | 305 | remote_ip = xmalloc_sockaddr2dotted_noport(&remote.sa); |
306 | cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp); | 306 | cur_per_host = ipsvd_perhost_add(remote_ip, max_per_host, &hccp); |
307 | if (cur_per_host > max_per_host) { | 307 | if (cur_per_host > max_per_host) { |
308 | /* ipsvd_perhost_add detected that max is exceeded | 308 | /* ipsvd_perhost_add detected that max is exceeded |
@@ -380,11 +380,11 @@ int tcpudpsvd_main(int argc, char **argv) | |||
380 | close(sock); | 380 | close(sock); |
381 | 381 | ||
382 | if (need_remote_ip) | 382 | if (need_remote_ip) |
383 | remote_addr = xmalloc_sockaddr2dotted(&remote.sa, sa_len); | 383 | remote_addr = xmalloc_sockaddr2dotted(&remote.sa); |
384 | 384 | ||
385 | if (need_hostnames) { | 385 | if (need_hostnames) { |
386 | if (option_mask32 & OPT_h) { | 386 | if (option_mask32 & OPT_h) { |
387 | remote_hostname = xmalloc_sockaddr2host_noport(&remote.sa, sa_len); | 387 | remote_hostname = xmalloc_sockaddr2host_noport(&remote.sa); |
388 | if (!remote_hostname) { | 388 | if (!remote_hostname) { |
389 | bb_error_msg("warning: cannot look up hostname for %s", remote_addr); | 389 | bb_error_msg("warning: cannot look up hostname for %s", remote_addr); |
390 | remote_hostname = (char*)""; | 390 | remote_hostname = (char*)""; |
@@ -397,9 +397,9 @@ int tcpudpsvd_main(int argc, char **argv) | |||
397 | local.len = sa_len; | 397 | local.len = sa_len; |
398 | getsockname(0, &local.sa, &local.len); | 398 | getsockname(0, &local.sa, &local.len); |
399 | } | 399 | } |
400 | local_addr = xmalloc_sockaddr2dotted(&local.sa, sa_len); | 400 | local_addr = xmalloc_sockaddr2dotted(&local.sa); |
401 | if (!local_hostname) { | 401 | if (!local_hostname) { |
402 | local_hostname = xmalloc_sockaddr2host_noport(&local.sa, sa_len); | 402 | local_hostname = xmalloc_sockaddr2host_noport(&local.sa); |
403 | if (!local_hostname) | 403 | if (!local_hostname) |
404 | bb_error_msg_and_die("warning: cannot look up hostname for %s"+9, local_addr); | 404 | bb_error_msg_and_die("warning: cannot look up hostname for %s"+9, local_addr); |
405 | } | 405 | } |
@@ -426,7 +426,7 @@ int tcpudpsvd_main(int argc, char **argv) | |||
426 | * an outbond connection to local handler, and it needs | 426 | * an outbond connection to local handler, and it needs |
427 | * to know where it originally tried to connect */ | 427 | * to know where it originally tried to connect */ |
428 | if (tcp && getsockopt(0, SOL_IP, SO_ORIGINAL_DST, &lsa->sa, &lsa->len) == 0) { | 428 | if (tcp && getsockopt(0, SOL_IP, SO_ORIGINAL_DST, &lsa->sa, &lsa->len) == 0) { |
429 | char *addr = xmalloc_sockaddr2dotted(&lsa->sa, sa_len); | 429 | char *addr = xmalloc_sockaddr2dotted(&lsa->sa); |
430 | xsetenv("TCPORIGDSTADDR", addr); | 430 | xsetenv("TCPORIGDSTADDR", addr); |
431 | free(addr); | 431 | free(addr); |
432 | } | 432 | } |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index b90aa9add..cb5ac2c8e 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -9,9 +9,9 @@ | |||
9 | #include <netinet/in.h> | 9 | #include <netinet/in.h> |
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | int setsockopt_reuseaddr(int fd) | 12 | void setsockopt_reuseaddr(int fd) |
13 | { | 13 | { |
14 | return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1)); | 14 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1)); |
15 | } | 15 | } |
16 | int setsockopt_broadcast(int fd) | 16 | int setsockopt_broadcast(int fd) |
17 | { | 17 | { |
@@ -298,11 +298,21 @@ int xconnect_stream(const len_and_sockaddr *lsa) | |||
298 | /* We hijack this constant to mean something else */ | 298 | /* We hijack this constant to mean something else */ |
299 | /* It doesn't hurt because we will add this bit anyway */ | 299 | /* It doesn't hurt because we will add this bit anyway */ |
300 | #define IGNORE_PORT NI_NUMERICSERV | 300 | #define IGNORE_PORT NI_NUMERICSERV |
301 | static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) | 301 | static char* sockaddr2str(const struct sockaddr *sa, int flags) |
302 | { | 302 | { |
303 | char host[128]; | 303 | char host[128]; |
304 | char serv[16]; | 304 | char serv[16]; |
305 | int rc = getnameinfo(sa, salen, | 305 | int rc; |
306 | socklen_t salen; | ||
307 | |||
308 | salen = LSA_SIZEOF_SA; | ||
309 | #if ENABLE_FEATURE_IPV6 | ||
310 | if (sa->sa_family == AF_INET) | ||
311 | salen = sizeof(struct sockaddr_in); | ||
312 | if (sa->sa_family == AF_INET6) | ||
313 | salen = sizeof(struct sockaddr_in6); | ||
314 | #endif | ||
315 | rc = getnameinfo(sa, salen, | ||
306 | host, sizeof(host), | 316 | host, sizeof(host), |
307 | /* can do ((flags & IGNORE_PORT) ? NULL : serv) but why bother? */ | 317 | /* can do ((flags & IGNORE_PORT) ? NULL : serv) but why bother? */ |
308 | serv, sizeof(serv), | 318 | serv, sizeof(serv), |
@@ -327,26 +337,26 @@ static char* sockaddr2str(const struct sockaddr *sa, socklen_t salen, int flags) | |||
327 | /*return xstrdup(host);*/ | 337 | /*return xstrdup(host);*/ |
328 | } | 338 | } |
329 | 339 | ||
330 | char* xmalloc_sockaddr2host(const struct sockaddr *sa, socklen_t salen) | 340 | char* xmalloc_sockaddr2host(const struct sockaddr *sa) |
331 | { | 341 | { |
332 | return sockaddr2str(sa, salen, 0); | 342 | return sockaddr2str(sa, 0); |
333 | } | 343 | } |
334 | 344 | ||
335 | char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa, socklen_t salen) | 345 | char* xmalloc_sockaddr2host_noport(const struct sockaddr *sa) |
336 | { | 346 | { |
337 | return sockaddr2str(sa, salen, IGNORE_PORT); | 347 | return sockaddr2str(sa, IGNORE_PORT); |
338 | } | 348 | } |
339 | 349 | ||
340 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa, socklen_t salen) | 350 | char* xmalloc_sockaddr2hostonly_noport(const struct sockaddr *sa) |
341 | { | 351 | { |
342 | return sockaddr2str(sa, salen, NI_NAMEREQD | IGNORE_PORT); | 352 | return sockaddr2str(sa, NI_NAMEREQD | IGNORE_PORT); |
343 | } | 353 | } |
344 | char* xmalloc_sockaddr2dotted(const struct sockaddr *sa, socklen_t salen) | 354 | char* xmalloc_sockaddr2dotted(const struct sockaddr *sa) |
345 | { | 355 | { |
346 | return sockaddr2str(sa, salen, NI_NUMERICHOST); | 356 | return sockaddr2str(sa, NI_NUMERICHOST); |
347 | } | 357 | } |
348 | 358 | ||
349 | char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa, socklen_t salen) | 359 | char* xmalloc_sockaddr2dotted_noport(const struct sockaddr *sa) |
350 | { | 360 | { |
351 | return sockaddr2str(sa, salen, NI_NUMERICHOST | IGNORE_PORT); | 361 | return sockaddr2str(sa, NI_NUMERICHOST | IGNORE_PORT); |
352 | } | 362 | } |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 64061e4f0..5a1090eaf 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -169,13 +169,18 @@ int ndelay_off(int fd) | |||
169 | return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); | 169 | return fcntl(fd, F_SETFL, fcntl(fd,F_GETFL,0) & ~O_NONBLOCK); |
170 | } | 170 | } |
171 | 171 | ||
172 | void xdup2(int from, int to) | ||
173 | { | ||
174 | if (dup2(from, to) != to) | ||
175 | bb_perror_msg_and_die("can't duplicate file descriptor"); | ||
176 | } | ||
177 | |||
172 | // "Renumber" opened fd | 178 | // "Renumber" opened fd |
173 | void xmove_fd(int from, int to) | 179 | void xmove_fd(int from, int to) |
174 | { | 180 | { |
175 | if (from == to) | 181 | if (from == to) |
176 | return; | 182 | return; |
177 | if (dup2(from, to) != to) | 183 | xdup2(from, to); |
178 | bb_perror_msg_and_die("can't duplicate file descriptor"); | ||
179 | close(from); | 184 | close(from); |
180 | } | 185 | } |
181 | 186 | ||
diff --git a/loginutils/getty.c b/loginutils/getty.c index 0254d3203..8b78856a2 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -226,12 +226,6 @@ static void parse_args(int argc, char **argv, struct options *op) | |||
226 | debug("exiting parseargs\n"); | 226 | debug("exiting parseargs\n"); |
227 | } | 227 | } |
228 | 228 | ||
229 | static void xdup2(int srcfd, int dstfd, const char *tty) | ||
230 | { | ||
231 | if (dup2(srcfd, dstfd) == -1) | ||
232 | bb_perror_msg_and_die("%s: dup", tty); | ||
233 | } | ||
234 | |||
235 | /* open_tty - set up tty as standard { input, output, error } */ | 229 | /* open_tty - set up tty as standard { input, output, error } */ |
236 | static void open_tty(const char *tty, struct termios *tp, int local) | 230 | static void open_tty(const char *tty, struct termios *tp, int local) |
237 | { | 231 | { |
@@ -255,7 +249,7 @@ static void open_tty(const char *tty, struct termios *tp, int local) | |||
255 | 249 | ||
256 | debug("open(2)\n"); | 250 | debug("open(2)\n"); |
257 | fd = xopen(tty, O_RDWR | O_NONBLOCK); | 251 | fd = xopen(tty, O_RDWR | O_NONBLOCK); |
258 | xdup2(fd, 0, tty); | 252 | xdup2(fd, 0); |
259 | while (fd > 2) close(fd--); | 253 | while (fd > 2) close(fd--); |
260 | } else { | 254 | } else { |
261 | /* | 255 | /* |
@@ -269,8 +263,8 @@ static void open_tty(const char *tty, struct termios *tp, int local) | |||
269 | 263 | ||
270 | /* Replace current standard output/error fd's with new ones */ | 264 | /* Replace current standard output/error fd's with new ones */ |
271 | debug("duping\n"); | 265 | debug("duping\n"); |
272 | xdup2(0, 1, tty); | 266 | xdup2(0, 1); |
273 | xdup2(0, 2, tty); | 267 | xdup2(0, 2); |
274 | 268 | ||
275 | /* | 269 | /* |
276 | * The following ioctl will fail if stdin is not a tty, but also when | 270 | * The following ioctl will fail if stdin is not a tty, but also when |
diff --git a/networking/dnsd.c b/networking/dnsd.c index 32166e555..672b729e0 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -375,7 +375,7 @@ int dnsd_main(int argc, char **argv) | |||
375 | xbind(udps, &lsa->sa, lsa->len); | 375 | xbind(udps, &lsa->sa, lsa->len); |
376 | /* xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? */ | 376 | /* xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? */ |
377 | bb_info_msg("Accepting UDP packets on %s", | 377 | bb_info_msg("Accepting UDP packets on %s", |
378 | xmalloc_sockaddr2dotted(&lsa->sa, lsa->len)); | 378 | xmalloc_sockaddr2dotted(&lsa->sa)); |
379 | 379 | ||
380 | while (1) { | 380 | while (1) { |
381 | int r; | 381 | int r; |
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index f3d6009dd..255e413cb 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c | |||
@@ -348,7 +348,7 @@ int ftpgetput_main(int argc, char **argv) | |||
348 | server->lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21)); | 348 | server->lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21)); |
349 | if (verbose_flag) { | 349 | if (verbose_flag) { |
350 | printf("Connecting to %s (%s)\n", argv[0], | 350 | printf("Connecting to %s (%s)\n", argv[0], |
351 | xmalloc_sockaddr2dotted(&server->lsa->sa, server->lsa->len)); | 351 | xmalloc_sockaddr2dotted(&server->lsa->sa)); |
352 | } | 352 | } |
353 | 353 | ||
354 | /* Connect/Setup/Configure the FTP session */ | 354 | /* Connect/Setup/Configure the FTP session */ |
diff --git a/networking/inetd.c b/networking/inetd.c index 211a8dcbf..a7517ebdf 100644 --- a/networking/inetd.c +++ b/networking/inetd.c | |||
@@ -453,8 +453,7 @@ static void setup(servtab_t *sep) | |||
453 | bb_perror_msg("%s/%s: socket", sep->se_service, sep->se_proto); | 453 | bb_perror_msg("%s/%s: socket", sep->se_service, sep->se_proto); |
454 | return; | 454 | return; |
455 | } | 455 | } |
456 | if (setsockopt_reuseaddr(sep->se_fd) < 0) | 456 | setsockopt_reuseaddr(sep->se_fd); |
457 | bb_perror_msg("setsockopt(SO_REUSEADDR)"); | ||
458 | 457 | ||
459 | #if ENABLE_FEATURE_INETD_RPC | 458 | #if ENABLE_FEATURE_INETD_RPC |
460 | if (isrpcservice(sep)) { | 459 | if (isrpcservice(sep)) { |
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index 0d1071499..30abb3c1c 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c | |||
@@ -278,7 +278,7 @@ static void dolisten(void) | |||
278 | rr = getsockname(netfd, &ouraddr->sa, &ouraddr->len); | 278 | rr = getsockname(netfd, &ouraddr->sa, &ouraddr->len); |
279 | if (rr < 0) | 279 | if (rr < 0) |
280 | bb_perror_msg_and_die("getsockname after bind"); | 280 | bb_perror_msg_and_die("getsockname after bind"); |
281 | addr = xmalloc_sockaddr2dotted(&ouraddr->sa, ouraddr->len); | 281 | addr = xmalloc_sockaddr2dotted(&ouraddr->sa); |
282 | fprintf(stderr, "listening on %s ...\n", addr); | 282 | fprintf(stderr, "listening on %s ...\n", addr); |
283 | free(addr); | 283 | free(addr); |
284 | } | 284 | } |
@@ -341,7 +341,7 @@ create new one, and bind() it. TODO */ | |||
341 | /* nc 1.10 bails out instead, and its error message | 341 | /* nc 1.10 bails out instead, and its error message |
342 | * is not suppressed by o_verbose */ | 342 | * is not suppressed by o_verbose */ |
343 | if (o_verbose) { | 343 | if (o_verbose) { |
344 | char *remaddr = xmalloc_sockaddr2dotted(&remend.sa, remend.len); | 344 | char *remaddr = xmalloc_sockaddr2dotted(&remend.sa); |
345 | bb_error_msg("connect from wrong ip/port %s ignored", remaddr); | 345 | bb_error_msg("connect from wrong ip/port %s ignored", remaddr); |
346 | free(remaddr); | 346 | free(remaddr); |
347 | } | 347 | } |
@@ -393,9 +393,9 @@ create new one, and bind() it. TODO */ | |||
393 | accept the connection and then reject undesireable ones by closing. | 393 | accept the connection and then reject undesireable ones by closing. |
394 | In other words, we need a TCP MSG_PEEK. */ | 394 | In other words, we need a TCP MSG_PEEK. */ |
395 | /* bbox: removed most of it */ | 395 | /* bbox: removed most of it */ |
396 | lcladdr = xmalloc_sockaddr2dotted(&ouraddr->sa, ouraddr->len); | 396 | lcladdr = xmalloc_sockaddr2dotted(&ouraddr->sa); |
397 | remaddr = xmalloc_sockaddr2dotted(&remend.sa, remend.len); | 397 | remaddr = xmalloc_sockaddr2dotted(&remend.sa); |
398 | remhostname = o_nflag ? remaddr : xmalloc_sockaddr2host(&remend.sa, remend.len); | 398 | remhostname = o_nflag ? remaddr : xmalloc_sockaddr2host(&remend.sa); |
399 | fprintf(stderr, "connect to %s from %s (%s)\n", | 399 | fprintf(stderr, "connect to %s from %s (%s)\n", |
400 | lcladdr, remhostname, remaddr); | 400 | lcladdr, remhostname, remaddr); |
401 | free(lcladdr); | 401 | free(lcladdr); |
@@ -796,7 +796,7 @@ int nc_main(int argc, char **argv) | |||
796 | 796 | ||
797 | remend = *themaddr; | 797 | remend = *themaddr; |
798 | if (o_verbose) | 798 | if (o_verbose) |
799 | themdotted = xmalloc_sockaddr2dotted(&themaddr->sa, themaddr->len); | 799 | themdotted = xmalloc_sockaddr2dotted(&themaddr->sa); |
800 | 800 | ||
801 | x = connect_w_timeout(netfd); | 801 | x = connect_w_timeout(netfd); |
802 | if (o_zero && x == 0 && o_udpmode) /* if UDP scanning... */ | 802 | if (o_zero && x == 0 && o_udpmode) /* if UDP scanning... */ |
diff --git a/networking/netstat.c b/networking/netstat.c index 014e5e251..9fd3d2f86 100644 --- a/networking/netstat.c +++ b/networking/netstat.c | |||
@@ -140,8 +140,8 @@ static char *ip_port_str(struct sockaddr *addr, int port, const char *proto, int | |||
140 | /* Code which used "*" for INADDR_ANY is removed: it's ambiguous in IPv6, | 140 | /* Code which used "*" for INADDR_ANY is removed: it's ambiguous in IPv6, |
141 | * while "0.0.0.0" is not. */ | 141 | * while "0.0.0.0" is not. */ |
142 | 142 | ||
143 | host = numeric ? xmalloc_sockaddr2dotted_noport(addr, salen) | 143 | host = numeric ? xmalloc_sockaddr2dotted_noport(addr) |
144 | : xmalloc_sockaddr2host_noport(addr, salen); | 144 | : xmalloc_sockaddr2host_noport(addr); |
145 | 145 | ||
146 | host_port = xasprintf("%s:%s", host, get_sname(htons(port), proto, numeric)); | 146 | host_port = xasprintf("%s:%s", host, get_sname(htons(port), proto, numeric)); |
147 | free(host); | 147 | free(host); |
diff --git a/networking/nslookup.c b/networking/nslookup.c index 608e65462..0036d0d17 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c | |||
@@ -72,8 +72,8 @@ static int print_host(const char *hostname, const char *header) | |||
72 | // printf("%s\n", cur->ai_canonname); ? | 72 | // printf("%s\n", cur->ai_canonname); ? |
73 | while (cur) { | 73 | while (cur) { |
74 | char *dotted, *revhost; | 74 | char *dotted, *revhost; |
75 | dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr, cur->ai_addrlen); | 75 | dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr); |
76 | revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr, cur->ai_addrlen); | 76 | revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr); |
77 | 77 | ||
78 | printf("Address %u: %s%c", ++cnt, dotted, revhost ? ' ' : '\n'); | 78 | printf("Address %u: %s%c", ++cnt, dotted, revhost ? ' ' : '\n'); |
79 | if (revhost) { | 79 | if (revhost) { |
@@ -102,8 +102,7 @@ static void server_print(void) | |||
102 | { | 102 | { |
103 | char *server; | 103 | char *server; |
104 | 104 | ||
105 | server = xmalloc_sockaddr2dotted_noport((struct sockaddr*)&_res.nsaddr_list[0], | 105 | server = xmalloc_sockaddr2dotted_noport((struct sockaddr*)&_res.nsaddr_list[0]); |
106 | sizeof(struct sockaddr_in)); | ||
107 | /* I honestly don't know what to do if DNS server has _IPv6 address_. | 106 | /* I honestly don't know what to do if DNS server has _IPv6 address_. |
108 | * Probably it is listed in | 107 | * Probably it is listed in |
109 | * _res._u._ext_.nsaddrs[MAXNS] (of type "struct sockaddr_in6*" each) | 108 | * _res._u._ext_.nsaddrs[MAXNS] (of type "struct sockaddr_in6*" each) |
diff --git a/networking/ping.c b/networking/ping.c index 127474ccc..d1a413dd3 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -664,7 +664,7 @@ static void ping(len_and_sockaddr *lsa) | |||
664 | printf("PING %s (%s)", hostname, dotted); | 664 | printf("PING %s (%s)", hostname, dotted); |
665 | if (source_lsa) { | 665 | if (source_lsa) { |
666 | printf(" from %s", | 666 | printf(" from %s", |
667 | xmalloc_sockaddr2dotted_noport(&source_lsa->sa, source_lsa->len)); | 667 | xmalloc_sockaddr2dotted_noport(&source_lsa->sa)); |
668 | } | 668 | } |
669 | printf(": %d data bytes\n", datalen); | 669 | printf(": %d data bytes\n", datalen); |
670 | 670 | ||
@@ -715,7 +715,7 @@ int ping_main(int argc, char **argv) | |||
715 | /* leaking it here... */ | 715 | /* leaking it here... */ |
716 | source_lsa = NULL; | 716 | source_lsa = NULL; |
717 | 717 | ||
718 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len); | 718 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa); |
719 | ping(lsa); | 719 | ping(lsa); |
720 | pingstats(0); | 720 | pingstats(0); |
721 | return EXIT_SUCCESS; | 721 | return EXIT_SUCCESS; |
diff --git a/networking/tftp.c b/networking/tftp.c index 85d1a857f..030c0116e 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -443,7 +443,7 @@ int tftp_main(int argc, char **argv) | |||
443 | 443 | ||
444 | #if ENABLE_DEBUG_TFTP | 444 | #if ENABLE_DEBUG_TFTP |
445 | fprintf(stderr, "using server '%s', remotefile '%s', localfile '%s'\n", | 445 | fprintf(stderr, "using server '%s', remotefile '%s', localfile '%s'\n", |
446 | xmalloc_sockaddr2dotted(&peer_lsa->sa, peer_lsa->len), | 446 | xmalloc_sockaddr2dotted(&peer_lsa->sa), |
447 | remotefile, localfile); | 447 | remotefile, localfile); |
448 | #endif | 448 | #endif |
449 | 449 | ||
diff --git a/networking/traceroute.c b/networking/traceroute.c index 20f304d53..0923d97dc 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -812,7 +812,7 @@ print_inetname(struct sockaddr_in *from) | |||
812 | else { | 812 | else { |
813 | char *n = NULL; | 813 | char *n = NULL; |
814 | if (from->sin_addr.s_addr != INADDR_ANY) | 814 | if (from->sin_addr.s_addr != INADDR_ANY) |
815 | n = xmalloc_sockaddr2host_noport((struct sockaddr*)from, sizeof(*from)); | 815 | n = xmalloc_sockaddr2host_noport((struct sockaddr*)from); |
816 | printf(" %s (%s)", (n ? n : ina), ina); | 816 | printf(" %s (%s)", (n ? n : ina), ina); |
817 | free(n); | 817 | free(n); |
818 | } | 818 | } |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index bc21176a5..33417af09 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -83,7 +83,7 @@ int udhcp_sp_fd_set(fd_set *rfds, int extra_fd); | |||
83 | int udhcp_sp_read(fd_set *rfds); | 83 | int udhcp_sp_read(fd_set *rfds); |
84 | int raw_socket(int ifindex); | 84 | int raw_socket(int ifindex); |
85 | int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t *arp); | 85 | int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t *arp); |
86 | int listen_socket(uint32_t ip, int port, const char *inf); | 86 | int listen_socket(/*uint32_t ip,*/ int port, const char *inf); |
87 | /* Returns 1 if no reply received */ | 87 | /* Returns 1 if no reply received */ |
88 | int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface); | 88 | int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface); |
89 | 89 | ||
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 7d38742b9..f0a3351fd 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -311,7 +311,7 @@ int udhcpc_main(int argc, char **argv) | |||
311 | 311 | ||
312 | if (listen_mode != LISTEN_NONE && sockfd < 0) { | 312 | if (listen_mode != LISTEN_NONE && sockfd < 0) { |
313 | if (listen_mode == LISTEN_KERNEL) | 313 | if (listen_mode == LISTEN_KERNEL) |
314 | sockfd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface); | 314 | sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface); |
315 | else | 315 | else |
316 | sockfd = raw_socket(client_config.ifindex); | 316 | sockfd = raw_socket(client_config.ifindex); |
317 | } | 317 | } |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index fb42e2f73..2fd16ce9b 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -95,7 +95,7 @@ int udhcpd_main(int argc, char **argv) | |||
95 | while (1) { /* loop until universe collapses */ | 95 | while (1) { /* loop until universe collapses */ |
96 | 96 | ||
97 | if (server_socket < 0) { | 97 | if (server_socket < 0) { |
98 | server_socket = listen_socket(INADDR_ANY, SERVER_PORT, | 98 | server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT, |
99 | server_config.interface); | 99 | server_config.interface); |
100 | } | 100 | } |
101 | 101 | ||
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c index 4ed65a2d6..3e1758d5c 100644 --- a/networking/udhcp/dhcprelay.c +++ b/networking/udhcp/dhcprelay.c | |||
@@ -167,16 +167,17 @@ static int init_sockets(char **client, int num_clients, | |||
167 | int i; | 167 | int i; |
168 | 168 | ||
169 | /* talk to real server on bootps */ | 169 | /* talk to real server on bootps */ |
170 | fds[0] = listen_socket(htonl(INADDR_ANY), 67, server); | 170 | fds[0] = listen_socket(/*INADDR_ANY,*/ 67, server); |
171 | *max_socket = fds[0]; | 171 | *max_socket = fds[0]; |
172 | 172 | ||
173 | /* array starts at 1 since server is 0 */ | 173 | /* array starts at 1 since server is 0 */ |
174 | num_clients++; | 174 | num_clients++; |
175 | 175 | ||
176 | for (i=1; i < num_clients; i++) { | 176 | for (i = 1; i < num_clients; i++) { |
177 | /* listen for clients on bootps */ | 177 | /* listen for clients on bootps */ |
178 | fds[i] = listen_socket(htonl(INADDR_ANY), 67, client[i-1]); | 178 | fds[i] = listen_socket(/*NADDR_ANY,*/ 67, client[i-1]); |
179 | if (fds[i] > *max_socket) *max_socket = fds[i]; | 179 | if (fds[i] > *max_socket) |
180 | *max_socket = fds[i]; | ||
180 | } | 181 | } |
181 | 182 | ||
182 | return i; | 183 | return i; |
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 272e79df1..41cd32135 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
@@ -194,17 +194,14 @@ int udhcp_kernel_packet(struct dhcpMessage *payload, | |||
194 | if (fd < 0) | 194 | if (fd < 0) |
195 | return -1; | 195 | return -1; |
196 | 196 | ||
197 | if (setsockopt_reuseaddr(fd) == -1) { | 197 | setsockopt_reuseaddr(fd); |
198 | close(fd); | ||
199 | return -1; | ||
200 | } | ||
201 | 198 | ||
202 | memset(&client, 0, sizeof(client)); | 199 | memset(&client, 0, sizeof(client)); |
203 | client.sin_family = AF_INET; | 200 | client.sin_family = AF_INET; |
204 | client.sin_port = htons(source_port); | 201 | client.sin_port = htons(source_port); |
205 | client.sin_addr.s_addr = source_ip; | 202 | client.sin_addr.s_addr = source_ip; |
206 | 203 | ||
207 | if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) { | 204 | if (bind(fd, (struct sockaddr *)&client, sizeof(client)) == -1) { |
208 | close(fd); | 205 | close(fd); |
209 | return -1; | 206 | return -1; |
210 | } | 207 | } |
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 1e62f8e40..79ddfb1e2 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c | |||
@@ -45,10 +45,6 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t | |||
45 | 45 | ||
46 | memset(&ifr, 0, sizeof(ifr)); | 46 | memset(&ifr, 0, sizeof(ifr)); |
47 | fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); | 47 | fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); |
48 | // if (fd < 0) { | ||
49 | // bb_perror_msg("socket failed"); | ||
50 | // return -1; | ||
51 | // } | ||
52 | 48 | ||
53 | ifr.ifr_addr.sa_family = AF_INET; | 49 | ifr.ifr_addr.sa_family = AF_INET; |
54 | strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); | 50 | strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); |
@@ -87,40 +83,30 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t | |||
87 | return 0; | 83 | return 0; |
88 | } | 84 | } |
89 | 85 | ||
90 | 86 | /* 1. None of the callers expects it to ever fail */ | |
91 | int listen_socket(uint32_t ip, int port, const char *inf) | 87 | /* 2. ip was always INADDR_ANY */ |
88 | int listen_socket(/*uint32_t ip,*/ int port, const char *inf) | ||
92 | { | 89 | { |
93 | struct ifreq interface; | ||
94 | int fd; | 90 | int fd; |
91 | struct ifreq interface; | ||
95 | struct sockaddr_in addr; | 92 | struct sockaddr_in addr; |
96 | 93 | ||
97 | DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf); | 94 | DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf); |
98 | fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); | 95 | fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); |
99 | 96 | ||
100 | memset(&addr, 0, sizeof(addr)); | 97 | setsockopt_reuseaddr(fd); |
101 | addr.sin_family = AF_INET; | 98 | if (setsockopt_broadcast(fd) == -1) |
102 | addr.sin_port = htons(port); | 99 | bb_perror_msg_and_die("SO_BROADCAST"); |
103 | addr.sin_addr.s_addr = ip; | ||
104 | |||
105 | if (setsockopt_reuseaddr(fd) == -1) { | ||
106 | close(fd); | ||
107 | return -1; | ||
108 | } | ||
109 | if (setsockopt_broadcast(fd) == -1) { | ||
110 | close(fd); | ||
111 | return -1; | ||
112 | } | ||
113 | 100 | ||
114 | strncpy(interface.ifr_name, inf, IFNAMSIZ); | 101 | strncpy(interface.ifr_name, inf, IFNAMSIZ); |
115 | if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface)) < 0) { | 102 | if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface)) == -1) |
116 | close(fd); | 103 | bb_perror_msg_and_die("SO_BINDTODEVICE"); |
117 | return -1; | ||
118 | } | ||
119 | 104 | ||
120 | if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { | 105 | memset(&addr, 0, sizeof(addr)); |
121 | close(fd); | 106 | addr.sin_family = AF_INET; |
122 | return -1; | 107 | addr.sin_port = htons(port); |
123 | } | 108 | /* addr.sin_addr.s_addr = ip; - all-zeros is INADDR_ANY */ |
109 | xbind(fd, (struct sockaddr *)&addr, sizeof(addr)); | ||
124 | 110 | ||
125 | return fd; | 111 | return fd; |
126 | } | 112 | } |
diff --git a/networking/wget.c b/networking/wget.c index d90368c40..3e61ea656 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -236,7 +236,7 @@ int wget_main(int argc, char **argv) | |||
236 | lsa = xhost2sockaddr(server.host, server.port); | 236 | lsa = xhost2sockaddr(server.host, server.port); |
237 | if (!(opt & WGET_OPT_QUIET)) { | 237 | if (!(opt & WGET_OPT_QUIET)) { |
238 | fprintf(stderr, "Connecting to %s (%s)\n", server.host, | 238 | fprintf(stderr, "Connecting to %s (%s)\n", server.host, |
239 | xmalloc_sockaddr2dotted(&lsa->sa, lsa->len)); | 239 | xmalloc_sockaddr2dotted(&lsa->sa)); |
240 | /* We leak result of xmalloc_sockaddr2dotted */ | 240 | /* We leak result of xmalloc_sockaddr2dotted */ |
241 | } | 241 | } |
242 | 242 | ||
diff --git a/runit/runsv.c b/runit/runsv.c index 20f849528..f70b51390 100644 --- a/runit/runsv.c +++ b/runit/runsv.c | |||
@@ -313,14 +313,11 @@ static void startservice(struct svdir *s) | |||
313 | /* child */ | 313 | /* child */ |
314 | if (haslog) { | 314 | if (haslog) { |
315 | if (s->islog) { | 315 | if (s->islog) { |
316 | if (dup2(logpipe[0], 0) == -1) | 316 | xdup2(logpipe[0], 0); |
317 | fatal_cannot("setup filedescriptor for ./log/run"); | ||
318 | close(logpipe[1]); | 317 | close(logpipe[1]); |
319 | if (chdir("./log") == -1) | 318 | xchdir("./log"); |
320 | fatal_cannot("change directory to ./log"); | ||
321 | } else { | 319 | } else { |
322 | if (dup2(logpipe[1], 1) == -1) | 320 | xdup2(logpipe[1], 1); |
323 | fatal_cannot("setup filedescriptor for ./run"); | ||
324 | close(logpipe[0]); | 321 | close(logpipe[0]); |
325 | } | 322 | } |
326 | } | 323 | } |
diff --git a/util-linux/mount.c b/util-linux/mount.c index c159f41e1..bd7ecc258 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -1413,7 +1413,7 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
1413 | 1413 | ||
1414 | // insert ip=... option into string flags. | 1414 | // insert ip=... option into string flags. |
1415 | 1415 | ||
1416 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len); | 1416 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa); |
1417 | ip = xasprintf("ip=%s", dotted); | 1417 | ip = xasprintf("ip=%s", dotted); |
1418 | parse_mount_options(ip, &filteropts); | 1418 | parse_mount_options(ip, &filteropts); |
1419 | 1419 | ||