aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h2
-rw-r--r--libbb/xconnect.c16
-rw-r--r--networking/ftpd.c4
-rw-r--r--networking/ftpgetput.c2
-rw-r--r--networking/inetd.c4
-rw-r--r--networking/nc_bloaty.c8
-rw-r--r--networking/pscan.c2
-rw-r--r--networking/tcpudp.c2
-rw-r--r--networking/traceroute.c8
-rw-r--r--networking/wget.c2
10 files changed, 26 insertions, 24 deletions
diff --git a/include/libbb.h b/include/libbb.h
index f2f3313b4..34f7f6a8b 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -589,7 +589,7 @@ len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t
589/* Assign sin[6]_port member if the socket is an AF_INET[6] one, 589/* Assign sin[6]_port member if the socket is an AF_INET[6] one,
590 * otherwise no-op. Useful for ftp. 590 * otherwise no-op. Useful for ftp.
591 * NB: does NOT do htons() internally, just direct assignment. */ 591 * NB: does NOT do htons() internally, just direct assignment. */
592void set_nport(len_and_sockaddr *lsa, unsigned port) FAST_FUNC; 592void set_nport(struct sockaddr *sa, unsigned port) FAST_FUNC;
593/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ 593/* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */
594int get_nport(const struct sockaddr *sa) FAST_FUNC; 594int get_nport(const struct sockaddr *sa) FAST_FUNC;
595/* Reverse DNS. Returns NULL on failure. */ 595/* Reverse DNS. Returns NULL on failure. */
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 127e2a5fc..4b7c110d3 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -134,16 +134,18 @@ int FAST_FUNC get_nport(const struct sockaddr *sa)
134 return -1; 134 return -1;
135} 135}
136 136
137void FAST_FUNC set_nport(len_and_sockaddr *lsa, unsigned port) 137void FAST_FUNC set_nport(struct sockaddr *sa, unsigned port)
138{ 138{
139#if ENABLE_FEATURE_IPV6 139#if ENABLE_FEATURE_IPV6
140 if (lsa->u.sa.sa_family == AF_INET6) { 140 if (sa->sa_family == AF_INET6) {
141 lsa->u.sin6.sin6_port = port; 141 struct sockaddr_in6 *sin6 = (void*) sa;
142 sin6->sin6_port = port;
142 return; 143 return;
143 } 144 }
144#endif 145#endif
145 if (lsa->u.sa.sa_family == AF_INET) { 146 if (sa->sa_family == AF_INET) {
146 lsa->u.sin.sin_port = port; 147 struct sockaddr_in *sin = (void*) sa;
148 sin->sin_port = port;
147 return; 149 return;
148 } 150 }
149 /* What? UNIX socket? IPX?? :) */ 151 /* What? UNIX socket? IPX?? :) */
@@ -283,7 +285,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;)
283 memcpy(&r->u.sa, used_res->ai_addr, used_res->ai_addrlen); 285 memcpy(&r->u.sa, used_res->ai_addr, used_res->ai_addrlen);
284 286
285 set_port: 287 set_port:
286 set_nport(r, htons(port)); 288 set_nport(&r->u.sa, htons(port));
287 ret: 289 ret:
288 if (result) 290 if (result)
289 freeaddrinfo(result); 291 freeaddrinfo(result);
@@ -369,7 +371,7 @@ static int create_and_bind_or_die(const char *bindaddr, int port, int sock_type)
369 fd = xsocket(lsa->u.sa.sa_family, sock_type, 0); 371 fd = xsocket(lsa->u.sa.sa_family, sock_type, 0);
370 } else { 372 } else {
371 fd = xsocket_type(&lsa, IF_FEATURE_IPV6(AF_UNSPEC,) sock_type); 373 fd = xsocket_type(&lsa, IF_FEATURE_IPV6(AF_UNSPEC,) sock_type);
372 set_nport(lsa, htons(port)); 374 set_nport(&lsa->u.sa, htons(port));
373 } 375 }
374 setsockopt_reuseaddr(fd); 376 setsockopt_reuseaddr(fd);
375 xbind(fd, &lsa->u.sa, lsa->len); 377 xbind(fd, &lsa->u.sa, lsa->len);
diff --git a/networking/ftpd.c b/networking/ftpd.c
index b59135667..fae634ec4 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -433,7 +433,7 @@ bind_for_passive_mode(void)
433 G.pasv_listen_fd = fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0); 433 G.pasv_listen_fd = fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0);
434 setsockopt_reuseaddr(fd); 434 setsockopt_reuseaddr(fd);
435 435
436 set_nport(G.local_addr, 0); 436 set_nport(&G.local_addr->u.sa, 0);
437 xbind(fd, &G.local_addr->u.sa, G.local_addr->len); 437 xbind(fd, &G.local_addr->u.sa, G.local_addr->len);
438 xlisten(fd, 1); 438 xlisten(fd, 1);
439 getsockname(fd, &G.local_addr->u.sa, &G.local_addr->len); 439 getsockname(fd, &G.local_addr->u.sa, &G.local_addr->len);
@@ -542,7 +542,7 @@ handle_port(void)
542 G.port_addr = xdotted2sockaddr(raw, port); 542 G.port_addr = xdotted2sockaddr(raw, port);
543#else 543#else
544 G.port_addr = get_peer_lsa(STDIN_FILENO); 544 G.port_addr = get_peer_lsa(STDIN_FILENO);
545 set_nport(G.port_addr, htons(port)); 545 set_nport(&G.port_addr->u.sa, htons(port));
546#endif 546#endif
547 WRITE_OK(FTP_PORTOK); 547 WRITE_OK(FTP_PORTOK);
548} 548}
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index c68d0ace2..09c5ff30f 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -151,7 +151,7 @@ TODO2: need to stop ignoring IP address in PASV response.
151 *buf_ptr = '\0'; 151 *buf_ptr = '\0';
152 port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; 152 port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256;
153 153
154 set_nport(lsa, htons(port_num)); 154 set_nport(&lsa->u.sa, htons(port_num));
155 return xconnect_stream(lsa); 155 return xconnect_stream(lsa);
156} 156}
157 157
diff --git a/networking/inetd.c b/networking/inetd.c
index fb00c6cd7..6018665ef 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -501,7 +501,7 @@ static void prepare_socket_fd(servtab_t *sep)
501 501
502 /* zero out the port for all RPC services; let bind() 502 /* zero out the port for all RPC services; let bind()
503 * find one. */ 503 * find one. */
504 set_nport(sep->se_lsa, 0); 504 set_nport(&sep->se_lsa->u.sa, 0);
505 505
506 /* for RPC services, attempt to use a reserved port 506 /* for RPC services, attempt to use a reserved port
507 * if they are going to be running as root. */ 507 * if they are going to be running as root. */
@@ -959,7 +959,7 @@ static void reread_config_file(int sig UNUSED_PARAM)
959 } 959 }
960 if (LONE_CHAR(sep->se_local_hostname, '*')) { 960 if (LONE_CHAR(sep->se_local_hostname, '*')) {
961 lsa = xzalloc_lsa(sep->se_family); 961 lsa = xzalloc_lsa(sep->se_family);
962 set_nport(lsa, port); 962 set_nport(&lsa->u.sa, port);
963 } else { 963 } else {
964 lsa = host_and_af2sockaddr(sep->se_local_hostname, 964 lsa = host_and_af2sockaddr(sep->se_local_hostname,
965 ntohs(port), sep->se_family); 965 ntohs(port), sep->se_family);
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index e98a5dd5b..29f99e76b 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -386,10 +386,10 @@ create new one, and bind() it. TODO */
386 if (port == 0) { 386 if (port == 0) {
387 /* "nc -nl -p LPORT RHOST" (w/o RPORT!): 387 /* "nc -nl -p LPORT RHOST" (w/o RPORT!):
388 * we should accept any remote port */ 388 * we should accept any remote port */
389 set_nport(&remend, 0); /* blot out remote port# */ 389 set_nport(&remend.u.sa, 0); /* blot out remote port# */
390 } 390 }
391 r = memcmp(&remend.u.sa, &themaddr->u.sa, remend.len); 391 r = memcmp(&remend.u.sa, &themaddr->u.sa, remend.len);
392 set_nport(&remend, sv_port); /* restore */ 392 set_nport(&remend.u.sa, sv_port); /* restore */
393 if (r != 0) { 393 if (r != 0) {
394 /* nc 1.10 bails out instead, and its error message 394 /* nc 1.10 bails out instead, and its error message
395 * is not suppressed by o_verbose */ 395 * is not suppressed by o_verbose */
@@ -486,7 +486,7 @@ static int udptest(void)
486 us to hang forever, and hit it */ 486 us to hang forever, and hit it */
487 o_wait = 5; /* enough that we'll notice?? */ 487 o_wait = 5; /* enough that we'll notice?? */
488 rr = xsocket(ouraddr->u.sa.sa_family, SOCK_STREAM, 0); 488 rr = xsocket(ouraddr->u.sa.sa_family, SOCK_STREAM, 0);
489 set_nport(themaddr, htons(SLEAZE_PORT)); 489 set_nport(&themaddr->u.sa, htons(SLEAZE_PORT));
490 connect_w_timeout(rr); 490 connect_w_timeout(rr);
491 /* don't need to restore themaddr's port, it's not used anymore */ 491 /* don't need to restore themaddr's port, it's not used anymore */
492 close(rr); 492 close(rr);
@@ -813,7 +813,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv)
813 (themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC), 813 (themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC),
814 x); 814 x);
815 if (o_lport) 815 if (o_lport)
816 set_nport(ouraddr, htons(o_lport)); 816 set_nport(&ouraddr->u.sa, htons(o_lport));
817 } 817 }
818 xmove_fd(x, netfd); 818 xmove_fd(x, netfd);
819 setsockopt_reuseaddr(netfd); 819 setsockopt_reuseaddr(netfd);
diff --git a/networking/pscan.c b/networking/pscan.c
index a8194d1a8..a9e5d5c29 100644
--- a/networking/pscan.c
+++ b/networking/pscan.c
@@ -76,7 +76,7 @@ int pscan_main(int argc UNUSED_PARAM, char **argv)
76 DMSG("rtt %u", rtt_4); 76 DMSG("rtt %u", rtt_4);
77 77
78 /* The SOCK_STREAM socket type is implemented on the TCP/IP protocol. */ 78 /* The SOCK_STREAM socket type is implemented on the TCP/IP protocol. */
79 set_nport(lsap, htons(port)); 79 set_nport(&lsap->u.sa, htons(port));
80 s = xsocket(lsap->u.sa.sa_family, SOCK_STREAM, 0); 80 s = xsocket(lsap->u.sa.sa_family, SOCK_STREAM, 0);
81 /* We need unblocking socket so we don't need to wait for ETIMEOUT. */ 81 /* We need unblocking socket so we don't need to wait for ETIMEOUT. */
82 /* Nonblocking connect typically "fails" with errno == EINPROGRESS */ 82 /* Nonblocking connect typically "fails" with errno == EINPROGRESS */
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index b532e43cd..3ff2acbf8 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -387,7 +387,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv)
387 * already bound in parent! This seems to work in Linux. 387 * already bound in parent! This seems to work in Linux.
388 * (otherwise we can move socket to fd #0 only if bind succeeds) */ 388 * (otherwise we can move socket to fd #0 only if bind succeeds) */
389 close(0); 389 close(0);
390 set_nport(localp, htons(local_port)); 390 set_nport(&localp->u.sa, htons(local_port));
391 xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0); 391 xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0);
392 setsockopt_reuseaddr(0); /* crucial */ 392 setsockopt_reuseaddr(0); /* crucial */
393 xbind(0, &localp->u.sa, localp->len); 393 xbind(0, &localp->u.sa, localp->len);
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 82bb0118c..55dc15b66 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -482,7 +482,7 @@ send_probe(int seq, int ttl)
482 if (!(option_mask32 & OPT_USE_ICMP)) { 482 if (!(option_mask32 & OPT_USE_ICMP)) {
483 out = outdata; 483 out = outdata;
484 len -= sizeof(*outudp); 484 len -= sizeof(*outudp);
485 set_nport(dest_lsa, htons(port + seq)); 485 set_nport(&dest_lsa->u.sa, htons(port + seq));
486 } 486 }
487 } 487 }
488 488
@@ -1018,10 +1018,10 @@ common_traceroute_main(int op, char **argv)
1018 int probe_fd = xsocket(af, SOCK_DGRAM, 0); 1018 int probe_fd = xsocket(af, SOCK_DGRAM, 0);
1019 if (op & OPT_DEVICE) 1019 if (op & OPT_DEVICE)
1020 setsockopt_bindtodevice(probe_fd, device); 1020 setsockopt_bindtodevice(probe_fd, device);
1021 set_nport(dest_lsa, htons(1025)); 1021 set_nport(&dest_lsa->u.sa, htons(1025));
1022 /* dummy connect. makes kernel pick source IP (and port) */ 1022 /* dummy connect. makes kernel pick source IP (and port) */
1023 xconnect(probe_fd, &dest_lsa->u.sa, dest_lsa->len); 1023 xconnect(probe_fd, &dest_lsa->u.sa, dest_lsa->len);
1024 set_nport(dest_lsa, htons(port)); 1024 set_nport(&dest_lsa->u.sa, htons(port));
1025 1025
1026 /* read IP and port */ 1026 /* read IP and port */
1027 source_lsa = get_sock_lsa(probe_fd); 1027 source_lsa = get_sock_lsa(probe_fd);
@@ -1031,7 +1031,7 @@ common_traceroute_main(int op, char **argv)
1031 close(probe_fd); 1031 close(probe_fd);
1032 1032
1033 /* bind our sockets to this IP (but not port) */ 1033 /* bind our sockets to this IP (but not port) */
1034 set_nport(source_lsa, 0); 1034 set_nport(&source_lsa->u.sa, 0);
1035 xbind(sndsock, &source_lsa->u.sa, source_lsa->len); 1035 xbind(sndsock, &source_lsa->u.sa, source_lsa->len);
1036 xbind(rcvsock, &source_lsa->u.sa, source_lsa->len); 1036 xbind(rcvsock, &source_lsa->u.sa, source_lsa->len);
1037 1037
diff --git a/networking/wget.c b/networking/wget.c
index 2f89c8f7f..3a4be9878 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -407,7 +407,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
407 str = strrchr(G.wget_buf, ','); 407 str = strrchr(G.wget_buf, ',');
408 if (!str) goto pasv_error; 408 if (!str) goto pasv_error;
409 port += xatou_range(str+1, 0, 255) * 256; 409 port += xatou_range(str+1, 0, 255) * 256;
410 set_nport(lsa, htons(port)); 410 set_nport(&lsa->u.sa, htons(port));
411 411
412 *dfpp = open_socket(lsa); 412 *dfpp = open_socket(lsa);
413 413