From 5518f64fd5ce2ce9f8b008cb0eececade6768333 Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 18 Apr 2014 16:23:00 +0000 Subject: [PATCH] move ICMP6 code parsing to function OK benno@ --- usr.sbin/traceroute6/traceroute6.c | 65 +++++++++++++++++------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c index db6198a431f..6af5ccf9e12 100644 --- a/usr.sbin/traceroute6/traceroute6.c +++ b/usr.sbin/traceroute6/traceroute6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traceroute6.c,v 1.75 2014/04/18 16:20:56 florian Exp $ */ +/* $OpenBSD: traceroute6.c,v 1.76 2014/04/18 16:23:00 florian Exp $ */ /* $KAME: traceroute6.c,v 1.63 2002/10/24 12:53:25 itojun Exp $ */ /* @@ -292,6 +292,7 @@ int get_hoplim(struct msghdr *); double deltaT(struct timeval *, struct timeval *); char *pr_type(int); int packet_ok(struct msghdr *, int, int, int); +void icmp6_code(int, int *, int *); void print(struct sockaddr *, int, const char *); const char *inetname(struct sockaddr *); void print_asn(struct sockaddr_storage *); @@ -731,34 +732,8 @@ main(int argc, char *argv[]) /* time exceeded in transit */ if (i == -1) break; - switch (i - 1) { - case ICMP6_DST_UNREACH_NOROUTE: - ++unreachable; - printf(" !N"); - break; - case ICMP6_DST_UNREACH_ADMIN: - ++unreachable; - printf(" !P"); - break; - case ICMP6_DST_UNREACH_NOTNEIGHBOR: - ++unreachable; - printf(" !S"); - break; - case ICMP6_DST_UNREACH_ADDR: - ++unreachable; - printf(" !A"); - break; - case ICMP6_DST_UNREACH_NOPORT: - if (rcvhlim >= 0 && - rcvhlim <= 1) - printf(" !"); - ++got_there; - break; - default: - ++unreachable; - printf(" !<%d>", i - 1); - break; - } + icmp6_code(i - 1, &got_there, + &unreachable); break; } } @@ -1120,6 +1095,38 @@ print(struct sockaddr *from, int cc, const char *to) printf(" %d bytes to %s", cc, to); } +void +icmp6_code(int code, int *got_there, int *unreachable) +{ + switch (code) { + case ICMP6_DST_UNREACH_NOROUTE: + ++(*unreachable); + printf(" !N"); + break; + case ICMP6_DST_UNREACH_ADMIN: + ++(*unreachable); + printf(" !P"); + break; + case ICMP6_DST_UNREACH_NOTNEIGHBOR: + ++(*unreachable); + printf(" !S"); + break; + case ICMP6_DST_UNREACH_ADDR: + ++(*unreachable); + printf(" !A"); + break; + case ICMP6_DST_UNREACH_NOPORT: + if (rcvhlim >= 0 && rcvhlim <= 1) + printf(" !"); + ++(*got_there); + break; + default: + ++(*unreachable); + printf(" !<%d>", code); + break; + } +} + /* * Construct an Internet address representation. */ -- 2.20.1