forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lc
76 lines (61 loc) · 3.8 KB
/
main.lc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "trace.h"## 1 ##src/traceroute/main.c##
struct proto proto_v4 = { icmpcode_v4, recv_v4, NULL, NULL, NULL, NULL, 0,## 2 ##src/traceroute/main.c##
IPPROTO_ICMP, IPPROTO_IP, IP_TTL## 3 ##src/traceroute/main.c##
};## 4 ##src/traceroute/main.c##
#ifdef IPV6## 5 ##src/traceroute/main.c##
struct proto proto_v6 = { icmpcode_v6, recv_v6, NULL, NULL, NULL, NULL, 0,## 6 ##src/traceroute/main.c##
IPPROTO_ICMPV6, IPPROTO_IPV6, IPV6_UNICAST_HOPS## 7 ##src/traceroute/main.c##
};## 8 ##src/traceroute/main.c##
#endif## 9 ##src/traceroute/main.c##
int datalen = sizeof(struct rec); /* defaults */## 10 ##src/traceroute/main.c##
int max_ttl = 30;## 11 ##src/traceroute/main.c##
int nprobes = 3;## 12 ##src/traceroute/main.c##
u_short dport = 32768 + 666;## 13 ##src/traceroute/main.c##
int## 14 ##src/traceroute/main.c##
main(int argc, char **argv)## 15 ##src/traceroute/main.c##
{## 16 ##src/traceroute/main.c##
int c;## 17 ##src/traceroute/main.c##
struct addrinfo *ai;## 18 ##src/traceroute/main.c##
opterr = 0; /* don't want getopt() writing to stderr */## 19 ##src/traceroute/main.c##
while ((c = getopt(argc, argv, "m:v")) != -1) {## 20 ##src/traceroute/main.c##
switch (c) {## 21 ##src/traceroute/main.c##
case 'm':## 22 ##src/traceroute/main.c##
if ((max_ttl = atoi(optarg)) <= 1)## 23 ##src/traceroute/main.c##
err_quit("invalid -m value");## 24 ##src/traceroute/main.c##
break;## 25 ##src/traceroute/main.c##
case 'v':## 26 ##src/traceroute/main.c##
verbose++;## 27 ##src/traceroute/main.c##
break;## 28 ##src/traceroute/main.c##
case '?':## 29 ##src/traceroute/main.c##
err_quit("unrecognized option: %c", c);## 30 ##src/traceroute/main.c##
}## 31 ##src/traceroute/main.c##
}## 32 ##src/traceroute/main.c##
if (optind != argc - 1)## 33 ##src/traceroute/main.c##
err_quit("usage: traceroute [ -m <maxttl> -v ] <hostname>");## 34 ##src/traceroute/main.c##
host = argv[optind];## 35 ##src/traceroute/main.c##
pid = getpid();## 36 ##src/traceroute/main.c##
Signal(SIGALRM, sig_alrm);## 37 ##src/traceroute/main.c##
ai = Host_serv(host, NULL, 0, 0);## 38 ##src/traceroute/main.c##
printf("traceroute to %s (%s): %d hops max, %d data bytes\n",## 39 ##src/traceroute/main.c##
ai->ai_canonname,## 40 ##src/traceroute/main.c##
Sock_ntop_host(ai->ai_addr, ai->ai_addrlen), max_ttl, datalen);## 41 ##src/traceroute/main.c##
/* initialize according to protocol */## 42 ##src/traceroute/main.c##
if (ai->ai_family == AF_INET) {## 43 ##src/traceroute/main.c##
pr = &proto_v4;## 44 ##src/traceroute/main.c##
#ifdef IPV6## 45 ##src/traceroute/main.c##
} else if (ai->ai_family == AF_INET6) {## 46 ##src/traceroute/main.c##
pr = &proto_v6;## 47 ##src/traceroute/main.c##
if (IN6_IS_ADDR_V4MAPPED## 48 ##src/traceroute/main.c##
(&(((struct sockaddr_in6 *) ai->ai_addr)->sin6_addr)))## 49 ##src/traceroute/main.c##
err_quit("cannot traceroute IPv4-mapped IPv6 address");## 50 ##src/traceroute/main.c##
#endif## 51 ##src/traceroute/main.c##
} else## 52 ##src/traceroute/main.c##
err_quit("unknown address family %d", ai->ai_family);## 53 ##src/traceroute/main.c##
pr->sasend = ai->ai_addr; /* contains destination address */## 54 ##src/traceroute/main.c##
pr->sarecv = Calloc(1, ai->ai_addrlen);## 55 ##src/traceroute/main.c##
pr->salast = Calloc(1, ai->ai_addrlen);## 56 ##src/traceroute/main.c##
pr->sabind = Calloc(1, ai->ai_addrlen);## 57 ##src/traceroute/main.c##
pr->salen = ai->ai_addrlen;## 58 ##src/traceroute/main.c##
traceloop();## 59 ##src/traceroute/main.c##
exit(0);## 60 ##src/traceroute/main.c##
}## 61 ##src/traceroute/main.c##