summaryrefslogtreecommitdiff
path: root/usr.sbin/traceroute6
diff options
context:
space:
mode:
authorFlorian Obser <florian@cvs.openbsd.org>2014-04-18 16:23:01 +0000
committerFlorian Obser <florian@cvs.openbsd.org>2014-04-18 16:23:01 +0000
commit281acc5c1ebab830624d98308758a77996fb5ee4 (patch)
treea72871f661a1aa02a91d666d19686a19805188d7 /usr.sbin/traceroute6
parenta7f553acf6bd75d8b03ba4c313e6c54730cb284f (diff)
move ICMP6 code parsing to function
OK benno@
Diffstat (limited to 'usr.sbin/traceroute6')
-rw-r--r--usr.sbin/traceroute6/traceroute6.c65
1 files 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.
*/