aboutsummaryrefslogtreecommitdiff
path: root/networking/traceroute.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 14:12:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 14:12:08 +0000
commit703e20235aa0624d3ff4335c1e86edaa6e21efe2 (patch)
tree49e8451efad93b75c0be74ee553d3b3f8c04a25d /networking/traceroute.c
parent6cd2d2bcba37a13d0d73326dd7bca64bbccce4f8 (diff)
downloadbusybox-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.
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r--networking/traceroute.c40
1 files changed, 19 insertions, 21 deletions
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)
888int 889int
889traceroute_main(int argc, char *argv[]) 890traceroute_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());