summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenys Vlasenko2020-12-13 15:58:47 +0100
committerDenys Vlasenko2020-12-13 15:58:47 +0100
commit6c5f4296dca1d836695d3ec77e7429bd40ca5ce3 (patch)
treebde73833e224991456c9f40c0a7ea0a0581c199f /networking
parent623e55a396597be7d6f3be332f28c2f0e3b09a1d (diff)
downloadbusybox-6c5f4296dca1d836695d3ec77e7429bd40ca5ce3.zip
busybox-6c5f4296dca1d836695d3ec77e7429bd40ca5ce3.tar.gz
traceroute: code shrink
function old new delta hexdump_if_verbose - 255 +255 common_traceroute_main 1668 1644 -24 hexdump 239 - -239 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/1 up/down: 255/-263) Total: -8 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r--networking/traceroute.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/networking/traceroute.c b/networking/traceroute.c
index c1eb2d9..2f4d6bb 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -602,12 +602,15 @@ pr_type(unsigned char t)
return ttab[t];
}
-static void
-hexdump(const struct icmp *icp, int len)
+static int
+hexdump_if_verbose(const struct icmp *icp, int len)
{
const unsigned char *p;
int i;
+ if (!verbose)
+ return 0;
+
printf("\n%d bytes from %s to %s: icmp type %u (%s) code %u\n",
len,
auto_string(xmalloc_sockaddr2dotted_noport(&G.from_lsa->u.sa)),
@@ -622,9 +625,10 @@ hexdump(const struct icmp *icp, int len)
printf(" %02x", p[i]);
}
bb_putchar('\n');
+ return 0;
}
#else
-# define hexdump(...) ((void)0)
+# define hexdump_if_verbose(...) 0
#endif
static int
@@ -704,9 +708,8 @@ packet4_ok(int read_len, int seq)
}
}
}
- if (verbose) /* testcase: traceroute -vI 127.0.0.1 (sees its own echo requests) */
- hexdump(icp, read_len);
- return 0;
+ /* testcase: traceroute -vI 127.0.0.1 (sees its own echo requests) */
+ return hexdump_if_verbose(icp, read_len);
}
#if ENABLE_TRACEROUTE6
@@ -767,10 +770,8 @@ packet6_ok(int read_len, int seq)
}
}
}
- if (verbose)
- /* cast is safe since the beginning of icmp4 and icmp6 layouts match */
- hexdump((const struct icmp *)icp, read_len);
- return 0;
+ /* cast is safe since the beginning of icmp4 and icmp6 layouts match */
+ return hexdump_if_verbose((const struct icmp *)icp, read_len);
}
static int