diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-07 13:43:28 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-09-07 13:43:28 +0000 |
commit | 87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch) | |
tree | 2f7fe9fc910d5e97f695c902f848db497fec8bfd /networking/traceroute.c | |
parent | 40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff) | |
download | busybox-w32-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.gz busybox-w32-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.bz2 busybox-w32-87f3b26b3a17369c12f4f9a70d6845796f8648d6.zip |
*: 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 236ddbdaf..21921e56d 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -346,10 +346,10 @@ static int optlen; /* length of ip options */ | |||
346 | 346 | ||
347 | 347 | ||
348 | struct globals { | 348 | struct globals { |
349 | /* last inbound (icmp) packet */ | ||
350 | unsigned char packet[512]; | ||
351 | struct sockaddr_storage whereto; /* Who to try to reach */ | 349 | struct sockaddr_storage whereto; /* Who to try to reach */ |
352 | struct sockaddr_storage wherefrom; /* Who we are */ | 350 | struct sockaddr_storage wherefrom; /* Who we are */ |
351 | /* last inbound (icmp) packet */ | ||
352 | unsigned char packet[512]; | ||
353 | #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE | 353 | #if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE |
354 | /* Maximum number of gateways (include room for one noop) */ | 354 | /* Maximum number of gateways (include room for one noop) */ |
355 | #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t))) | 355 | #define NGATEWAYS ((int)((MAX_IPOPTLEN - IPOPT_MINOFF - 1) / sizeof(uint32_t))) |
@@ -359,7 +359,7 @@ struct globals { | |||
359 | }; | 359 | }; |
360 | 360 | ||
361 | #define G (*ptr_to_globals) | 361 | #define G (*ptr_to_globals) |
362 | 362 | #define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G)) | |
363 | #define packet (G.packet ) | 363 | #define packet (G.packet ) |
364 | #define whereto (G.whereto ) | 364 | #define whereto (G.whereto ) |
365 | #define wherefrom (G.wherefrom) | 365 | #define wherefrom (G.wherefrom) |
@@ -537,21 +537,15 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from) | |||
537 | static int | 537 | static int |
538 | wait_for_reply(int sock, struct sockaddr_in *fromp) | 538 | wait_for_reply(int sock, struct sockaddr_in *fromp) |
539 | { | 539 | { |
540 | fd_set fds; | 540 | struct pollfd pfd[1]; |
541 | struct timeval tvwait; | ||
542 | int cc = 0; | 541 | int cc = 0; |
543 | socklen_t fromlen = sizeof(*fromp); | 542 | socklen_t fromlen = sizeof(*fromp); |
544 | 543 | ||
545 | FD_ZERO(&fds); | 544 | pfd[0].fd = sock; |
546 | FD_SET(sock, &fds); | 545 | pfd[0].events = POLLIN; |
547 | 546 | if (poll(pfd, 1, waittime * 1000) > 0) | |
548 | tvwait.tv_sec = waittime; | 547 | cc = recvfrom(sock, packet, sizeof(packet), 0, |
549 | tvwait.tv_usec = 0; | ||
550 | |||
551 | if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) | ||
552 | cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, | ||
553 | (struct sockaddr *)fromp, &fromlen); | 548 | (struct sockaddr *)fromp, &fromlen); |
554 | |||
555 | return cc; | 549 | return cc; |
556 | } | 550 | } |
557 | 551 | ||
@@ -930,7 +924,7 @@ int traceroute_main(int argc, char **argv) | |||
930 | llist_t *source_route_list = NULL; | 924 | llist_t *source_route_list = NULL; |
931 | #endif | 925 | #endif |
932 | 926 | ||
933 | PTR_TO_GLOBALS = xzalloc(sizeof(G)); | 927 | INIT_G(); |
934 | from = (struct sockaddr_in *)&wherefrom; | 928 | from = (struct sockaddr_in *)&wherefrom; |
935 | to = (struct sockaddr_in *)&whereto; | 929 | to = (struct sockaddr_in *)&whereto; |
936 | 930 | ||