diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-22 14:12:08 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-22 14:12:08 +0000 |
| commit | 703e20235aa0624d3ff4335c1e86edaa6e21efe2 (patch) | |
| tree | 49e8451efad93b75c0be74ee553d3b3f8c04a25d | |
| parent | 6cd2d2bcba37a13d0d73326dd7bca64bbccce4f8 (diff) | |
| download | busybox-w32-703e20235aa0624d3ff4335c1e86edaa6e21efe2.tar.gz busybox-w32-703e20235aa0624d3ff4335c1e86edaa6e21efe2.tar.bz2 busybox-w32-703e20235aa0624d3ff4335c1e86edaa6e21efe2.zip | |
cleanups: unnecessary casts, unified const_1, eliminate cross-.c file
prototypes (heresy!), add spaces in places like "flags&NETSTAT_CONNECTED",
removed unused #defines, #ifdef -> #if, use uint32_t for ipv4 addrs.
| -rw-r--r-- | include/libbb.h | 6 | ||||
| -rw-r--r-- | libbb/inet_common.c | 51 | ||||
| -rw-r--r-- | libbb/lineedit.c | 4 | ||||
| -rw-r--r-- | libbb/messages.c | 3 | ||||
| -rw-r--r-- | libbb/xconnect.c | 5 | ||||
| -rw-r--r-- | modutils/insmod.c | 2 | ||||
| -rw-r--r-- | networking/arping.c | 3 | ||||
| -rw-r--r-- | networking/httpd.c | 4 | ||||
| -rw-r--r-- | networking/nc.c | 15 | ||||
| -rw-r--r-- | networking/netstat.c | 258 | ||||
| -rw-r--r-- | networking/ping.c | 3 | ||||
| -rw-r--r-- | networking/ping6.c | 17 | ||||
| -rw-r--r-- | networking/route.c | 72 | ||||
| -rw-r--r-- | networking/telnet.c | 4 | ||||
| -rw-r--r-- | networking/traceroute.c | 40 | ||||
| -rw-r--r-- | networking/udhcp/socket.c | 2 | ||||
| -rw-r--r-- | shell/lash.c | 2 |
17 files changed, 231 insertions, 260 deletions
diff --git a/include/libbb.h b/include/libbb.h index c1c9486c4..cd192b9eb 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -486,6 +486,9 @@ extern void bb_vinfo_msg(const char *s, va_list p); | |||
| 486 | extern int bb_cat(char** argv); | 486 | extern int bb_cat(char** argv); |
| 487 | extern int bb_echo(char** argv); | 487 | extern int bb_echo(char** argv); |
| 488 | extern int bb_test(int argc, char** argv); | 488 | extern int bb_test(int argc, char** argv); |
| 489 | #if ENABLE_ROUTE | ||
| 490 | extern void bb_displayroutes(int noresolve, int netstatfmt); | ||
| 491 | #endif | ||
| 489 | 492 | ||
| 490 | 493 | ||
| 491 | /* Networking */ | 494 | /* Networking */ |
| @@ -740,6 +743,9 @@ extern const char bb_path_motd_file[]; | |||
| 740 | extern const char bb_path_wtmp_file[]; | 743 | extern const char bb_path_wtmp_file[]; |
| 741 | extern const char bb_dev_null[]; | 744 | extern const char bb_dev_null[]; |
| 742 | 745 | ||
| 746 | extern const int const_int_0; | ||
| 747 | extern const int const_int_1; | ||
| 748 | |||
| 743 | #ifndef BUFSIZ | 749 | #ifndef BUFSIZ |
| 744 | #define BUFSIZ 4096 | 750 | #define BUFSIZ 4096 |
| 745 | #endif | 751 | #endif |
diff --git a/libbb/inet_common.c b/libbb/inet_common.c index 9cdcb11de..6b31c79f2 100644 --- a/libbb/inet_common.c +++ b/libbb/inet_common.c | |||
| @@ -33,19 +33,23 @@ int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst) | |||
| 33 | /* If we expect this to be a hostname, try hostname database first */ | 33 | /* If we expect this to be a hostname, try hostname database first */ |
| 34 | #ifdef DEBUG | 34 | #ifdef DEBUG |
| 35 | if (hostfirst) { | 35 | if (hostfirst) { |
| 36 | bb_error_msg("gethostbyname (%s)", name); | 36 | bb_error_msg("gethostbyname(%s)", name); |
| 37 | } | 37 | } |
| 38 | #endif | 38 | #endif |
| 39 | if (hostfirst && (hp = gethostbyname(name)) != (struct hostent *) NULL) { | 39 | if (hostfirst) { |
| 40 | memcpy((char *) &s_in->sin_addr, (char *) hp->h_addr_list[0], | 40 | hp = gethostbyname(name); |
| 41 | sizeof(struct in_addr)); | 41 | if (hp != NULL) { |
| 42 | return 0; | 42 | memcpy(&s_in->sin_addr, hp->h_addr_list[0], |
| 43 | sizeof(struct in_addr)); | ||
| 44 | return 0; | ||
| 45 | } | ||
| 43 | } | 46 | } |
| 44 | /* Try the NETWORKS database to see if this is a known network. */ | 47 | /* Try the NETWORKS database to see if this is a known network. */ |
| 45 | #ifdef DEBUG | 48 | #ifdef DEBUG |
| 46 | bb_error_msg("getnetbyname (%s)", name); | 49 | bb_error_msg("getnetbyname(%s)", name); |
| 47 | #endif | 50 | #endif |
| 48 | if ((np = getnetbyname(name)) != (struct netent *) NULL) { | 51 | np = getnetbyname(name); |
| 52 | if (np != NULL) { | ||
| 49 | s_in->sin_addr.s_addr = htonl(np->n_net); | 53 | s_in->sin_addr.s_addr = htonl(np->n_net); |
| 50 | return 1; | 54 | return 1; |
| 51 | } | 55 | } |
| @@ -59,14 +63,13 @@ int INET_resolve(const char *name, struct sockaddr_in *s_in, int hostfirst) | |||
| 59 | #endif | 63 | #endif |
| 60 | 64 | ||
| 61 | #ifdef DEBUG | 65 | #ifdef DEBUG |
| 62 | bb_error_msg("gethostbyname (%s)", name); | 66 | bb_error_msg("gethostbyname(%s)", name); |
| 63 | #endif | 67 | #endif |
| 64 | if ((hp = gethostbyname(name)) == (struct hostent *) NULL) { | 68 | hp = gethostbyname(name); |
| 69 | if (hp == NULL) { | ||
| 65 | return -1; | 70 | return -1; |
| 66 | } | 71 | } |
| 67 | memcpy((char *) &s_in->sin_addr, (char *) hp->h_addr_list[0], | 72 | memcpy(&s_in->sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); |
| 68 | sizeof(struct in_addr)); | ||
| 69 | |||
| 70 | return 0; | 73 | return 0; |
| 71 | } | 74 | } |
| 72 | 75 | ||
| @@ -78,7 +81,7 @@ struct addr { | |||
| 78 | struct addr *next; | 81 | struct addr *next; |
| 79 | }; | 82 | }; |
| 80 | 83 | ||
| 81 | static struct addr *INET_nn = NULL; /* addr-to-name cache */ | 84 | static struct addr *INET_nn = NULL; /* addr-to-name cache */ |
| 82 | 85 | ||
| 83 | /* numeric: & 0x8000: default instead of *, | 86 | /* numeric: & 0x8000: default instead of *, |
| 84 | * & 0x4000: host instead of net, | 87 | * & 0x4000: host instead of net, |
| @@ -90,7 +93,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, | |||
| 90 | struct hostent *ent; | 93 | struct hostent *ent; |
| 91 | struct netent *np; | 94 | struct netent *np; |
| 92 | struct addr *pn; | 95 | struct addr *pn; |
| 93 | unsigned long ad, host_ad; | 96 | uint32_t ad, host_ad; |
| 94 | int host = 0; | 97 | int host = 0; |
| 95 | 98 | ||
| 96 | /* Grmpf. -FvK */ | 99 | /* Grmpf. -FvK */ |
| @@ -102,9 +105,9 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, | |||
| 102 | errno = EAFNOSUPPORT; | 105 | errno = EAFNOSUPPORT; |
| 103 | return -1; | 106 | return -1; |
| 104 | } | 107 | } |
| 105 | ad = (unsigned long) s_in->sin_addr.s_addr; | 108 | ad = s_in->sin_addr.s_addr; |
| 106 | #ifdef DEBUG | 109 | #ifdef DEBUG |
| 107 | bb_error_msg("rresolve: %08lx, mask %08x, num %08x", ad, netmask, numeric); | 110 | bb_error_msg("rresolve: %08x, mask %08x, num %08x", (unsigned)ad, netmask, numeric); |
| 108 | #endif | 111 | #endif |
| 109 | if (ad == INADDR_ANY) { | 112 | if (ad == INADDR_ANY) { |
| 110 | if ((numeric & 0x0FFF) == 0) { | 113 | if ((numeric & 0x0FFF) == 0) { |
| @@ -127,8 +130,8 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, | |||
| 127 | if (pn->addr.sin_addr.s_addr == ad && pn->host == host) { | 130 | if (pn->addr.sin_addr.s_addr == ad && pn->host == host) { |
| 128 | safe_strncpy(name, pn->name, len); | 131 | safe_strncpy(name, pn->name, len); |
| 129 | #ifdef DEBUG | 132 | #ifdef DEBUG |
| 130 | bb_error_msg("rresolve: found %s %08lx in cache", | 133 | bb_error_msg("rresolve: found %s %08x in cache", |
| 131 | (host ? "host" : "net"), ad); | 134 | (host ? "host" : "net"), (unsigned)ad); |
| 132 | #endif | 135 | #endif |
| 133 | return 0; | 136 | return 0; |
| 134 | } | 137 | } |
| @@ -140,7 +143,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, | |||
| 140 | ent = NULL; | 143 | ent = NULL; |
| 141 | if (host) { | 144 | if (host) { |
| 142 | #ifdef DEBUG | 145 | #ifdef DEBUG |
| 143 | bb_error_msg("gethostbyaddr (%08lx)", ad); | 146 | bb_error_msg("gethostbyaddr (%08x)", (unsigned)ad); |
| 144 | #endif | 147 | #endif |
| 145 | ent = gethostbyaddr((char *) &ad, 4, AF_INET); | 148 | ent = gethostbyaddr((char *) &ad, 4, AF_INET); |
| 146 | if (ent != NULL) { | 149 | if (ent != NULL) { |
| @@ -148,14 +151,14 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, | |||
| 148 | } | 151 | } |
| 149 | } else { | 152 | } else { |
| 150 | #ifdef DEBUG | 153 | #ifdef DEBUG |
| 151 | bb_error_msg("getnetbyaddr (%08lx)", host_ad); | 154 | bb_error_msg("getnetbyaddr (%08x)", (unsigned)host_ad); |
| 152 | #endif | 155 | #endif |
| 153 | np = getnetbyaddr(host_ad, AF_INET); | 156 | np = getnetbyaddr(host_ad, AF_INET); |
| 154 | if (np != NULL) { | 157 | if (np != NULL) { |
| 155 | safe_strncpy(name, np->n_name, len); | 158 | safe_strncpy(name, np->n_name, len); |
| 156 | } | 159 | } |
| 157 | } | 160 | } |
| 158 | if ((ent == NULL) && (np == NULL)) { | 161 | if (!ent && !np) { |
| 159 | safe_strncpy(name, inet_ntoa(s_in->sin_addr), len); | 162 | safe_strncpy(name, inet_ntoa(s_in->sin_addr), len); |
| 160 | } | 163 | } |
| 161 | pn = xmalloc(sizeof(struct addr)); | 164 | pn = xmalloc(sizeof(struct addr)); |
| @@ -164,7 +167,6 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in, | |||
| 164 | pn->host = host; | 167 | pn->host = host; |
| 165 | pn->name = xstrdup(name); | 168 | pn->name = xstrdup(name); |
| 166 | INET_nn = pn; | 169 | INET_nn = pn; |
| 167 | |||
| 168 | return 0; | 170 | return 0; |
| 169 | } | 171 | } |
| 170 | 172 | ||
| @@ -183,9 +185,7 @@ int INET6_resolve(const char *name, struct sockaddr_in6 *sin6) | |||
| 183 | return -1; | 185 | return -1; |
| 184 | } | 186 | } |
| 185 | memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); | 187 | memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); |
| 186 | |||
| 187 | freeaddrinfo(ai); | 188 | freeaddrinfo(ai); |
| 188 | |||
| 189 | return 0; | 189 | return 0; |
| 190 | } | 190 | } |
| 191 | 191 | ||
| @@ -224,7 +224,8 @@ int INET6_rresolve(char *name, size_t len, struct sockaddr_in6 *sin6, | |||
| 224 | return 0; | 224 | return 0; |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), name, len, NULL, 0, 0); | 227 | s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), |
| 228 | name, len, NULL, 0, 0); | ||
| 228 | if (s) { | 229 | if (s) { |
| 229 | bb_error_msg("getnameinfo failed"); | 230 | bb_error_msg("getnameinfo failed"); |
| 230 | return -1; | 231 | return -1; |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 2c849eb74..08dab26f0 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -1254,8 +1254,6 @@ static void win_changed(int nsig) | |||
| 1254 | 1254 | ||
| 1255 | int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *st) | 1255 | int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *st) |
| 1256 | { | 1256 | { |
| 1257 | static const int null_flags; | ||
| 1258 | |||
| 1259 | int lastWasTab = FALSE; | 1257 | int lastWasTab = FALSE; |
| 1260 | unsigned int ic; | 1258 | unsigned int ic; |
| 1261 | unsigned char c; | 1259 | unsigned char c; |
| @@ -1270,7 +1268,7 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t | |||
| 1270 | maxsize = BUFSIZ; | 1268 | maxsize = BUFSIZ; |
| 1271 | 1269 | ||
| 1272 | /* With null flags, no other fields are ever used */ | 1270 | /* With null flags, no other fields are ever used */ |
| 1273 | state = st ? st : (line_input_t*) &null_flags; | 1271 | state = st ? st : (line_input_t*) &const_int_0; |
| 1274 | if (state->flags & SAVE_HISTORY) | 1272 | if (state->flags & SAVE_HISTORY) |
| 1275 | load_history(state->hist_file); | 1273 | load_history(state->hist_file); |
| 1276 | 1274 | ||
diff --git a/libbb/messages.c b/libbb/messages.c index 6c3d2f608..105e4ce66 100644 --- a/libbb/messages.c +++ b/libbb/messages.c | |||
| @@ -40,6 +40,9 @@ const char bb_path_motd_file[] = "/etc/motd"; | |||
| 40 | const char bb_default_login_shell[] = LIBBB_DEFAULT_LOGIN_SHELL; | 40 | const char bb_default_login_shell[] = LIBBB_DEFAULT_LOGIN_SHELL; |
| 41 | const char bb_dev_null[] = "/dev/null"; | 41 | const char bb_dev_null[] = "/dev/null"; |
| 42 | 42 | ||
| 43 | const int const_int_0; | ||
| 44 | const int const_int_1 = 1; | ||
| 45 | |||
| 43 | #include <utmp.h> | 46 | #include <utmp.h> |
| 44 | /* This is usually something like "/var/adm/wtmp" or "/var/log/wtmp" */ | 47 | /* This is usually something like "/var/adm/wtmp" or "/var/log/wtmp" */ |
| 45 | const char bb_path_wtmp_file[] = | 48 | const char bb_path_wtmp_file[] = |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index 62cab95a1..0addda157 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
| @@ -9,14 +9,13 @@ | |||
| 9 | #include <netinet/in.h> | 9 | #include <netinet/in.h> |
| 10 | #include "libbb.h" | 10 | #include "libbb.h" |
| 11 | 11 | ||
| 12 | static const int one = 1; | ||
| 13 | int setsockopt_reuseaddr(int fd) | 12 | int setsockopt_reuseaddr(int fd) |
| 14 | { | 13 | { |
| 15 | return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); | 14 | return setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_1, sizeof(const_int_1)); |
| 16 | } | 15 | } |
| 17 | int setsockopt_broadcast(int fd) | 16 | int setsockopt_broadcast(int fd) |
| 18 | { | 17 | { |
| 19 | return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one)); | 18 | return setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &const_int_1, sizeof(const_int_1)); |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) | 21 | void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen) |
diff --git a/modutils/insmod.c b/modutils/insmod.c index a9bf1854c..1ad3c23a4 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
| @@ -337,7 +337,6 @@ extern int insmod_ng_main( int argc, char **argv); | |||
| 337 | 337 | ||
| 338 | 338 | ||
| 339 | #ifndef MODUTILS_MODULE_H | 339 | #ifndef MODUTILS_MODULE_H |
| 340 | /* Why? static const int MODUTILS_MODULE_H = 1;*/ | ||
| 341 | 340 | ||
| 342 | /*======================================================================*/ | 341 | /*======================================================================*/ |
| 343 | /* For sizeof() which are related to the module platform and not to the | 342 | /* For sizeof() which are related to the module platform and not to the |
| @@ -494,7 +493,6 @@ int delete_module(const char *); | |||
| 494 | 493 | ||
| 495 | 494 | ||
| 496 | #ifndef MODUTILS_OBJ_H | 495 | #ifndef MODUTILS_OBJ_H |
| 497 | /* Why? static const int MODUTILS_OBJ_H = 1; */ | ||
| 498 | 496 | ||
| 499 | /* The relocatable object is manipulated using elfin types. */ | 497 | /* The relocatable object is manipulated using elfin types. */ |
| 500 | 498 | ||
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) | |||
| 335 | saddr.sin_addr = src; | 335 | saddr.sin_addr = src; |
| 336 | xbind(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); | 336 | xbind(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); |
| 337 | } else if (!(cfg & dad)) { | 337 | } else if (!(cfg & dad)) { |
| 338 | static const int on = 1; | ||
| 339 | socklen_t alen = sizeof(saddr); | 338 | socklen_t alen = sizeof(saddr); |
| 340 | 339 | ||
| 341 | saddr.sin_port = htons(1025); | 340 | saddr.sin_port = htons(1025); |
| 342 | saddr.sin_addr = dst; | 341 | saddr.sin_addr = dst; |
| 343 | 342 | ||
| 344 | if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, (char *) &on, sizeof(on)) == -1) | 343 | if (setsockopt(probe_fd, SOL_SOCKET, SO_DONTROUTE, &const_int_1, sizeof(const_int_1)) == -1) |
| 345 | bb_perror_msg("warning: setsockopt(SO_DONTROUTE)"); | 344 | bb_perror_msg("warning: setsockopt(SO_DONTROUTE)"); |
| 346 | xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); | 345 | xconnect(probe_fd, (struct sockaddr *) &saddr, sizeof(saddr)); |
| 347 | if (getsockname(probe_fd, (struct sockaddr *) &saddr, &alen) == -1) { | 346 | 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) | |||
| 1764 | ****************************************************************************/ | 1764 | ****************************************************************************/ |
| 1765 | static int miniHttpd(int server) | 1765 | static int miniHttpd(int server) |
| 1766 | { | 1766 | { |
| 1767 | static const int on = 1; | ||
| 1768 | |||
| 1769 | fd_set readfd, portfd; | 1767 | fd_set readfd, portfd; |
| 1770 | 1768 | ||
| 1771 | FD_ZERO(&portfd); | 1769 | FD_ZERO(&portfd); |
| @@ -1812,7 +1810,7 @@ static int miniHttpd(int server) | |||
| 1812 | #endif | 1810 | #endif |
| 1813 | 1811 | ||
| 1814 | /* set the KEEPALIVE option to cull dead connections */ | 1812 | /* set the KEEPALIVE option to cull dead connections */ |
| 1815 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); | 1813 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); |
| 1816 | 1814 | ||
| 1817 | if (DEBUG || fork() == 0) { | 1815 | if (DEBUG || fork() == 0) { |
| 1818 | /* child */ | 1816 | /* 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) | |||
| 43 | else if (ENABLE_NC_SERVER && opt=='p') { | 43 | else if (ENABLE_NC_SERVER && opt=='p') { |
| 44 | USE_NC_SERVER(lport = bb_lookup_port(optarg, "tcp", 0)); | 44 | USE_NC_SERVER(lport = bb_lookup_port(optarg, "tcp", 0)); |
| 45 | } | 45 | } |
| 46 | else if (ENABLE_NC_EXTRA && opt=='w') USE_NC_EXTRA( wsecs = xatou(optarg)); | 46 | else if (ENABLE_NC_EXTRA && opt=='w') USE_NC_EXTRA( wsecs = xatou(optarg)); |
| 47 | else if (ENABLE_NC_EXTRA && opt=='i') USE_NC_EXTRA( delay = xatou(optarg)); | 47 | else if (ENABLE_NC_EXTRA && opt=='i') USE_NC_EXTRA( delay = xatou(optarg)); |
| 48 | else if (ENABLE_NC_EXTRA && opt=='f') USE_NC_EXTRA( cfd = xopen(optarg, O_RDWR)); | 48 | else if (ENABLE_NC_EXTRA && opt=='f') USE_NC_EXTRA( cfd = xopen(optarg, O_RDWR)); |
| 49 | else if (ENABLE_NC_EXTRA && opt=='e' && optind<=argc) { | 49 | else if (ENABLE_NC_EXTRA && opt=='e' && optind<=argc) { |
| 50 | /* We cannot just 'break'. We should let getopt finish. | 50 | /* We cannot just 'break'. We should let getopt finish. |
| 51 | ** Or else we won't be able to find where | 51 | ** Or else we won't be able to find where |
| 52 | ** 'host' and 'port' params are | 52 | ** 'host' and 'port' params are |
| @@ -91,8 +91,6 @@ int nc_main(int argc, char **argv) | |||
| 91 | 91 | ||
| 92 | if (!cfd) { | 92 | if (!cfd) { |
| 93 | if (do_listen) { | 93 | if (do_listen) { |
| 94 | socklen_t addrlen; | ||
| 95 | |||
| 96 | /* create_and_bind_stream_or_die(NULL, lport) | 94 | /* create_and_bind_stream_or_die(NULL, lport) |
| 97 | * would've work wonderfully, but we need | 95 | * would've work wonderfully, but we need |
| 98 | * to know lsa */ | 96 | * to know lsa */ |
| @@ -105,15 +103,14 @@ int nc_main(int argc, char **argv) | |||
| 105 | /* If we didn't specify a port number, | 103 | /* If we didn't specify a port number, |
| 106 | * query and print it after listen() */ | 104 | * query and print it after listen() */ |
| 107 | if (!lport) { | 105 | if (!lport) { |
| 108 | addrlen = lsa->len; | 106 | socklen_t addrlen = lsa->len; |
| 109 | getsockname(sfd, &lsa->sa, &addrlen); | 107 | getsockname(sfd, &lsa->sa, &addrlen); |
| 110 | lport = get_nport(lsa); | 108 | lport = get_nport(lsa); |
| 111 | fdprintf(2, "%d\n", ntohs(lport)); | 109 | fdprintf(2, "%d\n", ntohs(lport)); |
| 112 | } | 110 | } |
| 113 | fcntl(sfd, F_SETFD, FD_CLOEXEC); | 111 | fcntl(sfd, F_SETFD, FD_CLOEXEC); |
| 114 | accept_again: | 112 | accept_again: |
| 115 | addrlen = lsa->len; | 113 | cfd = accept(sfd, NULL, 0); |
| 116 | cfd = accept(sfd, NULL, 0); /* &lsa->sa, &addrlen); */ | ||
| 117 | if (cfd < 0) | 114 | if (cfd < 0) |
| 118 | bb_perror_msg_and_die("accept"); | 115 | bb_perror_msg_and_die("accept"); |
| 119 | if (!execparam) | 116 | 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 @@ | |||
| 14 | #include "busybox.h" | 14 | #include "busybox.h" |
| 15 | #include "inet_common.h" | 15 | #include "inet_common.h" |
| 16 | 16 | ||
| 17 | #ifdef CONFIG_ROUTE | 17 | #define NETSTAT_CONNECTED 0x01 |
| 18 | extern void displayroutes(int noresolve, int netstatfmt); | 18 | #define NETSTAT_LISTENING 0x02 |
| 19 | #endif | 19 | #define NETSTAT_NUMERIC 0x04 |
| 20 | |||
| 21 | #define NETSTAT_CONNECTED 0x01 | ||
| 22 | #define NETSTAT_LISTENING 0x02 | ||
| 23 | #define NETSTAT_NUMERIC 0x04 | ||
| 24 | /* Must match getopt32 option string */ | 20 | /* Must match getopt32 option string */ |
| 25 | #define NETSTAT_TCP 0x10 | 21 | #define NETSTAT_TCP 0x10 |
| 26 | #define NETSTAT_UDP 0x20 | 22 | #define NETSTAT_UDP 0x20 |
| 27 | #define NETSTAT_RAW 0x40 | 23 | #define NETSTAT_RAW 0x40 |
| 28 | #define NETSTAT_UNIX 0x80 | 24 | #define NETSTAT_UNIX 0x80 |
| 29 | #define NETSTAT_ALLPROTO (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW|NETSTAT_UNIX) | 25 | #define NETSTAT_ALLPROTO (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW|NETSTAT_UNIX) |
| 30 | 26 | ||
| 31 | static int flags = NETSTAT_CONNECTED | NETSTAT_ALLPROTO; | 27 | static int flags = NETSTAT_CONNECTED | NETSTAT_ALLPROTO; |
| 32 | 28 | ||
| 33 | #define PROGNAME_WIDTHs PROGNAME_WIDTH1(PROGNAME_WIDTH) | ||
| 34 | #define PROGNAME_WIDTH1(s) PROGNAME_WIDTH2(s) | ||
| 35 | #define PROGNAME_WIDTH2(s) #s | ||
| 36 | |||
| 37 | #define PRG_HASH_SIZE 211 | ||
| 38 | |||
| 39 | enum { | 29 | enum { |
| 40 | TCP_ESTABLISHED = 1, | 30 | TCP_ESTABLISHED = 1, |
| 41 | TCP_SYN_SENT, | 31 | TCP_SYN_SENT, |
| 42 | TCP_SYN_RECV, | 32 | TCP_SYN_RECV, |
| 43 | TCP_FIN_WAIT1, | 33 | TCP_FIN_WAIT1, |
| 44 | TCP_FIN_WAIT2, | 34 | TCP_FIN_WAIT2, |
| 45 | TCP_TIME_WAIT, | 35 | TCP_TIME_WAIT, |
| 46 | TCP_CLOSE, | 36 | TCP_CLOSE, |
| 47 | TCP_CLOSE_WAIT, | 37 | TCP_CLOSE_WAIT, |
| 48 | TCP_LAST_ACK, | 38 | TCP_LAST_ACK, |
| 49 | TCP_LISTEN, | 39 | TCP_LISTEN, |
| 50 | TCP_CLOSING /* now a valid state */ | 40 | TCP_CLOSING /* now a valid state */ |
| 51 | }; | 41 | }; |
| 52 | 42 | ||
| 53 | static const char * const tcp_state[] = | 43 | static const char * const tcp_state[] = |
| 54 | { | 44 | { |
| 55 | "", | 45 | "", |
| 56 | "ESTABLISHED", | 46 | "ESTABLISHED", |
| 57 | "SYN_SENT", | 47 | "SYN_SENT", |
| 58 | "SYN_RECV", | 48 | "SYN_RECV", |
| 59 | "FIN_WAIT1", | 49 | "FIN_WAIT1", |
| 60 | "FIN_WAIT2", | 50 | "FIN_WAIT2", |
| 61 | "TIME_WAIT", | 51 | "TIME_WAIT", |
| 62 | "CLOSE", | 52 | "CLOSE", |
| 63 | "CLOSE_WAIT", | 53 | "CLOSE_WAIT", |
| 64 | "LAST_ACK", | 54 | "LAST_ACK", |
| 65 | "LISTEN", | 55 | "LISTEN", |
| 66 | "CLOSING" | 56 | "CLOSING" |
| 67 | }; | 57 | }; |
| 68 | 58 | ||
| 69 | typedef enum { | 59 | typedef enum { |
| 70 | SS_FREE = 0, /* not allocated */ | 60 | SS_FREE = 0, /* not allocated */ |
| 71 | SS_UNCONNECTED, /* unconnected to any socket */ | 61 | SS_UNCONNECTED, /* unconnected to any socket */ |
| 72 | SS_CONNECTING, /* in process of connecting */ | 62 | SS_CONNECTING, /* in process of connecting */ |
| 73 | SS_CONNECTED, /* connected to socket */ | 63 | SS_CONNECTED, /* connected to socket */ |
| 74 | SS_DISCONNECTING /* in process of disconnecting */ | 64 | SS_DISCONNECTING /* in process of disconnecting */ |
| 75 | } socket_state; | 65 | } socket_state; |
| 76 | 66 | ||
| 77 | #define SO_ACCEPTCON (1<<16) /* performed a listen */ | 67 | #define SO_ACCEPTCON (1<<16) /* performed a listen */ |
| 78 | #define SO_WAITDATA (1<<17) /* wait data to read */ | 68 | #define SO_WAITDATA (1<<17) /* wait data to read */ |
| 79 | #define SO_NOSPACE (1<<18) /* no space to write */ | 69 | #define SO_NOSPACE (1<<18) /* no space to write */ |
| 80 | 70 | ||
| 81 | static char *get_sname(int port, const char *proto, int num) | 71 | static char *get_sname(int port, const char *proto, int num) |
| 82 | { | 72 | { |
| 83 | char *str=itoa(ntohs(port)); | 73 | char *str = itoa(ntohs(port)); |
| 84 | if (num) { | 74 | if (!num) { |
| 85 | } else { | 75 | struct servent *se = getservbyport(port, proto); |
| 86 | struct servent *se=getservbyport(port,proto); | ||
| 87 | if (se) | 76 | if (se) |
| 88 | str=se->s_name; | 77 | str = se->s_name; |
| 89 | } | 78 | } |
| 90 | if (!port) { | 79 | if (!port) { |
| 91 | str="*"; | 80 | str = "*"; |
| 92 | } | 81 | } |
| 93 | return str; | 82 | return str; |
| 94 | } | 83 | } |
| @@ -97,21 +86,21 @@ static void snprint_ip_port(char *ip_port, int size, struct sockaddr *addr, int | |||
| 97 | { | 86 | { |
| 98 | char *port_name; | 87 | char *port_name; |
| 99 | 88 | ||
| 100 | #ifdef CONFIG_FEATURE_IPV6 | 89 | #if ENABLE_FEATURE_IPV6 |
| 101 | if (addr->sa_family == AF_INET6) { | 90 | if (addr->sa_family == AF_INET6) { |
| 102 | INET6_rresolve(ip_port, size, (struct sockaddr_in6 *)addr, | 91 | INET6_rresolve(ip_port, size, (struct sockaddr_in6 *)addr, |
| 103 | (numeric&NETSTAT_NUMERIC) ? 0x0fff : 0); | 92 | (numeric & NETSTAT_NUMERIC) ? 0x0fff : 0); |
| 104 | } else | 93 | } else |
| 105 | #endif | 94 | #endif |
| 106 | { | 95 | { |
| 107 | INET_rresolve(ip_port, size, (struct sockaddr_in *)addr, | 96 | INET_rresolve(ip_port, size, (struct sockaddr_in *)addr, |
| 108 | 0x4000 | ((numeric&NETSTAT_NUMERIC) ? 0x0fff : 0), | 97 | 0x4000 | ((numeric & NETSTAT_NUMERIC) ? 0x0fff : 0), |
| 109 | 0xffffffff); | 98 | 0xffffffff); |
| 110 | } | 99 | } |
| 111 | port_name=get_sname(htons(port), proto, numeric); | 100 | port_name = get_sname(htons(port), proto, numeric); |
| 112 | if ((strlen(ip_port) + strlen(port_name)) > 22) | 101 | if ((strlen(ip_port) + strlen(port_name)) > 22) |
| 113 | ip_port[22 - strlen(port_name)] = '\0'; | 102 | ip_port[22 - strlen(port_name)] = '\0'; |
| 114 | ip_port+=strlen(ip_port); | 103 | ip_port += strlen(ip_port); |
| 115 | strcat(ip_port, ":"); | 104 | strcat(ip_port, ":"); |
| 116 | strcat(ip_port, port_name); | 105 | strcat(ip_port, port_name); |
| 117 | } | 106 | } |
| @@ -122,7 +111,7 @@ static void tcp_do_one(int lnr, const char *line) | |||
| 122 | const char *state_str; | 111 | const char *state_str; |
| 123 | char more[512]; | 112 | char more[512]; |
| 124 | int num, local_port, rem_port, d, state, timer_run, uid, timeout; | 113 | int num, local_port, rem_port, d, state, timer_run, uid, timeout; |
| 125 | #ifdef CONFIG_FEATURE_IPV6 | 114 | #if ENABLE_FEATURE_IPV6 |
| 126 | struct sockaddr_in6 localaddr, remaddr; | 115 | struct sockaddr_in6 localaddr, remaddr; |
| 127 | char addr6[INET6_ADDRSTRLEN]; | 116 | char addr6[INET6_ADDRSTRLEN]; |
| 128 | struct in6_addr in6; | 117 | struct in6_addr in6; |
| @@ -142,7 +131,7 @@ static void tcp_do_one(int lnr, const char *line) | |||
| 142 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); | 131 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); |
| 143 | 132 | ||
| 144 | if (strlen(local_addr) > 8) { | 133 | if (strlen(local_addr) > 8) { |
| 145 | #ifdef CONFIG_FEATURE_IPV6 | 134 | #if ENABLE_FEATURE_IPV6 |
| 146 | sscanf(local_addr, "%08X%08X%08X%08X", | 135 | sscanf(local_addr, "%08X%08X%08X%08X", |
| 147 | &in6.s6_addr32[0], &in6.s6_addr32[1], | 136 | &in6.s6_addr32[0], &in6.s6_addr32[1], |
| 148 | &in6.s6_addr32[2], &in6.s6_addr32[3]); | 137 | &in6.s6_addr32[2], &in6.s6_addr32[3]); |
| @@ -170,20 +159,19 @@ static void tcp_do_one(int lnr, const char *line) | |||
| 170 | return; | 159 | return; |
| 171 | } | 160 | } |
| 172 | state_str = tcp_state[state]; | 161 | state_str = tcp_state[state]; |
| 173 | if ((rem_port && (flags&NETSTAT_CONNECTED)) || | 162 | if ((rem_port && (flags & NETSTAT_CONNECTED)) |
| 174 | (!rem_port && (flags&NETSTAT_LISTENING))) | 163 | || (!rem_port && (flags & NETSTAT_LISTENING)) |
| 175 | { | 164 | ) { |
| 176 | snprint_ip_port(local_addr, sizeof(local_addr), | 165 | snprint_ip_port(local_addr, sizeof(local_addr), |
| 177 | (struct sockaddr *) &localaddr, local_port, | 166 | (struct sockaddr *) &localaddr, local_port, |
| 178 | "tcp", flags&NETSTAT_NUMERIC); | 167 | "tcp", flags & NETSTAT_NUMERIC); |
| 179 | 168 | ||
| 180 | snprint_ip_port(rem_addr, sizeof(rem_addr), | 169 | snprint_ip_port(rem_addr, sizeof(rem_addr), |
| 181 | (struct sockaddr *) &remaddr, rem_port, | 170 | (struct sockaddr *) &remaddr, rem_port, |
| 182 | "tcp", flags&NETSTAT_NUMERIC); | 171 | "tcp", flags & NETSTAT_NUMERIC); |
| 183 | 172 | ||
| 184 | printf("tcp %6ld %6ld %-23s %-23s %-12s\n", | 173 | printf("tcp %6ld %6ld %-23s %-23s %-12s\n", |
| 185 | rxq, txq, local_addr, rem_addr, state_str); | 174 | rxq, txq, local_addr, rem_addr, state_str); |
| 186 | |||
| 187 | } | 175 | } |
| 188 | } | 176 | } |
| 189 | 177 | ||
| @@ -192,7 +180,7 @@ static void udp_do_one(int lnr, const char *line) | |||
| 192 | char local_addr[64], rem_addr[64]; | 180 | char local_addr[64], rem_addr[64]; |
| 193 | char *state_str, more[512]; | 181 | char *state_str, more[512]; |
| 194 | int num, local_port, rem_port, d, state, timer_run, uid, timeout; | 182 | int num, local_port, rem_port, d, state, timer_run, uid, timeout; |
| 195 | #ifdef CONFIG_FEATURE_IPV6 | 183 | #if ENABLE_FEATURE_IPV6 |
| 196 | struct sockaddr_in6 localaddr, remaddr; | 184 | struct sockaddr_in6 localaddr, remaddr; |
| 197 | char addr6[INET6_ADDRSTRLEN]; | 185 | char addr6[INET6_ADDRSTRLEN]; |
| 198 | struct in6_addr in6; | 186 | struct in6_addr in6; |
| @@ -212,7 +200,7 @@ static void udp_do_one(int lnr, const char *line) | |||
| 212 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); | 200 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); |
| 213 | 201 | ||
| 214 | if (strlen(local_addr) > 8) { | 202 | if (strlen(local_addr) > 8) { |
| 215 | #ifdef CONFIG_FEATURE_IPV6 | 203 | #if ENABLE_FEATURE_IPV6 |
| 216 | /* Demangle what the kernel gives us */ | 204 | /* Demangle what the kernel gives us */ |
| 217 | sscanf(local_addr, "%08X%08X%08X%08X", | 205 | sscanf(local_addr, "%08X%08X%08X%08X", |
| 218 | &in6.s6_addr32[0], &in6.s6_addr32[1], | 206 | &in6.s6_addr32[0], &in6.s6_addr32[1], |
| @@ -254,7 +242,7 @@ static void udp_do_one(int lnr, const char *line) | |||
| 254 | break; | 242 | break; |
| 255 | } | 243 | } |
| 256 | 244 | ||
| 257 | #ifdef CONFIG_FEATURE_IPV6 | 245 | #if ENABLE_FEATURE_IPV6 |
| 258 | # define notnull(A) (((A.sin6_family == AF_INET6) && \ | 246 | # define notnull(A) (((A.sin6_family == AF_INET6) && \ |
| 259 | ((A.sin6_addr.s6_addr32[0]) || \ | 247 | ((A.sin6_addr.s6_addr32[0]) || \ |
| 260 | (A.sin6_addr.s6_addr32[1]) || \ | 248 | (A.sin6_addr.s6_addr32[1]) || \ |
| @@ -265,20 +253,19 @@ static void udp_do_one(int lnr, const char *line) | |||
| 265 | #else | 253 | #else |
| 266 | # define notnull(A) (A.sin_addr.s_addr) | 254 | # define notnull(A) (A.sin_addr.s_addr) |
| 267 | #endif | 255 | #endif |
| 268 | if ((notnull(remaddr) && (flags&NETSTAT_CONNECTED)) || | 256 | if ((notnull(remaddr) && (flags & NETSTAT_CONNECTED)) |
| 269 | (!notnull(remaddr) && (flags&NETSTAT_LISTENING))) | 257 | || (!notnull(remaddr) && (flags & NETSTAT_LISTENING)) |
| 270 | { | 258 | ) { |
| 271 | snprint_ip_port(local_addr, sizeof(local_addr), | 259 | snprint_ip_port(local_addr, sizeof(local_addr), |
| 272 | (struct sockaddr *) &localaddr, local_port, | 260 | (struct sockaddr *) &localaddr, local_port, |
| 273 | "udp", flags&NETSTAT_NUMERIC); | 261 | "udp", flags & NETSTAT_NUMERIC); |
| 274 | 262 | ||
| 275 | snprint_ip_port(rem_addr, sizeof(rem_addr), | 263 | snprint_ip_port(rem_addr, sizeof(rem_addr), |
| 276 | (struct sockaddr *) &remaddr, rem_port, | 264 | (struct sockaddr *) &remaddr, rem_port, |
| 277 | "udp", flags&NETSTAT_NUMERIC); | 265 | "udp", flags & NETSTAT_NUMERIC); |
| 278 | 266 | ||
| 279 | printf("udp %6ld %6ld %-23s %-23s %-12s\n", | 267 | printf("udp %6ld %6ld %-23s %-23s %-12s\n", |
| 280 | rxq, txq, local_addr, rem_addr, state_str); | 268 | rxq, txq, local_addr, rem_addr, state_str); |
| 281 | |||
| 282 | } | 269 | } |
| 283 | } | 270 | } |
| 284 | 271 | ||
| @@ -287,7 +274,7 @@ static void raw_do_one(int lnr, const char *line) | |||
| 287 | char local_addr[64], rem_addr[64]; | 274 | char local_addr[64], rem_addr[64]; |
| 288 | char *state_str, more[512]; | 275 | char *state_str, more[512]; |
| 289 | int num, local_port, rem_port, d, state, timer_run, uid, timeout; | 276 | int num, local_port, rem_port, d, state, timer_run, uid, timeout; |
| 290 | #ifdef CONFIG_FEATURE_IPV6 | 277 | #if ENABLE_FEATURE_IPV6 |
| 291 | struct sockaddr_in6 localaddr, remaddr; | 278 | struct sockaddr_in6 localaddr, remaddr; |
| 292 | char addr6[INET6_ADDRSTRLEN]; | 279 | char addr6[INET6_ADDRSTRLEN]; |
| 293 | struct in6_addr in6; | 280 | struct in6_addr in6; |
| @@ -307,7 +294,7 @@ static void raw_do_one(int lnr, const char *line) | |||
| 307 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); | 294 | &txq, &rxq, &timer_run, &time_len, &retr, &uid, &timeout, &inode, more); |
| 308 | 295 | ||
| 309 | if (strlen(local_addr) > 8) { | 296 | if (strlen(local_addr) > 8) { |
| 310 | #ifdef CONFIG_FEATURE_IPV6 | 297 | #if ENABLE_FEATURE_IPV6 |
| 311 | sscanf(local_addr, "%08X%08X%08X%08X", | 298 | sscanf(local_addr, "%08X%08X%08X%08X", |
| 312 | &in6.s6_addr32[0], &in6.s6_addr32[1], | 299 | &in6.s6_addr32[0], &in6.s6_addr32[1], |
| 313 | &in6.s6_addr32[2], &in6.s6_addr32[3]); | 300 | &in6.s6_addr32[2], &in6.s6_addr32[3]); |
| @@ -334,9 +321,9 @@ static void raw_do_one(int lnr, const char *line) | |||
| 334 | bb_error_msg("warning, got bogus raw line"); | 321 | bb_error_msg("warning, got bogus raw line"); |
| 335 | return; | 322 | return; |
| 336 | } | 323 | } |
| 337 | state_str=itoa(state); | 324 | state_str = itoa(state); |
| 338 | 325 | ||
| 339 | #ifdef CONFIG_FEATURE_IPV6 | 326 | #if ENABLE_FEATURE_IPV6 |
| 340 | # define notnull(A) (((A.sin6_family == AF_INET6) && \ | 327 | # define notnull(A) (((A.sin6_family == AF_INET6) && \ |
| 341 | ((A.sin6_addr.s6_addr32[0]) || \ | 328 | ((A.sin6_addr.s6_addr32[0]) || \ |
| 342 | (A.sin6_addr.s6_addr32[1]) || \ | 329 | (A.sin6_addr.s6_addr32[1]) || \ |
| @@ -347,20 +334,19 @@ static void raw_do_one(int lnr, const char *line) | |||
| 347 | #else | 334 | #else |
| 348 | # define notnull(A) (A.sin_addr.s_addr) | 335 | # define notnull(A) (A.sin_addr.s_addr) |
| 349 | #endif | 336 | #endif |
| 350 | if ((notnull(remaddr) && (flags&NETSTAT_CONNECTED)) || | 337 | if ((notnull(remaddr) && (flags & NETSTAT_CONNECTED)) |
| 351 | (!notnull(remaddr) && (flags&NETSTAT_LISTENING))) | 338 | || (!notnull(remaddr) && (flags & NETSTAT_LISTENING)) |
| 352 | { | 339 | ) { |
| 353 | snprint_ip_port(local_addr, sizeof(local_addr), | 340 | snprint_ip_port(local_addr, sizeof(local_addr), |
| 354 | (struct sockaddr *) &localaddr, local_port, | 341 | (struct sockaddr *) &localaddr, local_port, |
| 355 | "raw", flags&NETSTAT_NUMERIC); | 342 | "raw", flags & NETSTAT_NUMERIC); |
| 356 | 343 | ||
| 357 | snprint_ip_port(rem_addr, sizeof(rem_addr), | 344 | snprint_ip_port(rem_addr, sizeof(rem_addr), |
| 358 | (struct sockaddr *) &remaddr, rem_port, | 345 | (struct sockaddr *) &remaddr, rem_port, |
| 359 | "raw", flags&NETSTAT_NUMERIC); | 346 | "raw", flags & NETSTAT_NUMERIC); |
| 360 | 347 | ||
| 361 | printf("raw %6ld %6ld %-23s %-23s %-12s\n", | 348 | printf("raw %6ld %6ld %-23s %-23s %-12s\n", |
| 362 | rxq, txq, local_addr, rem_addr, state_str); | 349 | rxq, txq, local_addr, rem_addr, state_str); |
| 363 | |||
| 364 | } | 350 | } |
| 365 | } | 351 | } |
| 366 | 352 | ||
| @@ -390,12 +376,12 @@ static void unix_do_one(int nr, const char *line) | |||
| 390 | if (!(has & HAS_INODE)) | 376 | if (!(has & HAS_INODE)) |
| 391 | snprintf(path,sizeof(path),"%d",inode); | 377 | snprintf(path,sizeof(path),"%d",inode); |
| 392 | 378 | ||
| 393 | if ((flags&(NETSTAT_LISTENING|NETSTAT_CONNECTED))!=(NETSTAT_LISTENING|NETSTAT_CONNECTED)) { | 379 | if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) != (NETSTAT_LISTENING|NETSTAT_CONNECTED)) { |
| 394 | if ((state == SS_UNCONNECTED) && (unix_flags & SO_ACCEPTCON)) { | 380 | if ((state == SS_UNCONNECTED) && (unix_flags & SO_ACCEPTCON)) { |
| 395 | if (!(flags&NETSTAT_LISTENING)) | 381 | if (!(flags & NETSTAT_LISTENING)) |
| 396 | return; | 382 | return; |
| 397 | } else { | 383 | } else { |
| 398 | if (!(flags&NETSTAT_CONNECTED)) | 384 | if (!(flags & NETSTAT_CONNECTED)) |
| 399 | return; | 385 | return; |
| 400 | } | 386 | } |
| 401 | } | 387 | } |
| @@ -502,20 +488,20 @@ static void do_info(const char *file, const char *name, void (*proc)(int, const | |||
| 502 | procinfo = fopen(file, "r"); | 488 | procinfo = fopen(file, "r"); |
| 503 | if (procinfo == NULL) { | 489 | if (procinfo == NULL) { |
| 504 | if (errno != ENOENT) { | 490 | if (errno != ENOENT) { |
| 505 | perror(file); | 491 | bb_perror_msg("%s", file); |
| 506 | } else { | 492 | } else { |
| 507 | bb_error_msg("no support for '%s' on this system", name); | 493 | bb_error_msg("no support for '%s' on this system", name); |
| 508 | } | 494 | } |
| 509 | } else { | 495 | return; |
| 510 | do { | ||
| 511 | char *buffer = xmalloc_fgets(procinfo); | ||
| 512 | if (buffer) { | ||
| 513 | (proc)(lnr++, buffer); | ||
| 514 | free(buffer); | ||
| 515 | } | ||
| 516 | } while (!feof(procinfo)); | ||
| 517 | fclose(procinfo); | ||
| 518 | } | 496 | } |
| 497 | do { | ||
| 498 | char *buffer = xmalloc_fgets(procinfo); | ||
| 499 | if (buffer) { | ||
| 500 | (proc)(lnr++, buffer); | ||
| 501 | free(buffer); | ||
| 502 | } | ||
| 503 | } while (!feof(procinfo)); | ||
| 504 | fclose(procinfo); | ||
| 519 | } | 505 | } |
| 520 | 506 | ||
| 521 | /* | 507 | /* |
| @@ -529,12 +515,11 @@ int netstat_main(int argc, char **argv) | |||
| 529 | OPT_showroute = 0x100, | 515 | OPT_showroute = 0x100, |
| 530 | }; | 516 | }; |
| 531 | unsigned opt; | 517 | unsigned opt; |
| 532 | #ifdef CONFIG_FEATURE_IPV6 | 518 | #if ENABLE_FEATURE_IPV6 |
| 533 | int inet = 1; | 519 | int inet = 1; |
| 534 | int inet6 = 1; | 520 | int inet6 = 1; |
| 535 | #else | 521 | #else |
| 536 | # define inet 1 | 522 | enum { inet = 1, inet6 = 0 }; |
| 537 | # define inet6 0 | ||
| 538 | #endif | 523 | #endif |
| 539 | 524 | ||
| 540 | /* Option string must match NETSTAT_xxx constants */ | 525 | /* Option string must match NETSTAT_xxx constants */ |
| @@ -551,8 +536,8 @@ int netstat_main(int argc, char **argv) | |||
| 551 | //if (opt & 0x40) // -w: NETSTAT_RAW | 536 | //if (opt & 0x40) // -w: NETSTAT_RAW |
| 552 | //if (opt & 0x80) // -x: NETSTAT_UNIX | 537 | //if (opt & 0x80) // -x: NETSTAT_UNIX |
| 553 | if (opt & OPT_showroute) { // -r | 538 | if (opt & OPT_showroute) { // -r |
| 554 | #ifdef CONFIG_ROUTE | 539 | #if ENABLE_ROUTE |
| 555 | displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended)); | 540 | bb_displayroutes(flags & NETSTAT_NUMERIC, !(opt & OPT_extended)); |
| 556 | return 0; | 541 | return 0; |
| 557 | #else | 542 | #else |
| 558 | bb_error_msg_and_die("-r (display routing table) is not compiled in"); | 543 | bb_error_msg_and_die("-r (display routing table) is not compiled in"); |
| @@ -567,47 +552,42 @@ int netstat_main(int argc, char **argv) | |||
| 567 | if (flags & (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW)) { | 552 | if (flags & (NETSTAT_TCP|NETSTAT_UDP|NETSTAT_RAW)) { |
| 568 | printf("Active Internet connections "); /* xxx */ | 553 | printf("Active Internet connections "); /* xxx */ |
| 569 | 554 | ||
| 570 | if ((flags&(NETSTAT_LISTENING|NETSTAT_CONNECTED))==(NETSTAT_LISTENING|NETSTAT_CONNECTED)) | 555 | if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) == (NETSTAT_LISTENING|NETSTAT_CONNECTED)) |
| 571 | printf("(servers and established)"); | 556 | printf("(servers and established)"); |
| 572 | else { | 557 | else if (flags & NETSTAT_LISTENING) |
| 573 | if (flags & NETSTAT_LISTENING) | 558 | printf("(only servers)"); |
| 574 | printf("(only servers)"); | 559 | else |
| 575 | else | 560 | printf("(w/o servers)"); |
| 576 | printf("(w/o servers)"); | ||
| 577 | } | ||
| 578 | printf("\nProto Recv-Q Send-Q Local Address Foreign Address State\n"); | 561 | printf("\nProto Recv-Q Send-Q Local Address Foreign Address State\n"); |
| 579 | } | 562 | } |
| 580 | if (inet && flags&NETSTAT_TCP) | 563 | if (inet && flags & NETSTAT_TCP) |
| 581 | do_info(_PATH_PROCNET_TCP,"AF INET (tcp)",tcp_do_one); | 564 | do_info(_PATH_PROCNET_TCP, "AF INET (tcp)", tcp_do_one); |
| 582 | #ifdef CONFIG_FEATURE_IPV6 | 565 | #if ENABLE_FEATURE_IPV6 |
| 583 | if (inet6 && flags&NETSTAT_TCP) | 566 | if (inet6 && flags & NETSTAT_TCP) |
| 584 | do_info(_PATH_PROCNET_TCP6,"AF INET6 (tcp)",tcp_do_one); | 567 | do_info(_PATH_PROCNET_TCP6, "AF INET6 (tcp)", tcp_do_one); |
| 585 | #endif | 568 | #endif |
| 586 | if (inet && flags&NETSTAT_UDP) | 569 | if (inet && flags & NETSTAT_UDP) |
| 587 | do_info(_PATH_PROCNET_UDP,"AF INET (udp)",udp_do_one); | 570 | do_info(_PATH_PROCNET_UDP, "AF INET (udp)", udp_do_one); |
| 588 | #ifdef CONFIG_FEATURE_IPV6 | 571 | #if ENABLE_FEATURE_IPV6 |
| 589 | if (inet6 && flags&NETSTAT_UDP) | 572 | if (inet6 && flags & NETSTAT_UDP) |
| 590 | do_info(_PATH_PROCNET_UDP6,"AF INET6 (udp)",udp_do_one); | 573 | do_info(_PATH_PROCNET_UDP6, "AF INET6 (udp)", udp_do_one); |
| 591 | #endif | 574 | #endif |
| 592 | if (inet && flags&NETSTAT_RAW) | 575 | if (inet && flags & NETSTAT_RAW) |
| 593 | do_info(_PATH_PROCNET_RAW,"AF INET (raw)",raw_do_one); | 576 | do_info(_PATH_PROCNET_RAW, "AF INET (raw)", raw_do_one); |
| 594 | #ifdef CONFIG_FEATURE_IPV6 | 577 | #if ENABLE_FEATURE_IPV6 |
| 595 | if (inet6 && flags&NETSTAT_RAW) | 578 | if (inet6 && flags & NETSTAT_RAW) |
| 596 | do_info(_PATH_PROCNET_RAW6,"AF INET6 (raw)",raw_do_one); | 579 | do_info(_PATH_PROCNET_RAW6, "AF INET6 (raw)", raw_do_one); |
| 597 | #endif | 580 | #endif |
| 598 | if (flags&NETSTAT_UNIX) { | 581 | if (flags & NETSTAT_UNIX) { |
| 599 | printf("Active UNIX domain sockets "); | 582 | printf("Active UNIX domain sockets "); |
| 600 | if ((flags&(NETSTAT_LISTENING|NETSTAT_CONNECTED))==(NETSTAT_LISTENING|NETSTAT_CONNECTED)) | 583 | if ((flags & (NETSTAT_LISTENING|NETSTAT_CONNECTED)) == (NETSTAT_LISTENING|NETSTAT_CONNECTED)) |
| 601 | printf("(servers and established)"); | 584 | printf("(servers and established)"); |
| 602 | else { | 585 | else if (flags & NETSTAT_LISTENING) |
| 603 | if (flags&NETSTAT_LISTENING) | 586 | printf("(only servers)"); |
| 604 | printf("(only servers)"); | 587 | else |
| 605 | else | 588 | printf("(w/o servers)"); |
| 606 | printf("(w/o servers)"); | ||
| 607 | } | ||
| 608 | |||
| 609 | printf("\nProto RefCnt Flags Type State I-Node Path\n"); | 589 | printf("\nProto RefCnt Flags Type State I-Node Path\n"); |
| 610 | do_info(_PATH_PROCNET_UNIX,"AF UNIX",unix_do_one); | 590 | do_info(_PATH_PROCNET_UNIX, "AF UNIX", unix_do_one); |
| 611 | } | 591 | } |
| 612 | return 0; | 592 | return 0; |
| 613 | } | 593 | } |
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) | |||
| 343 | 343 | ||
| 344 | /* set recv buf for broadcast pings */ | 344 | /* set recv buf for broadcast pings */ |
| 345 | sockopt = 48 * 1024; /* explain why 48k? */ | 345 | sockopt = 48 * 1024; /* explain why 48k? */ |
| 346 | setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt, | 346 | setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); |
| 347 | sizeof(sockopt)); | ||
| 348 | 347 | ||
| 349 | printf("PING %s (%s)", | 348 | printf("PING %s (%s)", |
| 350 | hostent->h_name, | 349 | 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) | |||
| 77 | pkt->icmp6_type = ICMP6_ECHO_REQUEST; | 77 | pkt->icmp6_type = ICMP6_ECHO_REQUEST; |
| 78 | 78 | ||
| 79 | sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); | 79 | sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); |
| 80 | setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, (char *) &sockopt, | 80 | setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); |
| 81 | sizeof(sockopt)); | ||
| 82 | 81 | ||
| 83 | c = sendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), 0, | 82 | c = sendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), 0, |
| 84 | (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in6)); | 83 | (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in6)); |
| @@ -312,6 +311,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit | |||
| 312 | fflush(stdout); | 311 | fflush(stdout); |
| 313 | } | 312 | } |
| 314 | 313 | ||
| 314 | extern int BUG_bad_offsetof_icmp6_cksum(void); | ||
| 315 | static void ping(const char *host) | 315 | static void ping(const char *host) |
| 316 | { | 316 | { |
| 317 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; | 317 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
| @@ -353,18 +353,15 @@ static void ping(const char *host) | |||
| 353 | 353 | ||
| 354 | /* set recv buf for broadcast pings */ | 354 | /* set recv buf for broadcast pings */ |
| 355 | sockopt = 48 * 1024; /* explain why 48k? */ | 355 | sockopt = 48 * 1024; /* explain why 48k? */ |
| 356 | setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *) &sockopt, | 356 | setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); |
| 357 | sizeof(sockopt)); | ||
| 358 | 357 | ||
| 359 | sockopt = 2; /* iputils-ss020927 does this */ | ||
| 360 | sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); | 358 | sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); |
| 361 | setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, (char *) &sockopt, | 359 | if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2) |
| 362 | sizeof(sockopt)); | 360 | BUG_bad_offsetof_icmp6_cksum(); |
| 361 | setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); | ||
| 363 | 362 | ||
| 364 | /* request ttl info to be returned in ancillary data */ | 363 | /* request ttl info to be returned in ancillary data */ |
| 365 | sockopt = 1; | 364 | setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, &const_int_1, sizeof(const_int_1)); |
| 366 | setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, (char *) &sockopt, | ||
| 367 | sizeof(sockopt)); | ||
| 368 | 365 | ||
| 369 | if (if_index) | 366 | if (if_index) |
| 370 | pingaddr.sin6_scope_id = if_index; | 367 | 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 @@ | |||
| 63 | #endif | 63 | #endif |
| 64 | 64 | ||
| 65 | /* The RTACTION entries must agree with tbl_verb[] below! */ | 65 | /* The RTACTION entries must agree with tbl_verb[] below! */ |
| 66 | #define RTACTION_ADD 1 | 66 | #define RTACTION_ADD 1 |
| 67 | #define RTACTION_DEL 2 | 67 | #define RTACTION_DEL 2 |
| 68 | 68 | ||
| 69 | /* For the various tbl_*[] arrays, the 1st byte is the offset to | 69 | /* For the various tbl_*[] arrays, the 1st byte is the offset to |
| 70 | * the next entry and the 2nd byte is return value. */ | 70 | * the next entry and the 2nd byte is return value. */ |
| 71 | 71 | ||
| 72 | #define NET_FLAG 1 | 72 | #define NET_FLAG 1 |
| 73 | #define HOST_FLAG 2 | 73 | #define HOST_FLAG 2 |
| 74 | 74 | ||
| 75 | /* We remap '-' to '#' to avoid problems with getopt. */ | 75 | /* We remap '-' to '#' to avoid problems with getopt. */ |
| 76 | static const char tbl_hash_net_host[] = | 76 | static const char tbl_hash_net_host[] = |
| @@ -79,22 +79,22 @@ static const char tbl_hash_net_host[] = | |||
| 79 | "\007\002#host" /* Since last, we can save a byte. */ | 79 | "\007\002#host" /* Since last, we can save a byte. */ |
| 80 | ; | 80 | ; |
| 81 | 81 | ||
| 82 | #define KW_TAKES_ARG 020 | 82 | #define KW_TAKES_ARG 020 |
| 83 | #define KW_SETS_FLAG 040 | 83 | #define KW_SETS_FLAG 040 |
| 84 | 84 | ||
| 85 | #define KW_IPVx_METRIC 020 | 85 | #define KW_IPVx_METRIC 020 |
| 86 | #define KW_IPVx_NETMASK 021 | 86 | #define KW_IPVx_NETMASK 021 |
| 87 | #define KW_IPVx_GATEWAY 022 | 87 | #define KW_IPVx_GATEWAY 022 |
| 88 | #define KW_IPVx_MSS 023 | 88 | #define KW_IPVx_MSS 023 |
| 89 | #define KW_IPVx_WINDOW 024 | 89 | #define KW_IPVx_WINDOW 024 |
| 90 | #define KW_IPVx_IRTT 025 | 90 | #define KW_IPVx_IRTT 025 |
| 91 | #define KW_IPVx_DEVICE 026 | 91 | #define KW_IPVx_DEVICE 026 |
| 92 | 92 | ||
| 93 | #define KW_IPVx_FLAG_ONLY 040 | 93 | #define KW_IPVx_FLAG_ONLY 040 |
| 94 | #define KW_IPVx_REJECT 040 | 94 | #define KW_IPVx_REJECT 040 |
| 95 | #define KW_IPVx_MOD 041 | 95 | #define KW_IPVx_MOD 041 |
| 96 | #define KW_IPVx_DYN 042 | 96 | #define KW_IPVx_DYN 042 |
| 97 | #define KW_IPVx_REINSTATE 043 | 97 | #define KW_IPVx_REINSTATE 043 |
| 98 | 98 | ||
| 99 | static const char tbl_ipvx[] = | 99 | static const char tbl_ipvx[] = |
| 100 | /* 020 is the "takes an arg" bit */ | 100 | /* 020 is the "takes an arg" bit */ |
| @@ -167,7 +167,7 @@ static void INET_setroute(int action, char **args) | |||
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | /* Clean out the RTREQ structure. */ | 169 | /* Clean out the RTREQ structure. */ |
| 170 | memset((char *) &rt, 0, sizeof(struct rtentry)); | 170 | memset(&rt, 0, sizeof(rt)); |
| 171 | 171 | ||
| 172 | { | 172 | { |
| 173 | const char *target = *args++; | 173 | const char *target = *args++; |
| @@ -334,7 +334,7 @@ static void INET_setroute(int action, char **args) | |||
| 334 | if (ENABLE_FEATURE_CLEAN_UP) close(skfd); | 334 | if (ENABLE_FEATURE_CLEAN_UP) close(skfd); |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | #ifdef CONFIG_FEATURE_IPV6 | 337 | #if ENABLE_FEATURE_IPV6 |
| 338 | 338 | ||
| 339 | static void INET6_setroute(int action, char **args) | 339 | static void INET6_setroute(int action, char **args) |
| 340 | { | 340 | { |
| @@ -363,7 +363,7 @@ static void INET6_setroute(int action, char **args) | |||
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | /* Clean out the RTREQ structure. */ | 365 | /* Clean out the RTREQ structure. */ |
| 366 | memset((char *) &rt, 0, sizeof(struct in6_rtmsg)); | 366 | memset(&rt, 0, sizeof(rt)); |
| 367 | 367 | ||
| 368 | memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr)); | 368 | memcpy(&rt.rtmsg_dst, sa6.sin6_addr.s6_addr, sizeof(struct in6_addr)); |
| 369 | 369 | ||
| @@ -445,7 +445,7 @@ static const unsigned int flagvals[] = { /* Must agree with flagchars[]. */ | |||
| 445 | RTF_REINSTATE, | 445 | RTF_REINSTATE, |
| 446 | RTF_DYNAMIC, | 446 | RTF_DYNAMIC, |
| 447 | RTF_MODIFIED, | 447 | RTF_MODIFIED, |
| 448 | #ifdef CONFIG_FEATURE_IPV6 | 448 | #if ENABLE_FEATURE_IPV6 |
| 449 | RTF_DEFAULT, | 449 | RTF_DEFAULT, |
| 450 | RTF_ADDRCONF, | 450 | RTF_ADDRCONF, |
| 451 | RTF_CACHE | 451 | RTF_CACHE |
| @@ -457,7 +457,7 @@ static const unsigned int flagvals[] = { /* Must agree with flagchars[]. */ | |||
| 457 | 457 | ||
| 458 | static const char flagchars[] = /* Must agree with flagvals[]. */ | 458 | static const char flagchars[] = /* Must agree with flagvals[]. */ |
| 459 | "GHRDM" | 459 | "GHRDM" |
| 460 | #ifdef CONFIG_FEATURE_IPV6 | 460 | #if ENABLE_FEATURE_IPV6 |
| 461 | "DAC" | 461 | "DAC" |
| 462 | #endif | 462 | #endif |
| 463 | ; | 463 | ; |
| @@ -476,7 +476,7 @@ static void set_flags(char *flagstr, int flags) | |||
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | /* also used in netstat */ | 478 | /* also used in netstat */ |
| 479 | void displayroutes(int noresolve, int netstatfmt) | 479 | void bb_displayroutes(int noresolve, int netstatfmt) |
| 480 | { | 480 | { |
| 481 | char devname[64], flags[16], sdest[16], sgw[16]; | 481 | char devname[64], flags[16], sdest[16], sgw[16]; |
| 482 | unsigned long int d, g, m; | 482 | unsigned long int d, g, m; |
| @@ -537,7 +537,7 @@ void displayroutes(int noresolve, int netstatfmt) | |||
| 537 | } | 537 | } |
| 538 | } | 538 | } |
| 539 | 539 | ||
| 540 | #ifdef CONFIG_FEATURE_IPV6 | 540 | #if ENABLE_FEATURE_IPV6 |
| 541 | 541 | ||
| 542 | static void INET6_displayroutes(int noresolve) | 542 | static void INET6_displayroutes(int noresolve) |
| 543 | { | 543 | { |
| @@ -589,7 +589,7 @@ static void INET6_displayroutes(int noresolve) | |||
| 589 | goto ERROR; | 589 | goto ERROR; |
| 590 | } | 590 | } |
| 591 | addr6x[i++] = *p++; | 591 | addr6x[i++] = *p++; |
| 592 | if (!((i+1)%5)) { | 592 | if (!((i+1) % 5)) { |
| 593 | addr6x[i++] = ':'; | 593 | addr6x[i++] = ':'; |
| 594 | } | 594 | } |
| 595 | } while (i < 40+28+7); | 595 | } while (i < 40+28+7); |
| @@ -626,10 +626,10 @@ static void INET6_displayroutes(int noresolve) | |||
| 626 | 626 | ||
| 627 | #endif | 627 | #endif |
| 628 | 628 | ||
| 629 | #define ROUTE_OPT_A 0x01 | 629 | #define ROUTE_OPT_A 0x01 |
| 630 | #define ROUTE_OPT_n 0x02 | 630 | #define ROUTE_OPT_n 0x02 |
| 631 | #define ROUTE_OPT_e 0x04 | 631 | #define ROUTE_OPT_e 0x04 |
| 632 | #define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */ | 632 | #define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */ |
| 633 | 633 | ||
| 634 | /* 1st byte is offset to next entry offset. 2nd byte is return value. */ | 634 | /* 1st byte is offset to next entry offset. 2nd byte is return value. */ |
| 635 | static const char tbl_verb[] = /* 2nd byte matches RTACTION_* code */ | 635 | static const char tbl_verb[] = /* 2nd byte matches RTACTION_* code */ |
| @@ -649,15 +649,15 @@ int route_main(int argc, char **argv) | |||
| 649 | /* First, remap '-net' and '-host' to avoid getopt problems. */ | 649 | /* First, remap '-net' and '-host' to avoid getopt problems. */ |
| 650 | p = argv; | 650 | p = argv; |
| 651 | while (*++p) { | 651 | while (*++p) { |
| 652 | if ((strcmp(*p, "-net") == 0) || (strcmp(*p, "-host") == 0)) { | 652 | if (strcmp(*p, "-net") == 0 || strcmp(*p, "-host") == 0) { |
| 653 | p[0][0] = '#'; | 653 | p[0][0] = '#'; |
| 654 | } | 654 | } |
| 655 | } | 655 | } |
| 656 | 656 | ||
| 657 | opt = getopt32(argc, argv, "A:ne", &family); | 657 | opt = getopt32(argc, argv, "A:ne", &family); |
| 658 | 658 | ||
| 659 | if ((opt & ROUTE_OPT_A) && strcmp(family, "inet")) { | 659 | if ((opt & ROUTE_OPT_A) && strcmp(family, "inet") != 0) { |
| 660 | #ifdef CONFIG_FEATURE_IPV6 | 660 | #if ENABLE_FEATURE_IPV6 |
| 661 | if (strcmp(family, "inet6") == 0) { | 661 | if (strcmp(family, "inet6") == 0) { |
| 662 | opt |= ROUTE_OPT_INET6; /* Set flag for ipv6. */ | 662 | opt |= ROUTE_OPT_INET6; /* Set flag for ipv6. */ |
| 663 | } else | 663 | } else |
| @@ -670,12 +670,12 @@ int route_main(int argc, char **argv) | |||
| 670 | /* No more args means display the routing table. */ | 670 | /* No more args means display the routing table. */ |
| 671 | if (!*argv) { | 671 | if (!*argv) { |
| 672 | int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0; | 672 | int noresolve = (opt & ROUTE_OPT_n) ? 0x0fff : 0; |
| 673 | #ifdef CONFIG_FEATURE_IPV6 | 673 | #if ENABLE_FEATURE_IPV6 |
| 674 | if (opt & ROUTE_OPT_INET6) | 674 | if (opt & ROUTE_OPT_INET6) |
| 675 | INET6_displayroutes(noresolve); | 675 | INET6_displayroutes(noresolve); |
| 676 | else | 676 | else |
| 677 | #endif | 677 | #endif |
| 678 | displayroutes(noresolve, opt & ROUTE_OPT_e); | 678 | bb_displayroutes(noresolve, opt & ROUTE_OPT_e); |
| 679 | 679 | ||
| 680 | fflush_stdout_and_exit(EXIT_SUCCESS); | 680 | fflush_stdout_and_exit(EXIT_SUCCESS); |
| 681 | } | 681 | } |
| @@ -686,7 +686,7 @@ int route_main(int argc, char **argv) | |||
| 686 | bb_show_usage(); | 686 | bb_show_usage(); |
| 687 | } | 687 | } |
| 688 | 688 | ||
| 689 | #ifdef CONFIG_FEATURE_IPV6 | 689 | #if ENABLE_FEATURE_IPV6 |
| 690 | if (opt & ROUTE_OPT_INET6) | 690 | if (opt & ROUTE_OPT_INET6) |
| 691 | INET6_setroute(what, argv); | 691 | INET6_setroute(what, argv); |
| 692 | else | 692 | 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); | |||
| 95 | static int subneg(byte c); | 95 | static int subneg(byte c); |
| 96 | 96 | ||
| 97 | /* Some globals */ | 97 | /* Some globals */ |
| 98 | static const int one = 1; | ||
| 99 | |||
| 100 | #ifdef CONFIG_FEATURE_TELNET_TTYPE | 98 | #ifdef CONFIG_FEATURE_TELNET_TTYPE |
| 101 | static char *ttype; | 99 | static char *ttype; |
| 102 | #endif | 100 | #endif |
| @@ -630,7 +628,7 @@ int telnet_main(int argc, char** argv) | |||
| 630 | 628 | ||
| 631 | G.netfd = create_and_connect_stream_or_die(host, port); | 629 | G.netfd = create_and_connect_stream_or_die(host, port); |
| 632 | 630 | ||
| 633 | setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one); | 631 | setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1)); |
| 634 | 632 | ||
| 635 | signal(SIGINT, fgotsig); | 633 | signal(SIGINT, fgotsig); |
| 636 | 634 | ||
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 @@ | |||
| 207 | //#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP | 207 | //#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP |
| 208 | //#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP | 208 | //#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP |
| 209 | 209 | ||
| 210 | #include "inet_common.h" | ||
| 211 | 210 | ||
| 212 | #include <net/if.h> | 211 | #include <net/if.h> |
| 213 | #include <arpa/inet.h> | 212 | #include <arpa/inet.h> |
| @@ -217,6 +216,7 @@ | |||
| 217 | #include <netinet/ip_icmp.h> | 216 | #include <netinet/ip_icmp.h> |
| 218 | 217 | ||
| 219 | #include "busybox.h" | 218 | #include "busybox.h" |
| 219 | #include "inet_common.h" | ||
| 220 | 220 | ||
| 221 | 221 | ||
| 222 | /* | 222 | /* |
| @@ -803,7 +803,8 @@ inetname(struct sockaddr_in *from) | |||
| 803 | char name[257]; | 803 | char name[257]; |
| 804 | 804 | ||
| 805 | if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { | 805 | if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { |
| 806 | if (INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0) | 806 | if (INET_rresolve(name, sizeof(name), from, 0x4000, |
| 807 | 0xffffffff) >= 0) | ||
| 807 | n = name; | 808 | n = name; |
| 808 | } | 809 | } |
| 809 | ina = inet_ntoa(from->sin_addr); | 810 | ina = inet_ntoa(from->sin_addr); |
| @@ -842,7 +843,7 @@ gethostinfo(const char *host) | |||
| 842 | 843 | ||
| 843 | hi = xzalloc(sizeof(*hi)); | 844 | hi = xzalloc(sizeof(*hi)); |
| 844 | addr = inet_addr(host); | 845 | addr = inet_addr(host); |
| 845 | if ((int32_t)addr != -1) { | 846 | if (addr != 0xffffffff) { |
| 846 | hi->name = xstrdup(host); | 847 | hi->name = xstrdup(host); |
| 847 | hi->n = 1; | 848 | hi->n = 1; |
| 848 | hi->addrs = xzalloc(sizeof(hi->addrs[0])); | 849 | hi->addrs = xzalloc(sizeof(hi->addrs[0])); |
| @@ -888,8 +889,6 @@ getaddr(uint32_t *ap, const char *host) | |||
| 888 | int | 889 | int |
| 889 | traceroute_main(int argc, char *argv[]) | 890 | traceroute_main(int argc, char *argv[]) |
| 890 | { | 891 | { |
| 891 | static const int on = 1; | ||
| 892 | |||
| 893 | int code, n; | 892 | int code, n; |
| 894 | unsigned char *outp; | 893 | unsigned char *outp; |
| 895 | uint32_t *ap; | 894 | uint32_t *ap; |
| @@ -1043,19 +1042,19 @@ traceroute_main(int argc, char *argv[]) | |||
| 1043 | 1042 | ||
| 1044 | /* Insure the socket fds won't be 0, 1 or 2 */ | 1043 | /* Insure the socket fds won't be 0, 1 or 2 */ |
| 1045 | do n = xopen(bb_dev_null, O_RDONLY); while (n < 2); | 1044 | do n = xopen(bb_dev_null, O_RDONLY); while (n < 2); |
| 1046 | if (n > 2) | 1045 | while (n > 2) |
| 1047 | close(n); | 1046 | close(n--); |
| 1048 | 1047 | ||
| 1049 | s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP); | 1048 | s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP); |
| 1050 | 1049 | ||
| 1051 | #if TRACEROUTE_SO_DEBUG | 1050 | #if TRACEROUTE_SO_DEBUG |
| 1052 | if (op & USAGE_OP_DEBUG) | 1051 | if (op & USAGE_OP_DEBUG) |
| 1053 | (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, (char *)&on, | 1052 | setsockopt(s, SOL_SOCKET, SO_DEBUG, |
| 1054 | sizeof(on)); | 1053 | &const_int_1, sizeof(const_int_1)); |
| 1055 | #endif | 1054 | #endif |
| 1056 | if (op & USAGE_OP_BYPASS_ROUTE) | 1055 | if (op & USAGE_OP_BYPASS_ROUTE) |
| 1057 | (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, | 1056 | setsockopt(s, SOL_SOCKET, SO_DONTROUTE, |
| 1058 | sizeof(on)); | 1057 | &const_int_1, sizeof(const_int_1)); |
| 1059 | 1058 | ||
| 1060 | sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); | 1059 | sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); |
| 1061 | 1060 | ||
| @@ -1087,32 +1086,31 @@ traceroute_main(int argc, char *argv[]) | |||
| 1087 | #endif /* CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE */ | 1086 | #endif /* CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE */ |
| 1088 | 1087 | ||
| 1089 | #ifdef SO_SNDBUF | 1088 | #ifdef SO_SNDBUF |
| 1090 | if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, (char *)&packlen, | 1089 | if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) < 0) { |
| 1091 | sizeof(packlen)) < 0) { | ||
| 1092 | bb_perror_msg_and_die("SO_SNDBUF"); | 1090 | bb_perror_msg_and_die("SO_SNDBUF"); |
| 1093 | } | 1091 | } |
| 1094 | #endif | 1092 | #endif |
| 1095 | #ifdef IP_HDRINCL | 1093 | #ifdef IP_HDRINCL |
| 1096 | if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, (char *)&on, | 1094 | if (setsockopt(sndsock, IPPROTO_IP, IP_HDRINCL, &const_int_1, sizeof(const_int_1)) < 0 |
| 1097 | sizeof(on)) < 0 && errno != ENOPROTOOPT) { | 1095 | && errno != ENOPROTOOPT |
| 1096 | ) { | ||
| 1098 | bb_perror_msg_and_die("IP_HDRINCL"); | 1097 | bb_perror_msg_and_die("IP_HDRINCL"); |
| 1099 | } | 1098 | } |
| 1100 | #else | 1099 | #else |
| 1101 | #ifdef IP_TOS | 1100 | #ifdef IP_TOS |
| 1102 | if (tos_str && setsockopt(sndsock, IPPROTO_IP, IP_TOS, | 1101 | if (tos_str && setsockopt(sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) { |
| 1103 | (char *)&tos, sizeof(tos)) < 0) { | ||
| 1104 | bb_perror_msg_and_die("setsockopt tos %d", tos); | 1102 | bb_perror_msg_and_die("setsockopt tos %d", tos); |
| 1105 | } | 1103 | } |
| 1106 | #endif | 1104 | #endif |
| 1107 | #endif | 1105 | #endif |
| 1108 | #if TRACEROUTE_SO_DEBUG | 1106 | #if TRACEROUTE_SO_DEBUG |
| 1109 | if (op & USAGE_OP_DEBUG) | 1107 | if (op & USAGE_OP_DEBUG) |
| 1110 | (void)setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, (char *)&on, | 1108 | setsockopt(sndsock, SOL_SOCKET, SO_DEBUG, |
| 1111 | sizeof(on)); | 1109 | &const_int_1, sizeof(const_int_1)); |
| 1112 | #endif | 1110 | #endif |
| 1113 | if (op & USAGE_OP_BYPASS_ROUTE) | 1111 | if (op & USAGE_OP_BYPASS_ROUTE) |
| 1114 | (void)setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, (char *)&on, | 1112 | setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE, |
| 1115 | sizeof(on)); | 1113 | &const_int_1, sizeof(const_int_1)); |
| 1116 | 1114 | ||
| 1117 | /* Revert to non-privileged user after opening sockets */ | 1115 | /* Revert to non-privileged user after opening sockets */ |
| 1118 | xsetgid(getgid()); | 1116 | 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) | |||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | strncpy(interface.ifr_name, inf, IFNAMSIZ); | 114 | strncpy(interface.ifr_name, inf, IFNAMSIZ); |
| 115 | if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, sizeof(interface)) < 0) { | 115 | if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface)) < 0) { |
| 116 | close(fd); | 116 | close(fd); |
| 117 | return -1; | 117 | return -1; |
| 118 | } | 118 | } |
diff --git a/shell/lash.c b/shell/lash.c index 4ea4e6763..90bd16885 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
| @@ -30,7 +30,7 @@ | |||
| 30 | #define CONFIG_LASH_PIPE_N_REDIRECTS | 30 | #define CONFIG_LASH_PIPE_N_REDIRECTS |
| 31 | #define CONFIG_LASH_JOB_CONTROL | 31 | #define CONFIG_LASH_JOB_CONTROL |
| 32 | 32 | ||
| 33 | static const int MAX_READ = 128; /* size of input buffer for `read' builtin */ | 33 | enum { MAX_READ = 128 }; /* size of input buffer for 'read' builtin */ |
| 34 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" | 34 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" |
| 35 | 35 | ||
| 36 | 36 | ||
