diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2016-09-11 18:18:26 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2016-09-11 18:18:26 +0000 |
commit | 5cee5cff0a08c25fa4265c04e26da9c8a3658ccd (patch) | |
tree | bbd265081ccc14430ef747268c82e0c9d2925819 | |
parent | b916416f09b70061d44c2ba5ca9bcbd5d077c92a (diff) |
Hoist fill() up, it's AF independent; no obj change.
Diff between ping and ping6 is easier to read if all identical
or as close as possible to being identical functions are in one place.
-rw-r--r-- | sbin/ping/ping.c | 62 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 63 |
2 files changed, 62 insertions, 63 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index bb904909353..d53c50abfb9 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.168 2016/09/11 18:04:07 florian Exp $ */ +/* $OpenBSD: ping.c,v 1.169 2016/09/11 18:18:25 florian Exp $ */ /* $NetBSD: ping.c,v 1.20 1995/08/11 22:37:58 cgd Exp $ */ /* @@ -651,6 +651,36 @@ onsignal(int sig) } } +void +fill(char *bp, char *patp) +{ + int ii, jj, kk; + int pat[16]; + char *cp; + + for (cp = patp; *cp; cp++) + if (!isxdigit((unsigned char)*cp)) + errx(1, "patterns must be specified as hex digits"); + ii = sscanf(patp, + "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", + &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6], + &pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12], + &pat[13], &pat[14], &pat[15]); + + if (ii > 0) + for (kk = 0; + kk <= MAXPAYLOAD - (8 + sizeof(struct payload) + ii); + kk += ii) + for (jj = 0; jj < ii; ++jj) + bp[jj + kk] = pat[jj]; + if (!(options & F_QUIET)) { + (void)printf("PATTERN: 0x"); + for (jj = 0; jj < ii; ++jj) + (void)printf("%02x", bp[jj] & 0xFF); + (void)printf("\n"); + } +} + /* * retransmit -- * This routine transmits another ping. @@ -1334,36 +1364,6 @@ pr_retip(struct ip *ip) (*cp * 256 + *(cp + 1)), (*(cp + 2) * 256 + *(cp + 3))); } -void -fill(char *bp, char *patp) -{ - int ii, jj, kk; - int pat[16]; - char *cp; - - for (cp = patp; *cp; cp++) - if (!isxdigit((unsigned char)*cp)) - errx(1, "patterns must be specified as hex digits"); - ii = sscanf(patp, - "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", - &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6], - &pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12], - &pat[13], &pat[14], &pat[15]); - - if (ii > 0) - for (kk = 0; - kk <= MAXPAYLOAD - (8 + sizeof(struct payload) + ii); - kk += ii) - for (jj = 0; jj < ii; ++jj) - bp[jj + kk] = pat[jj]; - if (!(options & F_QUIET)) { - (void)printf("PATTERN: 0x"); - for (jj = 0; jj < ii; ++jj) - (void)printf("%02x", bp[jj] & 0xFF); - (void)printf("\n"); - } -} - #ifndef SMALL int map_tos(char *key, int *val) diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index b70b404445f..08173162212 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.173 2016/09/11 18:16:12 florian Exp $ */ +/* $OpenBSD: ping6.c,v 1.174 2016/09/11 18:18:25 florian Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -755,6 +755,36 @@ onsignal(int sig) } } +void +fill(char *bp, char *patp) +{ + int ii, jj, kk; + int pat[16]; + char *cp; + + for (cp = patp; *cp; cp++) + if (!isxdigit((unsigned char)*cp)) + errx(1, "patterns must be specified as hex digits"); + ii = sscanf(patp, + "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", + &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6], + &pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12], + &pat[13], &pat[14], &pat[15]); + + if (ii > 0) + for (kk = 0; + kk <= MAXPAYLOAD - (8 + sizeof(struct payload) + ii); + kk += ii) + for (jj = 0; jj < ii; ++jj) + bp[jj + kk] = pat[jj]; + if (!(options & F_QUIET)) { + (void)printf("PATTERN: 0x"); + for (jj = 0; jj < ii; ++jj) + (void)printf("%02x", bp[jj] & 0xFF); + (void)printf("\n"); + } +} + /* * retransmit -- * This routine transmits another ping6. @@ -1510,37 +1540,6 @@ pr_retip(struct ip6_hdr *ip6, u_char *end) return; } -void -fill(char *bp, char *patp) -{ - int ii, jj, kk; - int pat[16]; - char *cp; - - for (cp = patp; *cp; cp++) - if (!isxdigit((unsigned char)*cp)) - errx(1, "patterns must be specified as hex digits"); - ii = sscanf(patp, - "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", - &pat[0], &pat[1], &pat[2], &pat[3], &pat[4], &pat[5], &pat[6], - &pat[7], &pat[8], &pat[9], &pat[10], &pat[11], &pat[12], - &pat[13], &pat[14], &pat[15]); - -/* xxx */ - if (ii > 0) - for (kk = 0; - kk <= MAXPAYLOAD - (8 + sizeof(struct payload) + ii); - kk += ii) - for (jj = 0; jj < ii; ++jj) - bp[jj + kk] = pat[jj]; - if (!(options & F_QUIET)) { - (void)printf("PATTERN: 0x"); - for (jj = 0; jj < ii; ++jj) - (void)printf("%02x", bp[jj] & 0xFF); - (void)printf("\n"); - } -} - __dead void usage(void) { |