diff options
author | Denis Vlasenko | 2007-09-07 13:43:28 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-09-07 13:43:28 +0000 |
commit | 87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch) | |
tree | 2f7fe9fc910d5e97f695c902f848db497fec8bfd /networking/traceroute.c | |
parent | 40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff) | |
download | busybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.zip busybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.gz |
*: replace select-for-one descriptor with poll, it's smaller.
$ ./.cmk bloatcheck
function old new delta
readit 406 364 -42
syslogd_main 1249 1206 -43
traceroute_main 4115 4060 -55
mysleep 112 45 -67
arpping 579 441 -138
tftp 1575 1182 -393
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-738) Total: -738 bytes
text data bss dec hex filename
770580 1051 10764 782395 bf03b busybox_old
769820 1051 10764 781635 bed43 busybox_unstripped
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r-- | networking/traceroute.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c index 236ddbd..21921e5 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -346,10 +346,10 @@ static int optlen; /* length of ip options */ struct globals { - /* last inbound (icmp) packet */ - unsigned char packet[512]; struct sockaddr_storage whereto; /* Who to try to reach */ struct sockaddr_storage wherefrom; /* Who we are */ + /* last inbound (icmp) packet */ + unsigned char packet[512]; #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE /* Maximum number of gateways (include room for one noop) */ #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t))) @@ -359,7 +359,7 @@ struct globals { }; #define G (*ptr_to_globals) - +#define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G)) #define packet (G.packet ) #define whereto (G.whereto ) #define wherefrom (G.wherefrom) @@ -537,21 +537,15 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) static int wait_for_reply(int sock, struct sockaddr_in *fromp) { - fd_set fds; - struct timeval tvwait; + struct pollfd pfd[1]; int cc = 0; socklen_t fromlen = sizeof(*fromp); - FD_ZERO(&fds); - FD_SET(sock, &fds); - - tvwait.tv_sec = waittime; - tvwait.tv_usec = 0; - - if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) - cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, + pfd[0].fd = sock; + pfd[0].events = POLLIN; + if (poll(pfd, 1, waittime * 1000) > 0) + cc = recvfrom(sock, packet, sizeof(packet), 0, (struct sockaddr *)fromp, &fromlen); - return cc; } @@ -930,7 +924,7 @@ int traceroute_main(int argc, char **argv) llist_t *source_route_list = NULL; #endif - PTR_TO_GLOBALS = xzalloc(sizeof(G)); + INIT_G(); from = (struct sockaddr_in *)&wherefrom; to = (struct sockaddr_in *)&whereto; |