diff options
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/xconnect.c | 16 | ||||
-rw-r--r-- | networking/ftpd.c | 4 | ||||
-rw-r--r-- | networking/ftpgetput.c | 2 | ||||
-rw-r--r-- | networking/inetd.c | 4 | ||||
-rw-r--r-- | networking/nc_bloaty.c | 8 | ||||
-rw-r--r-- | networking/pscan.c | 2 | ||||
-rw-r--r-- | networking/tcpudp.c | 2 | ||||
-rw-r--r-- | networking/traceroute.c | 8 | ||||
-rw-r--r-- | networking/wget.c | 2 |
10 files changed, 26 insertions, 24 deletions
diff --git a/include/libbb.h b/include/libbb.h index f2f3313..34f7f6a 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 /* Assign sin[6]_port member if the socket is an AF_INET[6] one, * otherwise no-op. Useful for ftp. * NB: does NOT do htons() internally, just direct assignment. */ -void set_nport(len_and_sockaddr *lsa, unsigned port) FAST_FUNC; +void set_nport(struct sockaddr *sa, unsigned port) FAST_FUNC; /* Retrieve sin[6]_port or return -1 for non-INET[6] lsa's */ int get_nport(const struct sockaddr *sa) FAST_FUNC; /* Reverse DNS. Returns NULL on failure. */ diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 127e2a5..4b7c110 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c @@ -134,16 +134,18 @@ int FAST_FUNC get_nport(const struct sockaddr *sa) return -1; } -void FAST_FUNC set_nport(len_and_sockaddr *lsa, unsigned port) +void FAST_FUNC set_nport(struct sockaddr *sa, unsigned port) { #if ENABLE_FEATURE_IPV6 - if (lsa->u.sa.sa_family == AF_INET6) { - lsa->u.sin6.sin6_port = port; + if (sa->sa_family == AF_INET6) { + struct sockaddr_in6 *sin6 = (void*) sa; + sin6->sin6_port = port; return; } #endif - if (lsa->u.sa.sa_family == AF_INET) { - lsa->u.sin.sin_port = port; + if (sa->sa_family == AF_INET) { + struct sockaddr_in *sin = (void*) sa; + sin->sin_port = port; return; } /* What? UNIX socket? IPX?? :) */ @@ -283,7 +285,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;) memcpy(&r->u.sa, used_res->ai_addr, used_res->ai_addrlen); set_port: - set_nport(r, htons(port)); + set_nport(&r->u.sa, htons(port)); ret: if (result) freeaddrinfo(result); @@ -369,7 +371,7 @@ static int create_and_bind_or_die(const char *bindaddr, int port, int sock_type) fd = xsocket(lsa->u.sa.sa_family, sock_type, 0); } else { fd = xsocket_type(&lsa, IF_FEATURE_IPV6(AF_UNSPEC,) sock_type); - set_nport(lsa, htons(port)); + set_nport(&lsa->u.sa, htons(port)); } setsockopt_reuseaddr(fd); xbind(fd, &lsa->u.sa, lsa->len); diff --git a/networking/ftpd.c b/networking/ftpd.c index b591356..fae634e 100644 --- a/networking/ftpd.c +++ b/networking/ftpd.c @@ -433,7 +433,7 @@ bind_for_passive_mode(void) G.pasv_listen_fd = fd = xsocket(G.local_addr->u.sa.sa_family, SOCK_STREAM, 0); setsockopt_reuseaddr(fd); - set_nport(G.local_addr, 0); + set_nport(&G.local_addr->u.sa, 0); xbind(fd, &G.local_addr->u.sa, G.local_addr->len); xlisten(fd, 1); getsockname(fd, &G.local_addr->u.sa, &G.local_addr->len); @@ -542,7 +542,7 @@ handle_port(void) G.port_addr = xdotted2sockaddr(raw, port); #else G.port_addr = get_peer_lsa(STDIN_FILENO); - set_nport(G.port_addr, htons(port)); + set_nport(&G.port_addr->u.sa, htons(port)); #endif WRITE_OK(FTP_PORTOK); } diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c index c68d0ac..09c5ff3 100644 --- a/networking/ftpgetput.c +++ b/networking/ftpgetput.c @@ -151,7 +151,7 @@ TODO2: need to stop ignoring IP address in PASV response. *buf_ptr = '\0'; port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; - set_nport(lsa, htons(port_num)); + set_nport(&lsa->u.sa, htons(port_num)); return xconnect_stream(lsa); } diff --git a/networking/inetd.c b/networking/inetd.c index fb00c6c..6018665 100644 --- a/networking/inetd.c +++ b/networking/inetd.c @@ -501,7 +501,7 @@ static void prepare_socket_fd(servtab_t *sep) /* zero out the port for all RPC services; let bind() * find one. */ - set_nport(sep->se_lsa, 0); + set_nport(&sep->se_lsa->u.sa, 0); /* for RPC services, attempt to use a reserved port * if they are going to be running as root. */ @@ -959,7 +959,7 @@ static void reread_config_file(int sig UNUSED_PARAM) } if (LONE_CHAR(sep->se_local_hostname, '*')) { lsa = xzalloc_lsa(sep->se_family); - set_nport(lsa, port); + set_nport(&lsa->u.sa, port); } else { lsa = host_and_af2sockaddr(sep->se_local_hostname, ntohs(port), sep->se_family); diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c index e98a5dd..29f99e7 100644 --- a/networking/nc_bloaty.c +++ b/networking/nc_bloaty.c @@ -386,10 +386,10 @@ create new one, and bind() it. TODO */ if (port == 0) { /* "nc -nl -p LPORT RHOST" (w/o RPORT!): * we should accept any remote port */ - set_nport(&remend, 0); /* blot out remote port# */ + set_nport(&remend.u.sa, 0); /* blot out remote port# */ } r = memcmp(&remend.u.sa, &themaddr->u.sa, remend.len); - set_nport(&remend, sv_port); /* restore */ + set_nport(&remend.u.sa, sv_port); /* restore */ if (r != 0) { /* nc 1.10 bails out instead, and its error message * is not suppressed by o_verbose */ @@ -486,7 +486,7 @@ static int udptest(void) us to hang forever, and hit it */ o_wait = 5; /* enough that we'll notice?? */ rr = xsocket(ouraddr->u.sa.sa_family, SOCK_STREAM, 0); - set_nport(themaddr, htons(SLEAZE_PORT)); + set_nport(&themaddr->u.sa, htons(SLEAZE_PORT)); connect_w_timeout(rr); /* don't need to restore themaddr's port, it's not used anymore */ close(rr); @@ -813,7 +813,7 @@ int nc_main(int argc UNUSED_PARAM, char **argv) (themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC), x); if (o_lport) - set_nport(ouraddr, htons(o_lport)); + set_nport(&ouraddr->u.sa, htons(o_lport)); } xmove_fd(x, netfd); setsockopt_reuseaddr(netfd); diff --git a/networking/pscan.c b/networking/pscan.c index a8194d1..a9e5d5c 100644 --- a/networking/pscan.c +++ b/networking/pscan.c @@ -76,7 +76,7 @@ int pscan_main(int argc UNUSED_PARAM, char **argv) DMSG("rtt %u", rtt_4); /* The SOCK_STREAM socket type is implemented on the TCP/IP protocol. */ - set_nport(lsap, htons(port)); + set_nport(&lsap->u.sa, htons(port)); s = xsocket(lsap->u.sa.sa_family, SOCK_STREAM, 0); /* We need unblocking socket so we don't need to wait for ETIMEOUT. */ /* Nonblocking connect typically "fails" with errno == EINPROGRESS */ diff --git a/networking/tcpudp.c b/networking/tcpudp.c index b532e43..3ff2acb 100644 --- a/networking/tcpudp.c +++ b/networking/tcpudp.c @@ -387,7 +387,7 @@ int tcpudpsvd_main(int argc UNUSED_PARAM, char **argv) * already bound in parent! This seems to work in Linux. * (otherwise we can move socket to fd #0 only if bind succeeds) */ close(0); - set_nport(localp, htons(local_port)); + set_nport(&localp->u.sa, htons(local_port)); xmove_fd(xsocket(localp->u.sa.sa_family, SOCK_DGRAM, 0), 0); setsockopt_reuseaddr(0); /* crucial */ xbind(0, &localp->u.sa, localp->len); diff --git a/networking/traceroute.c b/networking/traceroute.c index 82bb011..55dc15b 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -482,7 +482,7 @@ send_probe(int seq, int ttl) if (!(option_mask32 & OPT_USE_ICMP)) { out = outdata; len -= sizeof(*outudp); - set_nport(dest_lsa, htons(port + seq)); + set_nport(&dest_lsa->u.sa, htons(port + seq)); } } @@ -1018,10 +1018,10 @@ common_traceroute_main(int op, char **argv) int probe_fd = xsocket(af, SOCK_DGRAM, 0); if (op & OPT_DEVICE) setsockopt_bindtodevice(probe_fd, device); - set_nport(dest_lsa, htons(1025)); + set_nport(&dest_lsa->u.sa, htons(1025)); /* dummy connect. makes kernel pick source IP (and port) */ xconnect(probe_fd, &dest_lsa->u.sa, dest_lsa->len); - set_nport(dest_lsa, htons(port)); + set_nport(&dest_lsa->u.sa, htons(port)); /* read IP and port */ source_lsa = get_sock_lsa(probe_fd); @@ -1031,7 +1031,7 @@ common_traceroute_main(int op, char **argv) close(probe_fd); /* bind our sockets to this IP (but not port) */ - set_nport(source_lsa, 0); + set_nport(&source_lsa->u.sa, 0); xbind(sndsock, &source_lsa->u.sa, source_lsa->len); xbind(rcvsock, &source_lsa->u.sa, source_lsa->len); diff --git a/networking/wget.c b/networking/wget.c index 2f89c8f..3a4be98 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_ str = strrchr(G.wget_buf, ','); if (!str) goto pasv_error; port += xatou_range(str+1, 0, 255) * 256; - set_nport(lsa, htons(port)); + set_nport(&lsa->u.sa, htons(port)); *dfpp = open_socket(lsa); |