summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2007-08-18 14:16:39 +0000
committerDenis Vlasenko2007-08-18 14:16:39 +0000
commita27a11bb2c033d3e0312dc1d62430a002314686f (patch)
tree74b32a18cb1e09c4f663a49c27ffa3725d3e4ee5 /networking
parentb98c26ad684e3aed8f1480458737f1ab90477c9e (diff)
downloadbusybox-a27a11bb2c033d3e0312dc1d62430a002314686f.zip
busybox-a27a11bb2c033d3e0312dc1d62430a002314686f.tar.gz
introduce and use xdup2(int, int)
stop checking whether setsockopt_reuseaddr(int fd) was successful (it always is) remove second parameter (sockllen) from xmalloc_sockaddr2xxxxx functions sockaddr2str 142 156 +14 collect_blk 467 474 +7 xdup2 28 33 +5 singlemount 4456 4454 -2 print_host 214 212 -2 nslookup_main 139 137 -2 ftpgetput_main 414 412 -2 udhcpd_main 1258 1255 -3 udhcpc_main 2405 2402 -3 traceroute_main 4125 4122 -3 nc_main 1072 1069 -3 buffer_fill_and_print 76 73 -3 xmalloc_sockaddr2hostonly_noport 18 14 -4 xmalloc_sockaddr2host_noport 18 14 -4 xmalloc_sockaddr2host 15 11 -4 xmalloc_sockaddr2dotted_noport 18 14 -4 xmalloc_sockaddr2dotted 18 14 -4 wget_main 2618 2614 -4 ping_main 393 389 -4 ip_port_str 120 115 -5 dhcprelay_main 1146 1141 -5 dnsd_main 1531 1525 -6 passwd_main 1110 1102 -8 udhcp_kernel_packet 206 197 -9 udhcp_listen_socket 154 144 -10 getty_main 2576 2566 -10 setup 655 640 -15 xmove_fd 51 34 -17 dolisten 759 742 -17 tcpudpsvd_main 1866 1836 -30 startservice 339 299 -40
Diffstat (limited to 'networking')
-rw-r--r--networking/dnsd.c2
-rw-r--r--networking/ftpgetput.c2
-rw-r--r--networking/inetd.c3
-rw-r--r--networking/nc_bloaty.c12
-rw-r--r--networking/netstat.c4
-rw-r--r--networking/nslookup.c7
-rw-r--r--networking/ping.c4
-rw-r--r--networking/tftp.c2
-rw-r--r--networking/traceroute.c2
-rw-r--r--networking/udhcp/common.h2
-rw-r--r--networking/udhcp/dhcpc.c2
-rw-r--r--networking/udhcp/dhcpd.c2
-rw-r--r--networking/udhcp/dhcprelay.c9
-rw-r--r--networking/udhcp/packet.c7
-rw-r--r--networking/udhcp/socket.c42
-rw-r--r--networking/wget.c2
16 files changed, 43 insertions, 61 deletions
diff --git a/networking/dnsd.c b/networking/dnsd.c
index 32166e5..672b729 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -375,7 +375,7 @@ int dnsd_main(int argc, char **argv)
xbind(udps, &lsa->sa, lsa->len);
/* xlisten(udps, 50); - ?!! DGRAM sockets are never listened on I think? */
bb_info_msg("Accepting UDP packets on %s",
- xmalloc_sockaddr2dotted(&lsa->sa, lsa->len));
+ xmalloc_sockaddr2dotted(&lsa->sa));
while (1) {
int r;
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index f3d6009..255e413 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -348,7 +348,7 @@ int ftpgetput_main(int argc, char **argv)
server->lsa = xhost2sockaddr(argv[0], bb_lookup_port(port, "tcp", 21));
if (verbose_flag) {
printf("Connecting to %s (%s)\n", argv[0],
- xmalloc_sockaddr2dotted(&server->lsa->sa, server->lsa->len));
+ xmalloc_sockaddr2dotted(&server->lsa->sa));
}
/* Connect/Setup/Configure the FTP session */
diff --git a/networking/inetd.c b/networking/inetd.c
index 211a8dc..a7517eb 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -453,8 +453,7 @@ static void setup(servtab_t *sep)
bb_perror_msg("%s/%s: socket", sep->se_service, sep->se_proto);
return;
}
- if (setsockopt_reuseaddr(sep->se_fd) < 0)
- bb_perror_msg("setsockopt(SO_REUSEADDR)");
+ setsockopt_reuseaddr(sep->se_fd);
#if ENABLE_FEATURE_INETD_RPC
if (isrpcservice(sep)) {
diff --git a/networking/nc_bloaty.c b/networking/nc_bloaty.c
index 0d10714..30abb3c 100644
--- a/networking/nc_bloaty.c
+++ b/networking/nc_bloaty.c
@@ -278,7 +278,7 @@ static void dolisten(void)
rr = getsockname(netfd, &ouraddr->sa, &ouraddr->len);
if (rr < 0)
bb_perror_msg_and_die("getsockname after bind");
- addr = xmalloc_sockaddr2dotted(&ouraddr->sa, ouraddr->len);
+ addr = xmalloc_sockaddr2dotted(&ouraddr->sa);
fprintf(stderr, "listening on %s ...\n", addr);
free(addr);
}
@@ -341,7 +341,7 @@ create new one, and bind() it. TODO */
/* nc 1.10 bails out instead, and its error message
* is not suppressed by o_verbose */
if (o_verbose) {
- char *remaddr = xmalloc_sockaddr2dotted(&remend.sa, remend.len);
+ char *remaddr = xmalloc_sockaddr2dotted(&remend.sa);
bb_error_msg("connect from wrong ip/port %s ignored", remaddr);
free(remaddr);
}
@@ -393,9 +393,9 @@ create new one, and bind() it. TODO */
accept the connection and then reject undesireable ones by closing.
In other words, we need a TCP MSG_PEEK. */
/* bbox: removed most of it */
- lcladdr = xmalloc_sockaddr2dotted(&ouraddr->sa, ouraddr->len);
- remaddr = xmalloc_sockaddr2dotted(&remend.sa, remend.len);
- remhostname = o_nflag ? remaddr : xmalloc_sockaddr2host(&remend.sa, remend.len);
+ lcladdr = xmalloc_sockaddr2dotted(&ouraddr->sa);
+ remaddr = xmalloc_sockaddr2dotted(&remend.sa);
+ remhostname = o_nflag ? remaddr : xmalloc_sockaddr2host(&remend.sa);
fprintf(stderr, "connect to %s from %s (%s)\n",
lcladdr, remhostname, remaddr);
free(lcladdr);
@@ -796,7 +796,7 @@ int nc_main(int argc, char **argv)
remend = *themaddr;
if (o_verbose)
- themdotted = xmalloc_sockaddr2dotted(&themaddr->sa, themaddr->len);
+ themdotted = xmalloc_sockaddr2dotted(&themaddr->sa);
x = connect_w_timeout(netfd);
if (o_zero && x == 0 && o_udpmode) /* if UDP scanning... */
diff --git a/networking/netstat.c b/networking/netstat.c
index 014e5e2..9fd3d2f 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
/* Code which used "*" for INADDR_ANY is removed: it's ambiguous in IPv6,
* while "0.0.0.0" is not. */
- host = numeric ? xmalloc_sockaddr2dotted_noport(addr, salen)
- : xmalloc_sockaddr2host_noport(addr, salen);
+ host = numeric ? xmalloc_sockaddr2dotted_noport(addr)
+ : xmalloc_sockaddr2host_noport(addr);
host_port = xasprintf("%s:%s", host, get_sname(htons(port), proto, numeric));
free(host);
diff --git a/networking/nslookup.c b/networking/nslookup.c
index 608e654..0036d0d 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -72,8 +72,8 @@ static int print_host(const char *hostname, const char *header)
// printf("%s\n", cur->ai_canonname); ?
while (cur) {
char *dotted, *revhost;
- dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr, cur->ai_addrlen);
- revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr, cur->ai_addrlen);
+ dotted = xmalloc_sockaddr2dotted_noport(cur->ai_addr);
+ revhost = xmalloc_sockaddr2hostonly_noport(cur->ai_addr);
printf("Address %u: %s%c", ++cnt, dotted, revhost ? ' ' : '\n');
if (revhost) {
@@ -102,8 +102,7 @@ static void server_print(void)
{
char *server;
- server = xmalloc_sockaddr2dotted_noport((struct sockaddr*)&_res.nsaddr_list[0],
- sizeof(struct sockaddr_in));
+ server = xmalloc_sockaddr2dotted_noport((struct sockaddr*)&_res.nsaddr_list[0]);
/* I honestly don't know what to do if DNS server has _IPv6 address_.
* Probably it is listed in
* _res._u._ext_.nsaddrs[MAXNS] (of type "struct sockaddr_in6*" each)
diff --git a/networking/ping.c b/networking/ping.c
index 127474c..d1a413d 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -664,7 +664,7 @@ static void ping(len_and_sockaddr *lsa)
printf("PING %s (%s)", hostname, dotted);
if (source_lsa) {
printf(" from %s",
- xmalloc_sockaddr2dotted_noport(&source_lsa->sa, source_lsa->len));
+ xmalloc_sockaddr2dotted_noport(&source_lsa->sa));
}
printf(": %d data bytes\n", datalen);
@@ -715,7 +715,7 @@ int ping_main(int argc, char **argv)
/* leaking it here... */
source_lsa = NULL;
- dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa, lsa->len);
+ dotted = xmalloc_sockaddr2dotted_noport(&lsa->sa);
ping(lsa);
pingstats(0);
return EXIT_SUCCESS;
diff --git a/networking/tftp.c b/networking/tftp.c
index 85d1a85..030c011 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -443,7 +443,7 @@ int tftp_main(int argc, char **argv)
#if ENABLE_DEBUG_TFTP
fprintf(stderr, "using server '%s', remotefile '%s', localfile '%s'\n",
- xmalloc_sockaddr2dotted(&peer_lsa->sa, peer_lsa->len),
+ xmalloc_sockaddr2dotted(&peer_lsa->sa),
remotefile, localfile);
#endif
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 20f304d..0923d97 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -812,7 +812,7 @@ print_inetname(struct sockaddr_in *from)
else {
char *n = NULL;
if (from->sin_addr.s_addr != INADDR_ANY)
- n = xmalloc_sockaddr2host_noport((struct sockaddr*)from, sizeof(*from));
+ n = xmalloc_sockaddr2host_noport((struct sockaddr*)from);
printf(" %s (%s)", (n ? n : ina), ina);
free(n);
}
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index bc21176..33417af 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);
int udhcp_sp_read(fd_set *rfds);
int raw_socket(int ifindex);
int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
-int listen_socket(uint32_t ip, int port, const char *inf);
+int listen_socket(/*uint32_t ip,*/ int port, const char *inf);
/* Returns 1 if no reply received */
int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface);
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 7d38742..f0a3351 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -311,7 +311,7 @@ int udhcpc_main(int argc, char **argv)
if (listen_mode != LISTEN_NONE && sockfd < 0) {
if (listen_mode == LISTEN_KERNEL)
- sockfd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface);
+ sockfd = listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
else
sockfd = raw_socket(client_config.ifindex);
}
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index fb42e2f..2fd16ce 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -95,7 +95,7 @@ int udhcpd_main(int argc, char **argv)
while (1) { /* loop until universe collapses */
if (server_socket < 0) {
- server_socket = listen_socket(INADDR_ANY, SERVER_PORT,
+ server_socket = listen_socket(/*INADDR_ANY,*/ SERVER_PORT,
server_config.interface);
}
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index 4ed65a2..3e1758d 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -167,16 +167,17 @@ static int init_sockets(char **client, int num_clients,
int i;
/* talk to real server on bootps */
- fds[0] = listen_socket(htonl(INADDR_ANY), 67, server);
+ fds[0] = listen_socket(/*INADDR_ANY,*/ 67, server);
*max_socket = fds[0];
/* array starts at 1 since server is 0 */
num_clients++;
- for (i=1; i < num_clients; i++) {
+ for (i = 1; i < num_clients; i++) {
/* listen for clients on bootps */
- fds[i] = listen_socket(htonl(INADDR_ANY), 67, client[i-1]);
- if (fds[i] > *max_socket) *max_socket = fds[i];
+ fds[i] = listen_socket(/*NADDR_ANY,*/ 67, client[i-1]);
+ if (fds[i] > *max_socket)
+ *max_socket = fds[i];
}
return i;
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 272e79d..41cd321 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -194,17 +194,14 @@ int udhcp_kernel_packet(struct dhcpMessage *payload,
if (fd < 0)
return -1;
- if (setsockopt_reuseaddr(fd) == -1) {
- close(fd);
- return -1;
- }
+ setsockopt_reuseaddr(fd);
memset(&client, 0, sizeof(client));
client.sin_family = AF_INET;
client.sin_port = htons(source_port);
client.sin_addr.s_addr = source_ip;
- if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) {
+ if (bind(fd, (struct sockaddr *)&client, sizeof(client)) == -1) {
close(fd);
return -1;
}
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 1e62f8e..79ddfb1 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
memset(&ifr, 0, sizeof(ifr));
fd = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
-// if (fd < 0) {
-// bb_perror_msg("socket failed");
-// return -1;
-// }
ifr.ifr_addr.sa_family = AF_INET;
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
return 0;
}
-
-int listen_socket(uint32_t ip, int port, const char *inf)
+/* 1. None of the callers expects it to ever fail */
+/* 2. ip was always INADDR_ANY */
+int listen_socket(/*uint32_t ip,*/ int port, const char *inf)
{
- struct ifreq interface;
int fd;
+ struct ifreq interface;
struct sockaddr_in addr;
DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- addr.sin_addr.s_addr = ip;
-
- if (setsockopt_reuseaddr(fd) == -1) {
- close(fd);
- return -1;
- }
- if (setsockopt_broadcast(fd) == -1) {
- close(fd);
- return -1;
- }
+ setsockopt_reuseaddr(fd);
+ if (setsockopt_broadcast(fd) == -1)
+ bb_perror_msg_and_die("SO_BROADCAST");
strncpy(interface.ifr_name, inf, IFNAMSIZ);
- if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface)) < 0) {
- close(fd);
- return -1;
- }
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface)) == -1)
+ bb_perror_msg_and_die("SO_BINDTODEVICE");
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
- close(fd);
- return -1;
- }
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ /* addr.sin_addr.s_addr = ip; - all-zeros is INADDR_ANY */
+ xbind(fd, (struct sockaddr *)&addr, sizeof(addr));
return fd;
}
diff --git a/networking/wget.c b/networking/wget.c
index d90368c..3e61ea6 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -236,7 +236,7 @@ int wget_main(int argc, char **argv)
lsa = xhost2sockaddr(server.host, server.port);
if (!(opt & WGET_OPT_QUIET)) {
fprintf(stderr, "Connecting to %s (%s)\n", server.host,
- xmalloc_sockaddr2dotted(&lsa->sa, lsa->len));
+ xmalloc_sockaddr2dotted(&lsa->sa));
/* We leak result of xmalloc_sockaddr2dotted */
}