diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-04-10 19:06:34 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2018-04-10 19:06:34 +0200 |
commit | 0272fa04fd5da396d5f2b29d8c6c988822d2147b (patch) | |
tree | 3556fd850336ffbbbdb345691bb0964f405b53a1 /sys/src/cmd/ip/traceroute.c | |
parent | 3e60d7127d8bec7c5ac1361881c173ed0daf422e (diff) |
ip/traceroute: icmpv6 support
Diffstat (limited to 'sys/src/cmd/ip/traceroute.c')
-rw-r--r-- | sys/src/cmd/ip/traceroute.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/sys/src/cmd/ip/traceroute.c b/sys/src/cmd/ip/traceroute.c index 3113d6ded..186e3662d 100644 --- a/sys/src/cmd/ip/traceroute.c +++ b/sys/src/cmd/ip/traceroute.c @@ -180,9 +180,8 @@ udpprobe(int cfd, int dfd, char *dest, int interval) #define MSG "traceroute probe" #define MAGIC 0xdead -/* ICMPv4 only */ static int -icmpprobe(int cfd, int dfd, char *dest, int interval) +icmpprobe(int cfd, int dfd, int version, char *dest, int interval) { int x, i, n, len, rv; char buf[512], err[ERRMAX], msg[Maxstring]; @@ -194,15 +193,16 @@ icmpprobe(int cfd, int dfd, char *dest, int interval) return -1; rv = -1; - ip = (Icmphdr *)(buf + IPV4HDR_LEN); + len = (version == 4)? IPV4HDR_LEN: IPV6HDR_LEN; + ip = (Icmphdr *)(buf + len); + len += ICMP_HDRSIZE + sizeof(MSG); for(i = 0; i < 3; i++){ alarm(interval/3); - ip->type = EchoRequest; + ip->type = (version == 4)? EchoRequest: EchoRequestV6; ip->code = 0; strcpy((char*)ip->data, MSG); ip->seq[0] = MAGIC; ip->seq[1] = MAGIC>>8; - len = IPV4HDR_LEN + ICMP_HDRSIZE + sizeof(MSG); /* send a request */ if(write(dfd, buf, len) < len) @@ -222,7 +222,7 @@ icmpprobe(int cfd, int dfd, char *dest, int interval) continue; } x = (ip->seq[1]<<8) | ip->seq[0]; - if(n >= len && ip->type == EchoReply && x == MAGIC && + if(n >= len && ip->type == ((version == 4)? EchoReply: EchoReplyV6) && x == MAGIC && strcmp((char*)ip->data, MSG) == 0){ rv = 0; break; @@ -283,7 +283,9 @@ call(DS *ds, char *clone, char *dest, int ttl, long *interval) if(strcmp(ds->proto, "udp") == 0) rv = udpprobe(cfd, dfd, dest, 3000); else if(strcmp(ds->proto, "icmp") == 0) - rv = icmpprobe(cfd, dfd, dest, 3000); + rv = icmpprobe(cfd, dfd, 4, dest, 3000); + else if(strcmp(ds->proto, "icmpv6") == 0) + rv = icmpprobe(cfd, dfd, 6, dest, 3000); else /* il and tcp */ rv = tcpilprobe(cfd, dfd, dest, 3000); out: |