summaryrefslogtreecommitdiffhomepage
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/arping.c3
-rw-r--r--networking/httpd.c4
-rw-r--r--networking/nc.c15
-rw-r--r--networking/netstat.c258
-rw-r--r--networking/ping.c3
-rw-r--r--networking/ping6.c17
-rw-r--r--networking/route.c72
-rw-r--r--networking/telnet.c4
-rw-r--r--networking/traceroute.c40
-rw-r--r--networking/udhcp/socket.c2
10 files changed, 192 insertions, 226 deletions
diff --git a/networking/arping.c b/networking/arping.c
index 58d5b3bd6..55b27872b 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -335,13 +335,12 @@ int arping_main(int argc, char **argv)
saddr.sin_addr = src;
xbind(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr));
} else if (!(cfg & dad)) {
- static const int on = 1;
socklen_t alen = sizeof(saddr);
saddr.sin_port = htons(1025);
saddr.sin_addr = dst;
- if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, (char *) &on, sizeof(on)) == -1)
+ if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1)
bb_perror_msg("warning: setsockopt(SO_DONTROUTE)");
xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr));
if (getsockname(probe_fd, (struct sockaddr *) &saddr, &alen) == -1) {
diff --git a/networking/httpd.c b/networking/httpd.c
index d14b113a3..ea9fe0974 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1764,8 +1764,6 @@ static void handleIncoming(void)
****************************************************************************/
static int miniHttpd(int server)
{
- static const int on = 1;
-
fd_set readfd, portfd;
FD_ZERO(&portfd);
@@ -1812,7 +1810,7 @@ static int miniHttpd(int server)
#endif
/* set the KEEPALIVE option to cull dead connections */
- setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
+ setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
if (DEBUG || fork() == 0) {
/* child */
diff --git a/networking/nc.c b/networking/nc.c
index 09d89b0a8..dc9102b2a 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -43,10 +43,10 @@ int nc_main(int argc, char **argv)
else if (ENABLE_NC_SERVER && opt=='p') {
USE_NC_SERVER(lport = bb_lookup_port(optarg, "tcp", 0));
}
- else if (ENABLE_NC_EXTRA && opt=='w') USE_NC_EXTRA( wsecs = xatou(optarg));
- else if (ENABLE_NC_EXTRA && opt=='i') USE_NC_EXTRA( delay = xatou(optarg));
- else if (ENABLE_NC_EXTRA && opt=='f') USE_NC_EXTRA( cfd = xopen(optarg, O_RDWR));
- else if (ENABLE_NC_EXTRA && opt=='e' && optind<=argc) {
+ else if (ENABLE_NC_EXTRA && opt=='w') USE_NC_EXTRA( wsecs = xatou(optarg));
+ else if (ENABLE_NC_EXTRA && opt=='i') USE_NC_EXTRA( delay = xatou(optarg));
+ else if (ENABLE_NC_EXTRA && opt=='f') USE_NC_EXTRA( cfd = xopen(optarg, O_RDWR));
+ else if (ENABLE_NC_EXTRA && opt=='e' && optind<=argc) {
/* We cannot just 'break'. We should let getopt finish.
** Or else we won't be able to find where
** 'host' and 'port' params are
@@ -91,8 +91,6 @@ int nc_main(int argc, char **argv)
if (!cfd) {
if (do_listen) {
- socklen_t addrlen;
-
/* create_and_bind_stream_or_die(NULL, lport)
* would've work wonderfully, but we need
* to know lsa */
@@ -105,15 +103,14 @@ int nc_main(int argc, char **argv)
/* If we didn't specify a port number,
* query and print it after listen() */
if (!lport) {
- addrlen = lsa->len;
+ socklen_t addrlen = lsa->len;
getsockname(sfd, &lsa->sa, &addrlen);
lport = get_nport(lsa);
fdprintf(2, "%d\n", ntohs(lport));
}
fcntl(sfd, F_SETFD, FD_CLOEXEC);
accept_again:
- addrlen = lsa->len;
- cfd = accept(sfd, NULL, 0); /* &lsa->sa, &addrlen); */
+ cfd = accept(sfd, NULL, 0);
if (cfd < 0)
bb_perror_msg_and_die("accept");
if (!execparam)
diff --git a/networking/netstat.c b/networking/netstat.c
index 3dad57a40..16ee52d9a 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -14,81 +14,70 @@
#include "busybox.h"
#include "inet_common.h"
-#ifdef CONFIG_ROUTE
-extern void displayroutes(int noresolve, int netstatfmt);
-#endif
-
-#define NETSTAT_CONNECTED 0x01
-#define NETSTAT_LISTENING 0x02
-#define NETSTAT_NUMERIC 0x04
+#define NETSTAT_CONNECTED 0x01
+#define NETSTAT_LISTENING 0x02
+#define NETSTAT_NUMERIC 0x04
/* Must match getopt32 option string */
-#define NETSTAT_TCP 0x10
-#define NETSTAT_UDP 0x20
-#define NETSTAT_RAW 0x40
-#define NETSTAT_UNIX 0x80
-#define NETSTAT_ALLPROTO (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW|NETSTAT_UNIX)
+#define NETSTAT_TCP 0x10
+#define NETSTAT_UDP 0x20
+#define NETSTAT_RAW 0x40
+#define NETSTAT_UNIX 0x80
+#define NETSTAT_ALLPROTO (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW|NETSTAT_UNIX)
static int flags = NETSTAT_CONNECTED | NETSTAT_ALLPROTO;
-#define PROGNAME_WIDTHs PROGNAME_WIDTH1(PROGNAME_WIDTH)
-#define PROGNAME_WIDTH1(s) PROGNAME_WIDTH2(s)
-#define PROGNAME_WIDTH2(s) #s
-
-#define PRG_HASH_SIZE 211
-
enum {
- TCP_ESTABLISHED = 1,
- TCP_SYN_SENT,
- TCP_SYN_RECV,
- TCP_FIN_WAIT1,
- TCP_FIN_WAIT2,
- TCP_TIME_WAIT,
- TCP_CLOSE,
- TCP_CLOSE_WAIT,
- TCP_LAST_ACK,
- TCP_LISTEN,
- TCP_CLOSING /* now a valid state */
+ TCP_ESTABLISHED = 1,
+ TCP_SYN_SENT,
+ TCP_SYN_RECV,
+ TCP_FIN_WAIT1,
+ TCP_FIN_WAIT2,
+ TCP_TIME_WAIT,
+ TCP_CLOSE,
+ TCP_CLOSE_WAIT,
+ TCP_LAST_ACK,
+ TCP_LISTEN,
+ TCP_CLOSING /* now a valid state */
};
static const char * const tcp_state[] =
{
- "",
- "ESTABLISHED",
- "SYN_SENT",
- "SYN_RECV",
- "FIN_WAIT1",
- "FIN_WAIT2",
- "TIME_WAIT",
- "CLOSE",
- "CLOSE_WAIT",
- "LAST_ACK",
- "LISTEN",
- "CLOSING"
+ "",
+ "ESTABLISHED",
+ "SYN_SENT",
+ "SYN_RECV",
+ "FIN_WAIT1",
+ "FIN_WAIT2",
+ "TIME_WAIT",
+ "CLOSE",
+ "CLOSE_WAIT",
+ "LAST_ACK",
+ "LISTEN",
+ "CLOSING"
};
typedef enum {
- SS_FREE = 0, /* not allocated */
- SS_UNCONNECTED, /* unconnected to any socket */
- SS_CONNECTING, /* in process of connecting */
- SS_CONNECTED, /* connected to socket */
- SS_DISCONNECTING /* in process of disconnecting */
+ SS_FREE = 0, /* not allocated */
+ SS_UNCONNECTED, /* unconnected to any socket */
+ SS_CONNECTING, /* in process of connecting */
+ SS_CONNECTED, /* connected to socket */
+ SS_DISCONNECTING /* in process of disconnecting */
} socket_state;
-#define SO_ACCEPTCON (1<<16) /* performed a listen */
-#define SO_WAITDATA (1<<17) /* wait data to read */
-#define SO_NOSPACE (1<<18) /* no space to write */
+#define SO_ACCEPTCON (1<<16) /* performed a listen */
+#define SO_WAITDATA (1<<17) /* wait data to read */
+#define SO_NOSPACE (1<<18) /* no space to write */
static char *get_sname(int port, const char *proto, int num)
{
- char *str=itoa(ntohs(port));
- if (num) {
- } else {
- struct servent *se=getservbyport(port,proto);
+ char *str = itoa(ntohs(port));
+ if (!num) {
+ struct servent *se = getservbyport(port, proto);
if (se)
- str=se->s_name;
+ str = se->s_name;
}
if (!port) {
- str="*";
+ str = "*";
}
return str;
}
@@ -97,21 +86,21 @@ static void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int
{
char *port_name;
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
if (addr->sa_family == AF_INET6) {
INET6_rresolve(ip_port, size, (struct sockaddr_in6 *)addr,
- (numeric&NETSTAT_NUMERIC) ? 0x0fff : 0);
+ (numeric & NETSTAT_NUMERIC) ? 0x0fff : 0);
} else
#endif
{
- INET_rresolve(ip_port, size, (struct sockaddr_in *)addr,
- 0x4000 | ((numeric&NETSTAT_NUMERIC) ? 0x0fff : 0),
- 0xffffffff);
+ INET_rresolve(ip_port, size, (struct sockaddr_in *)addr,
+ 0x4000 | ((numeric & NETSTAT_NUMERIC) ? 0x0fff : 0),
+ 0xffffffff);
}
- port_name=get_sname(htons(port), proto, numeric);
+ port_name = get_sname(htons(port), proto, numeric);
if ((strlen(ip_port) + strlen(port_name)) > 22)
ip_port[22 - strlen(port_name)] = '\0';
- ip_port+=strlen(ip_port);
+ ip_port += strlen(ip_port);
strcat(ip_port, ":");
strcat(ip_port, port_name);
}
@@ -122,7 +111,7 @@ static void tcp_do_one(int lnr, const char *line)
const char *state_str;
char more[512];
int num, local_port, rem_port, d, state, timer_run, uid, timeout;
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
struct sockaddr_in6 localaddr, remaddr;
char addr6[INET6_ADDRSTRLEN];
struct in6_addr in6;
@@ -142,7 +131,7 @@ static void tcp_do_one(int lnr, const char *line)
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
if (strlen(local_addr) > 8) {
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
sscanf(local_addr, "%08X%08X%08X%08X",
&in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]);
@@ -170,20 +159,19 @@ static void tcp_do_one(int lnr, const char *line)
return;
}
state_str = tcp_state[state];
- if ((rem_port && (flags&NETSTAT_CONNECTED)) ||
- (!rem_port && (flags&NETSTAT_LISTENING)))
- {
+ if ((rem_port && (flags & NETSTAT_CONNECTED))
+ || (!rem_port && (flags & NETSTAT_LISTENING))
+ ) {
snprint_ip_port(local_addr, sizeof(local_addr),
(struct sockaddr *) &localaddr, local_port,
- "tcp", flags&NETSTAT_NUMERIC);
+ "tcp", flags & NETSTAT_NUMERIC);
snprint_ip_port(rem_addr, sizeof(rem_addr),
(struct sockaddr *) &remaddr, rem_port,
- "tcp", flags&NETSTAT_NUMERIC);
+ "tcp", flags & NETSTAT_NUMERIC);
printf("tcp %6ld %6ld %-23s %-23s %-12s\n",
rxq, txq, local_addr, rem_addr, state_str);
-
}
}
@@ -192,7 +180,7 @@ static void udp_do_one(int lnr, const char *line)
char local_addr[64], rem_addr[64];
char *state_str, more[512];
int num, local_port, rem_port, d, state, timer_run, uid, timeout;
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
struct sockaddr_in6 localaddr, remaddr;
char addr6[INET6_ADDRSTRLEN];
struct in6_addr in6;
@@ -212,7 +200,7 @@ static void udp_do_one(int lnr, const char *line)
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
if (strlen(local_addr) > 8) {
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
/* Demangle what the kernel gives us */
sscanf(local_addr, "%08X%08X%08X%08X",
&in6.s6_addr32[0], &in6.s6_addr32[1],
@@ -254,7 +242,7 @@ static void udp_do_one(int lnr, const char *line)
break;
}
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
# define notnull(A) (((A.sin6_family == AF_INET6) && \
((A.sin6_addr.s6_addr32[0]) || \
(A.sin6_addr.s6_addr32[1]) || \
@@ -265,20 +253,19 @@ static void udp_do_one(int lnr, const char *line)
#else
# define notnull(A) (A.sin_addr.s_addr)
#endif
- if ((notnull(remaddr) && (flags&NETSTAT_CONNECTED)) ||
- (!notnull(remaddr) && (flags&NETSTAT_LISTENING)))
- {
+ if ((notnull(remaddr) && (flags & NETSTAT_CONNECTED))
+ || (!notnull(remaddr) && (flags & NETSTAT_LISTENING))
+ ) {
snprint_ip_port(local_addr, sizeof(local_addr),
(struct sockaddr *) &localaddr, local_port,
- "udp", flags&NETSTAT_NUMERIC);
+ "udp", flags & NETSTAT_NUMERIC);
snprint_ip_port(rem_addr, sizeof(rem_addr),
(struct sockaddr *) &remaddr, rem_port,
- "udp", flags&NETSTAT_NUMERIC);
+ "udp", flags & NETSTAT_NUMERIC);
printf("udp %6ld %6ld %-23s %-23s %-12s\n",
rxq, txq, local_addr, rem_addr, state_str);
-
}
}
@@ -287,7 +274,7 @@ static void raw_do_one(int lnr, const char *line)
char local_addr[64], rem_addr[64];
char *state_str, more[512];
int num, local_port, rem_port, d, state, timer_run, uid, timeout;
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
struct sockaddr_in6 localaddr, remaddr;
char addr6[INET6_ADDRSTRLEN];
struct in6_addr in6;
@@ -307,7 +294,7 @@ static void raw_do_one(int lnr, const char *line)
&txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more);
if (strlen(local_addr) > 8) {
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
sscanf(local_addr, "%08X%08X%08X%08X",
&in6.s6_addr32[0], &in6.s6_addr32[1],
&in6.s6_addr32[2], &in6.s6_addr32[3]);
@@ -334,9 +321,9 @@ static void raw_do_one(int lnr, const char *line)
bb_error_msg("warning, got bogus raw line");
return;
}
- state_str=itoa(state);
+ state_str = itoa(state);
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
# define notnull(A) (((A.sin6_family == AF_INET6) && \
((A.sin6_addr.s6_addr32[0]) || \
(A.sin6_addr.s6_addr32[1]) || \
@@ -347,20 +334,19 @@ static void raw_do_one(int lnr, const char *line)
#else
# define notnull(A) (A.sin_addr.s_addr)
#endif
- if ((notnull(remaddr) && (flags&NETSTAT_CONNECTED)) ||
- (!notnull(remaddr) && (flags&NETSTAT_LISTENING)))
- {
+ if ((notnull(remaddr) && (flags & NETSTAT_CONNECTED))
+ || (!notnull(remaddr) && (flags & NETSTAT_LISTENING))
+ ) {
snprint_ip_port(local_addr, sizeof(local_addr),
(struct sockaddr *) &localaddr, local_port,
- "raw", flags&NETSTAT_NUMERIC);
+ "raw", flags & NETSTAT_NUMERIC);
snprint_ip_port(rem_addr, sizeof(rem_addr),
(struct sockaddr *) &remaddr, rem_port,
- "raw", flags&NETSTAT_NUMERIC);
+ "raw", flags & NETSTAT_NUMERIC);
printf("raw %6ld %6ld %-23s %-23s %-12s\n",
rxq, txq, local_addr, rem_addr, state_str);
-
}
}
@@ -390,12 +376,12 @@ static void unix_do_one(int nr, const char *line)
if (!(has & HAS_INODE))
snprintf(path,sizeof(path),"%d",inode);
- if ((flags&(NETSTAT_LISTENING|NETSTAT_CONNECTED))!=(NETSTAT_LISTENING|NETSTAT_CONNECTED)) {
+ if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) != (NETSTAT_LISTENING|NETSTAT_CONNECTED)) {
if ((state == SS_UNCONNECTED) && (unix_flags & SO_ACCEPTCON)) {
- if (!(flags&NETSTAT_LISTENING))
+ if (!(flags & NETSTAT_LISTENING))
return;
} else {
- if (!(flags&NETSTAT_CONNECTED))
+ if (!(flags & NETSTAT_CONNECTED))
return;
}
}
@@ -502,20 +488,20 @@ static void do_info(const char *file, const char *name, void (*proc)(int, const
procinfo = fopen(file, "r");
if (procinfo == NULL) {
if (errno != ENOENT) {
- perror(file);
+ bb_perror_msg("%s", file);
} else {
bb_error_msg("no support for '%s' on this system", name);
}
- } else {
- do {
- char *buffer = xmalloc_fgets(procinfo);
- if (buffer) {
- (proc)(lnr++, buffer);
- free(buffer);
- }
- } while (!feof(procinfo));
- fclose(procinfo);
+ return;
}
+ do {
+ char *buffer = xmalloc_fgets(procinfo);
+ if (buffer) {
+ (proc)(lnr++, buffer);
+ free(buffer);
+ }
+ } while (!feof(procinfo));
+ fclose(procinfo);
}
/*
@@ -529,12 +515,11 @@ int netstat_main(int argc, char **argv)
OPT_showroute = 0x100,
};
unsigned opt;
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
int inet = 1;
int inet6 = 1;
#else
-# define inet 1
-# define inet6 0
+ enum { inet = 1, inet6 = 0 };
#endif
/* Option string must match NETSTAT_xxx constants */
@@ -551,8 +536,8 @@ int netstat_main(int argc, char **argv)
//if (opt & 0x40) // -w: NETSTAT_RAW
//if (opt & 0x80) // -x: NETSTAT_UNIX
if (opt & OPT_showroute) { // -r
-#ifdef CONFIG_ROUTE
- displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended));
+#if ENABLE_ROUTE
+ bb_displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended));
return 0;
#else
bb_error_msg_and_die("-r (display routing table) is not compiled in");
@@ -567,47 +552,42 @@ int netstat_main(int argc, char **argv)
if (flags & (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW)) {
printf("Active Internet connections "); /* xxx */
- if ((flags&(NETSTAT_LISTENING|NETSTAT_CONNECTED))==(NETSTAT_LISTENING|NETSTAT_CONNECTED))
+ if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) == (NETSTAT_LISTENING|NETSTAT_CONNECTED))
printf("(servers and established)");
- else {
- if (flags & NETSTAT_LISTENING)
- printf("(only servers)");
- else
- printf("(w/o servers)");
- }
+ else if (flags & NETSTAT_LISTENING)
+ printf("(only servers)");
+ else
+ printf("(w/o servers)");
printf("\nProto Recv-Q Send-Q Local Address Foreign Address State\n");
}
- if (inet && flags&NETSTAT_TCP)
- do_info(_PATH_PROCNET_TCP,"AF INET (tcp)",tcp_do_one);
-#ifdef CONFIG_FEATURE_IPV6
- if (inet6 && flags&NETSTAT_TCP)
- do_info(_PATH_PROCNET_TCP6,"AF INET6 (tcp)",tcp_do_one);
+ if (inet && flags & NETSTAT_TCP)
+ do_info(_PATH_PROCNET_TCP, "AF INET (tcp)", tcp_do_one);
+#if ENABLE_FEATURE_IPV6
+ if (inet6 && flags & NETSTAT_TCP)
+ do_info(_PATH_PROCNET_TCP6, "AF INET6 (tcp)", tcp_do_one);
#endif
- if (inet && flags&NETSTAT_UDP)
- do_info(_PATH_PROCNET_UDP,"AF INET (udp)",udp_do_one);
-#ifdef CONFIG_FEATURE_IPV6
- if (inet6 && flags&NETSTAT_UDP)
- do_info(_PATH_PROCNET_UDP6,"AF INET6 (udp)",udp_do_one);
+ if (inet && flags & NETSTAT_UDP)
+ do_info(_PATH_PROCNET_UDP, "AF INET (udp)", udp_do_one);
+#if ENABLE_FEATURE_IPV6
+ if (inet6 && flags & NETSTAT_UDP)
+ do_info(_PATH_PROCNET_UDP6, "AF INET6 (udp)", udp_do_one);
#endif
- if (inet && flags&NETSTAT_RAW)
- do_info(_PATH_PROCNET_RAW,"AF INET (raw)",raw_do_one);
-#ifdef CONFIG_FEATURE_IPV6
- if (inet6 && flags&NETSTAT_RAW)
- do_info(_PATH_PROCNET_RAW6,"AF INET6 (raw)",raw_do_one);
+ if (inet && flags & NETSTAT_RAW)
+ do_info(_PATH_PROCNET_RAW, "AF INET (raw)", raw_do_one);
+#if ENABLE_FEATURE_IPV6
+ if (inet6 && flags & NETSTAT_RAW)
+ do_info(_PATH_PROCNET_RAW6, "AF INET6 (raw)", raw_do_one);
#endif
- if (flags&NETSTAT_UNIX) {
+ if (flags & NETSTAT_UNIX) {
printf("Active UNIX domain sockets ");
- if ((flags&(NETSTAT_LISTENING|NETSTAT_CONNECTED))==(NETSTAT_LISTENING|NETSTAT_CONNECTED))
+ if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) == (NETSTAT_LISTENING|NETSTAT_CONNECTED))
printf("(servers and established)");
- else {
- if (flags&NETSTAT_LISTENING)
- printf("(only servers)");
- else
- printf("(w/o servers)");
- }
-
+ else if (flags & NETSTAT_LISTENING)
+ printf("(only servers)");
+ else
+ printf("(w/o servers)");
printf("\nProto RefCnt Flags Type State I-Node Path\n");
- do_info(_PATH_PROCNET_UNIX,"AF UNIX",unix_do_one);
+ do_info(_PATH_PROCNET_UNIX, "AF UNIX", unix_do_one);
}
return 0;
}
diff --git a/networking/ping.c b/networking/ping.c
index d8a70334d..91708d282 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -343,8 +343,7 @@ static void ping(const char *host)
/* set recv buf for broadcast pings */
sockopt = 48 * 1024; /* explain why 48k? */
- setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
- sizeof(sockopt));
+ setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
printf("PING %s (%s)",
hostent->h_name,
diff --git a/networking/ping6.c b/networking/ping6.c
index dec3b426a..a92387e79 100644
--- a/networking/ping6.c
+++ b/networking/ping6.c
@@ -77,8 +77,7 @@ static void ping(const char *host)
pkt->icmp6_type = ICMP6_ECHO_REQUEST;
sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
- setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, (char *) &sockopt,
- sizeof(sockopt));
+ setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt));
c = sendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), 0,
(struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in6));
@@ -312,6 +311,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit
fflush(stdout);
}
+extern int BUG_bad_offsetof_icmp6_cksum(void);
static void ping(const char *host)
{
char packet[datalen + MAXIPLEN + MAXICMPLEN];
@@ -353,18 +353,15 @@ static void ping(const char *host)
/* set recv buf for broadcast pings */
sockopt = 48 * 1024; /* explain why 48k? */
- setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt,
- sizeof(sockopt));
+ setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));
- sockopt = 2; /* iputils-ss020927 does this */
sockopt = offsetof(struct icmp6_hdr, icmp6_cksum);
- setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, (char *) &sockopt,
- sizeof(sockopt));
+ if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2)
+ BUG_bad_offsetof_icmp6_cksum();
+ setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt));
/* request ttl info to be returned in ancillary data */
- sockopt = 1;
- setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt,
- sizeof(sockopt));
+ setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, &const_int_1, sizeof(const_int_1));
if (if_index)
pingaddr.sin6_scope_id = if_index;
diff --git a/networking/route.c b/networking/route.c
index d6d9b7dd9..c6fb5a371 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -63,14 +63,14 @@
#endif
/* The RTACTION entries must agree with tbl_verb[] below! */
-#define RTACTION_ADD 1
-#define RTACTION_DEL 2
+#define RTACTION_ADD 1
+#define RTACTION_DEL 2
/* For the various tbl_*[] arrays, the 1st byte is the offset to
* the next entry and the 2nd byte is return value. */
-#define NET_FLAG 1
-#define HOST_FLAG 2
+#define NET_FLAG 1
+#define HOST_FLAG 2
/* We remap '-' to '#' to avoid problems with getopt. */
static const char tbl_hash_net_host[] =
@@ -79,22 +79,22 @@ static const char tbl_hash_net_host[] =
"\007\002#host" /* Since last, we can save a byte. */
;
-#define KW_TAKES_ARG 020
-#define KW_SETS_FLAG 040
+#define KW_TAKES_ARG 020
+#define KW_SETS_FLAG 040
-#define KW_IPVx_METRIC 020
-#define KW_IPVx_NETMASK 021
-#define KW_IPVx_GATEWAY 022
-#define KW_IPVx_MSS 023
-#define KW_IPVx_WINDOW 024
-#define KW_IPVx_IRTT 025
-#define KW_IPVx_DEVICE 026
+#define KW_IPVx_METRIC 020
+#define KW_IPVx_NETMASK 021
+#define KW_IPVx_GATEWAY 022
+#define KW_IPVx_MSS 023
+#define KW_IPVx_WINDOW 024
+#define KW_IPVx_IRTT 025
+#define KW_IPVx_DEVICE 026
-#define KW_IPVx_FLAG_ONLY 040
-#define KW_IPVx_REJECT 040
-#define KW_IPVx_MOD 041
-#define KW_IPVx_DYN 042
-#define KW_IPVx_REINSTATE 043
+#define KW_IPVx_FLAG_ONLY 040
+#define KW_IPVx_REJECT 040
+#define KW_IPVx_MOD 041
+#define KW_IPVx_DYN 042
+#define KW_IPVx_REINSTATE 043
static const char tbl_ipvx[] =
/* 020 is the "takes an arg" bit */
@@ -167,7 +167,7 @@ static void INET_setroute(int action, char **args)
}
/* Clean out the RTREQ structure. */
- memset((char *) &rt, 0, sizeof(struct rtentry));
+ memset(&rt, 0, sizeof(rt));
{
const char *target = *args++;
@@ -334,7 +334,7 @@ static void INET_setroute(int action, char **args)
if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
}
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
static void INET6_setroute(int action, char **args)
{
@@ -363,7 +363,7 @@ static void INET6_setroute(int action, char **args)
}
/* Clean out the RTREQ structure. */
- memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
+ memset(&rt, 0, sizeof(rt));
memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr));
@@ -445,7 +445,7 @@ static const unsigned int flagvals[] = { /* Must agree with flagchars[]. */
RTF_REINSTATE,
RTF_DYNAMIC,
RTF_MODIFIED,
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
RTF_DEFAULT,
RTF_ADDRCONF,
RTF_CACHE
@@ -457,7 +457,7 @@ static const unsigned int flagvals[] = { /* Must agree with flagchars[]. */
static const char flagchars[] = /* Must agree with flagvals[]. */
"GHRDM"
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
"DAC"
#endif
;
@@ -476,7 +476,7 @@ static void set_flags(char *flagstr, int flags)
}
/* also used in netstat */
-void displayroutes(int noresolve, int netstatfmt)
+void bb_displayroutes(int noresolve, int netstatfmt)
{
char devname[64], flags[16], sdest[16], sgw[16];
unsigned long int d, g, m;
@@ -537,7 +537,7 @@ void displayroutes(int noresolve, int netstatfmt)
}
}
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
static void INET6_displayroutes(int noresolve)
{
@@ -589,7 +589,7 @@ static void INET6_displayroutes(int noresolve)
goto ERROR;
}
addr6x[i++] = *p++;
- if (!((i+1)%5)) {
+ if (!((i+1) % 5)) {
addr6x[i++] = ':';
}
} while (i < 40+28+7);
@@ -626,10 +626,10 @@ static void INET6_displayroutes(int noresolve)
#endif
-#define ROUTE_OPT_A 0x01
-#define ROUTE_OPT_n 0x02
-#define ROUTE_OPT_e 0x04
-#define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */
+#define ROUTE_OPT_A 0x01
+#define ROUTE_OPT_n 0x02
+#define ROUTE_OPT_e 0x04
+#define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */
/* 1st byte is offset to next entry offset. 2nd byte is return value. */
static const char tbl_verb[] = /* 2nd byte matches RTACTION_* code */
@@ -649,15 +649,15 @@ int route_main(int argc, char **argv)
/* First, remap '-net' and '-host' to avoid getopt problems. */
p = argv;
while (*++p) {
- if ((strcmp(*p, "-net") == 0) || (strcmp(*p, "-host") == 0)) {
+ if (strcmp(*p, "-net") == 0 || strcmp(*p, "-host") == 0) {
p[0][0] = '#';
}
}
opt = getopt32(argc, argv, "A:ne", &family);
- if ((opt & ROUTE_OPT_A) && strcmp(family, "inet")) {
-#ifdef CONFIG_FEATURE_IPV6
+ if ((opt & ROUTE_OPT_A) && strcmp(family, "inet") != 0) {
+#if ENABLE_FEATURE_IPV6
if (strcmp(family, "inet6") == 0) {
opt |= ROUTE_OPT_INET6; /* Set flag for ipv6. */
} else
@@ -670,12 +670,12 @@ int route_main(int argc, char **argv)
/* No more args means display the routing table. */
if (!*argv) {
int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0;
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
if (opt & ROUTE_OPT_INET6)
INET6_displayroutes(noresolve);
else
#endif
- displayroutes(noresolve, opt & ROUTE_OPT_e);
+ bb_displayroutes(noresolve, opt & ROUTE_OPT_e);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
@@ -686,7 +686,7 @@ int route_main(int argc, char **argv)
bb_show_usage();
}
-#ifdef CONFIG_FEATURE_IPV6
+#if ENABLE_FEATURE_IPV6
if (opt & ROUTE_OPT_INET6)
INET6_setroute(what, argv);
else
diff --git a/networking/telnet.c b/networking/telnet.c
index 86586600b..fc70cc406 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -95,8 +95,6 @@ static void telopt(byte c);
static int subneg(byte c);
/* Some globals */
-static const int one = 1;
-
#ifdef CONFIG_FEATURE_TELNET_TTYPE
static char *ttype;
#endif
@@ -630,7 +628,7 @@ int telnet_main(int argc, char** argv)
G.netfd = create_and_connect_stream_or_die(host, port);
- setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);
+ setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));
signal(SIGINT, fgotsig);
diff --git a/networking/traceroute.c b/networking/traceroute.c
index 5eac6cd1e..47775aa8a 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -207,7 +207,6 @@
//#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP
//#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP
-#include "inet_common.h"
#include <net/if.h>
#include <arpa/inet.h>
@@ -217,6 +216,7 @@
#include <netinet/ip_icmp.h>
#include "busybox.h"
+#include "inet_common.h"
/*
@@ -803,7 +803,8 @@ inetname(struct sockaddr_in *from)
char name[257];
if (!nflag && from->sin_addr.s_addr != INADDR_ANY) {
- if (INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0)
+ if (INET_rresolve(name, sizeof(name), from, 0x4000,
+ 0xffffffff) >= 0)
n = name;
}
ina = inet_ntoa(from->sin_addr);
@@ -842,7 +843,7 @@ gethostinfo(const char *host)
hi = xzalloc(sizeof(*hi));
addr = inet_addr(host);
- if ((int32_t)addr != -1) {
+ if (addr != 0xffffffff) {
hi->name = xstrdup(host);
hi->n = 1;
hi->addrs = xzalloc(sizeof(hi->addrs[0]));
@@ -888,8 +889,6 @@ getaddr(uint32_t *ap, const char *host)
int
traceroute_main(int argc, char *argv[])
{
- static const int on = 1;
-
int code, n;
unsigned char *outp;
uint32_t *ap;
@@ -1043,19 +1042,19 @@ traceroute_main(int argc, char *argv[])
/* Insure the socket fds won't be 0, 1 or 2 */
do n = xopen(bb_dev_null, O_RDONLY); while (n < 2);
- if (n > 2)
- close(n);
+ while (n > 2)
+ close(n--);
s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
#if TRACEROUTE_SO_DEBUG
if (op & USAGE_OP_DEBUG)
- (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on,
- sizeof(on));
+ setsockopt(s, SOL_SOCKET, SO_DEBUG,
+ &const_int_1, sizeof(const_int_1));
#endif
if (op & USAGE_OP_BYPASS_ROUTE)
- (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
- sizeof(on));
+ setsockopt(s, SOL_SOCKET, SO_DONTROUTE,
+ &const_int_1, sizeof(const_int_1));
sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
@@ -1087,32 +1086,31 @@ traceroute_main(int argc, char *argv[])
#endif /* CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE */
#ifdef SO_SNDBUF
- if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&packlen,
- sizeof(packlen)) < 0) {
+ if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) < 0) {
bb_perror_msg_and_die("SO_SNDBUF");
}
#endif
#ifdef IP_HDRINCL
- if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on,
- sizeof(on)) < 0 && errno != ENOPROTOOPT) {
+ if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, &const_int_1, sizeof(const_int_1)) < 0
+ && errno != ENOPROTOOPT
+ ) {
bb_perror_msg_and_die("IP_HDRINCL");
}
#else
#ifdef IP_TOS
- if (tos_str && setsockopt(sndsock, IPPROTO_IP, IP_TOS,
- (char *)&tos, sizeof(tos)) < 0) {
+ if (tos_str && setsockopt(sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
bb_perror_msg_and_die("setsockopt tos %d", tos);
}
#endif
#endif
#if TRACEROUTE_SO_DEBUG
if (op & USAGE_OP_DEBUG)
- (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on,
- sizeof(on));
+ setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
+ &const_int_1, sizeof(const_int_1));
#endif
if (op & USAGE_OP_BYPASS_ROUTE)
- (void)setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
- sizeof(on));
+ setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE,
+ &const_int_1, sizeof(const_int_1));
/* Revert to non-privileged user after opening sockets */
xsetgid(getgid());
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 8138f5a86..76ae7172d 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -112,7 +112,7 @@ int listen_socket(uint32_t ip, int port, char *inf)
}
strncpy(interface.ifr_name, inf, IFNAMSIZ);
- if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, sizeof(interface)) < 0) {
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface)) < 0) {
close(fd);
return -1;
}