From 3d68813784772fb7b8b0489e7b8b6cb10700d49b Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 18 Apr 2014 16:58:02 +0000 Subject: [PATCH] Declare socklen_t len in main, it's used in two places, no need to declare it twice. We can get rid of a { } block. OK benno@ --- usr.sbin/traceroute/traceroute.c | 15 ++++++--------- usr.sbin/traceroute6/traceroute6.c | 16 ++++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/usr.sbin/traceroute/traceroute.c b/usr.sbin/traceroute/traceroute.c index 34709f8d1eb..650059ea6cb 100644 --- a/usr.sbin/traceroute/traceroute.c +++ b/usr.sbin/traceroute/traceroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traceroute.c,v 1.106 2014/04/18 16:46:18 florian Exp $ */ +/* $OpenBSD: traceroute.c,v 1.107 2014/04/18 16:58:02 florian Exp $ */ /* $NetBSD: traceroute.c,v 1.10 1995/05/21 15:50:45 mycroft Exp $ */ /*- @@ -328,6 +328,7 @@ main(int argc, char *argv[]) long l; uid_t uid; u_int rtableid; + socklen_t len; if ((rcvsock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0) err(5, "icmp socket"); @@ -625,7 +626,6 @@ main(int argc, char *argv[]) } else { struct sockaddr_in nxt; int dummy; - socklen_t len; nxt = to; nxt.sin_port = htons(DUMMY_PORT); @@ -642,14 +642,11 @@ main(int argc, char *argv[]) if (bind(sndsock, (struct sockaddr *)&from, sizeof(from)) < 0) err(1, "bind sndsock"); - { - socklen_t len; + len = sizeof(from); + if (getsockname(sndsock, (struct sockaddr *)&from, &len) < 0) + err(1, "getsockname"); + srcport = ntohs(from.sin_port); - len = sizeof(from); - if (getsockname(sndsock, (struct sockaddr *)&from, &len) < 0) - err(1, "getsockname"); - srcport = ntohs(from.sin_port); - } fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to.sin_addr)); if (source) diff --git a/usr.sbin/traceroute6/traceroute6.c b/usr.sbin/traceroute6/traceroute6.c index 64144cf0f5d..5983d92a96a 100644 --- a/usr.sbin/traceroute6/traceroute6.c +++ b/usr.sbin/traceroute6/traceroute6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: traceroute6.c,v 1.81 2014/04/18 16:56:25 florian Exp $ */ +/* $OpenBSD: traceroute6.c,v 1.82 2014/04/18 16:58:02 florian Exp $ */ /* $KAME: traceroute6.c,v 1.63 2002/10/24 12:53:25 itojun Exp $ */ /* @@ -345,6 +345,7 @@ main(int argc, char *argv[]) uid_t uid; int rtableid = -1; const char *errstr; + socklen_t len; /* * Receive ICMP @@ -575,7 +576,6 @@ main(int argc, char *argv[]) } else { struct sockaddr_in6 Nxt; int dummy; - socklen_t len; Nxt = to; Nxt.sin6_port = htons(DUMMY_PORT); @@ -593,14 +593,10 @@ main(int argc, char *argv[]) if (bind(sndsock, (struct sockaddr *)&from, from.sin6_len) < 0) err(1, "bind sndsock"); - { - socklen_t len; - - len = sizeof(from); - if (getsockname(sndsock, (struct sockaddr *)&from, &len) < 0) - err(1, "getsockname"); - srcport = ntohs(from.sin6_port); - } + len = sizeof(from); + if (getsockname(sndsock, (struct sockaddr *)&from, &len) < 0) + err(1, "getsockname"); + srcport = ntohs(from.sin6_port); /* * Message to users -- 2.20.1