summaryrefslogtreecommitdiffhomepage
path: root/networking/traceroute.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/traceroute.c')
-rw-r--r--networking/traceroute.c24
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 */
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;