diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-10-10 12:55:06 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-10-11 09:29:33 +0200 |
commit | 104304864887f0e3765bb28333dc7b9bd991aa4f (patch) | |
tree | c1472d363822507fba1cebca8fb18f611accd51b /freebsd/contrib/tcpdump/print-dvmrp.c | |
parent | Update CONTRIBUTING.md (diff) | |
download | rtems-libbsd-104304864887f0e3765bb28333dc7b9bd991aa4f.tar.bz2 |
tcpdump: Update to FreeBSD head 2017-04-04
Update tcpdump from Git mirror commit
99a648a912e81e29d9c4c159cbbe263462f2d719 to
642b174daddbd0efd9bb5f242c43f4ab4db6869f.
Diffstat (limited to 'freebsd/contrib/tcpdump/print-dvmrp.c')
-rw-r--r-- | freebsd/contrib/tcpdump/print-dvmrp.c | 210 |
1 files changed, 107 insertions, 103 deletions
diff --git a/freebsd/contrib/tcpdump/print-dvmrp.c b/freebsd/contrib/tcpdump/print-dvmrp.c index 4f553b7d..894f08db 100644 --- a/freebsd/contrib/tcpdump/print-dvmrp.c +++ b/freebsd/contrib/tcpdump/print-dvmrp.c @@ -1,5 +1,8 @@ #include <machine/rtems-bsd-user-space.h> - +#ifdef __rtems__ +#include <machine/rtems-bsd-program.h> +#include "rtems-bsd-tcpdump-namespace.h" +#endif /* __rtems__ */ /* * Copyright (c) 1995, 1996 * The Regents of the University of California. All rights reserved. @@ -21,22 +24,15 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-dvmrp.c,v 1.27 2003-11-19 09:42:04 guy Exp $ (LBL)"; -#endif +/* \summary: Distance Vector Multicast Routing Protocol printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include <tcpdump-stdinc.h> +#include <netdissect-stdinc.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "addrtoname.h" @@ -64,27 +60,28 @@ static const char rcsid[] _U_ = #define DVMRP_NF_DISABLED 0x20 /* administratively disabled */ #define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */ -static int print_probe(const u_char *, const u_char *, u_int); -static int print_report(const u_char *, const u_char *, u_int); -static int print_neighbors(const u_char *, const u_char *, u_int); -static int print_neighbors2(const u_char *, const u_char *, u_int); -static int print_prune(const u_char *); -static int print_graft(const u_char *); -static int print_graft_ack(const u_char *); +static int print_probe(netdissect_options *, const u_char *, const u_char *, u_int); +static int print_report(netdissect_options *, const u_char *, const u_char *, u_int); +static int print_neighbors(netdissect_options *, const u_char *, const u_char *, u_int); +static int print_neighbors2(netdissect_options *, const u_char *, const u_char *, u_int); +static int print_prune(netdissect_options *, const u_char *); +static int print_graft(netdissect_options *, const u_char *); +static int print_graft_ack(netdissect_options *, const u_char *); -static u_int32_t target_level; +static uint32_t target_level; void -dvmrp_print(register const u_char *bp, register u_int len) +dvmrp_print(netdissect_options *ndo, + register const u_char *bp, register u_int len) { register const u_char *ep; register u_char type; - ep = (const u_char *)snapend; + ep = (const u_char *)ndo->ndo_snapend; if (bp >= ep) return; - TCHECK(bp[1]); + ND_TCHECK(bp[1]); type = bp[1]; /* Skip IGMP header */ @@ -94,94 +91,95 @@ dvmrp_print(register const u_char *bp, register u_int len) switch (type) { case DVMRP_PROBE: - printf(" Probe"); - if (vflag) { - if (print_probe(bp, ep, len) < 0) + ND_PRINT((ndo, " Probe")); + if (ndo->ndo_vflag) { + if (print_probe(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_REPORT: - printf(" Report"); - if (vflag > 1) { - if (print_report(bp, ep, len) < 0) + ND_PRINT((ndo, " Report")); + if (ndo->ndo_vflag > 1) { + if (print_report(ndo, bp, ep, len) < 0) goto trunc; } break; case DVMRP_ASK_NEIGHBORS: - printf(" Ask-neighbors(old)"); + ND_PRINT((ndo, " Ask-neighbors(old)")); break; case DVMRP_NEIGHBORS: - printf(" Neighbors(old)"); - if (print_neighbors(bp, ep, len) < 0) + ND_PRINT((ndo, " Neighbors(old)")); + if (print_neighbors(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_ASK_NEIGHBORS2: - printf(" Ask-neighbors2"); + ND_PRINT((ndo, " Ask-neighbors2")); break; case DVMRP_NEIGHBORS2: - printf(" Neighbors2"); + ND_PRINT((ndo, " Neighbors2")); /* * extract version and capabilities from IGMP group * address field */ bp -= 4; - TCHECK2(bp[0], 4); + ND_TCHECK2(bp[0], 4); target_level = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; bp += 4; - if (print_neighbors2(bp, ep, len) < 0) + if (print_neighbors2(ndo, bp, ep, len) < 0) goto trunc; break; case DVMRP_PRUNE: - printf(" Prune"); - if (print_prune(bp) < 0) + ND_PRINT((ndo, " Prune")); + if (print_prune(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT: - printf(" Graft"); - if (print_graft(bp) < 0) + ND_PRINT((ndo, " Graft")); + if (print_graft(ndo, bp) < 0) goto trunc; break; case DVMRP_GRAFT_ACK: - printf(" Graft-ACK"); - if (print_graft_ack(bp) < 0) + ND_PRINT((ndo, " Graft-ACK")); + if (print_graft_ack(ndo, bp) < 0) goto trunc; break; default: - printf(" [type %d]", type); + ND_PRINT((ndo, " [type %d]", type)); break; } return; trunc: - printf("[|dvmrp]"); + ND_PRINT((ndo, "[|dvmrp]")); return; } -static int -print_report(register const u_char *bp, register const u_char *ep, - register u_int len) +static int +print_report(netdissect_options *ndo, + register const u_char *bp, register const u_char *ep, + register u_int len) { - register u_int32_t mask, origin; + register uint32_t mask, origin; register int metric, done; register u_int i, width; while (len > 0) { if (len < 3) { - printf(" [|]"); + ND_PRINT((ndo, " [|]")); return (0); } - TCHECK2(bp[0], 3); - mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2]; + ND_TCHECK2(bp[0], 3); + mask = (uint32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2]; width = 1; if (bp[0]) width = 2; @@ -190,32 +188,32 @@ print_report(register const u_char *bp, register const u_char *ep, if (bp[2]) width = 4; - printf("\n\tMask %s", intoa(htonl(mask))); + ND_PRINT((ndo, "\n\tMask %s", intoa(htonl(mask)))); bp += 3; len -= 3; do { if (bp + width + 1 > ep) { - printf(" [|]"); + ND_PRINT((ndo, " [|]")); return (0); } if (len < width + 1) { - printf("\n\t [Truncated Report]"); + ND_PRINT((ndo, "\n\t [Truncated Report]")); return (0); } origin = 0; for (i = 0; i < width; ++i) { - TCHECK(*bp); + ND_TCHECK(*bp); origin = origin << 8 | *bp++; } for ( ; i < 4; ++i) origin <<= 8; - TCHECK(*bp); + ND_TCHECK(*bp); metric = *bp++; done = metric & 0x80; metric &= 0x7f; - printf("\n\t %s metric %d", intoa(htonl(origin)), - metric); + ND_PRINT((ndo, "\n\t %s metric %d", intoa(htonl(origin)), + metric)); len -= width + 1; } while (!done); } @@ -225,31 +223,29 @@ trunc: } static int -print_probe(register const u_char *bp, register const u_char *ep, - register u_int len) +print_probe(netdissect_options *ndo, + register const u_char *bp, register const u_char *ep, + register u_int len) { - register u_int32_t genid; + register uint32_t genid; - TCHECK2(bp[0], 4); + ND_TCHECK2(bp[0], 4); if ((len < 4) || ((bp + 4) > ep)) { /* { (ctags) */ - printf(" [|}"); + ND_PRINT((ndo, " [|}")); return (0); } genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; bp += 4; len -= 4; - if (vflag > 1) - printf("\n\t"); - else - printf(" "); - printf("genid %u", genid); - if (vflag < 2) + ND_PRINT((ndo, ndo->ndo_vflag > 1 ? "\n\t" : " ")); + ND_PRINT((ndo, "genid %u", genid)); + if (ndo->ndo_vflag < 2) return (0); while ((len > 0) && (bp < ep)) { - TCHECK2(bp[0], 4); - printf("\n\tneighbor %s", ipaddr_string(bp)); + ND_TCHECK2(bp[0], 4); + ND_PRINT((ndo, "\n\tneighbor %s", ipaddr_string(ndo, bp))); bp += 4; len -= 4; } return (0); @@ -258,8 +254,9 @@ trunc: } static int -print_neighbors(register const u_char *bp, register const u_char *ep, - register u_int len) +print_neighbors(netdissect_options *ndo, + register const u_char *bp, register const u_char *ep, + register u_int len) { const u_char *laddr; register u_char metric; @@ -267,7 +264,7 @@ print_neighbors(register const u_char *bp, register const u_char *ep, register int ncount; while (len > 0 && bp < ep) { - TCHECK2(bp[0], 7); + ND_TCHECK2(bp[0], 7); laddr = bp; bp += 4; metric = *bp++; @@ -275,10 +272,10 @@ print_neighbors(register const u_char *bp, register const u_char *ep, ncount = *bp++; len -= 7; while (--ncount >= 0) { - TCHECK2(bp[0], 4); - printf(" [%s ->", ipaddr_string(laddr)); - printf(" %s, (%d/%d)]", - ipaddr_string(bp), metric, thresh); + ND_TCHECK2(bp[0], 4); + ND_PRINT((ndo, " [%s ->", ipaddr_string(ndo, laddr))); + ND_PRINT((ndo, " %s, (%d/%d)]", + ipaddr_string(ndo, bp), metric, thresh)); bp += 4; len -= 4; } @@ -289,19 +286,20 @@ trunc: } static int -print_neighbors2(register const u_char *bp, register const u_char *ep, - register u_int len) +print_neighbors2(netdissect_options *ndo, + register const u_char *bp, register const u_char *ep, + register u_int len) { const u_char *laddr; register u_char metric, thresh, flags; register int ncount; - printf(" (v %d.%d):", + ND_PRINT((ndo, " (v %d.%d):", (int)target_level & 0xff, - (int)(target_level >> 8) & 0xff); + (int)(target_level >> 8) & 0xff)); while (len > 0 && bp < ep) { - TCHECK2(bp[0], 8); + ND_TCHECK2(bp[0], 8); laddr = bp; bp += 4; metric = *bp++; @@ -310,25 +308,25 @@ print_neighbors2(register const u_char *bp, register const u_char *ep, ncount = *bp++; len -= 8; while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) { - printf(" [%s -> ", ipaddr_string(laddr)); - printf("%s (%d/%d", ipaddr_string(bp), - metric, thresh); + ND_PRINT((ndo, " [%s -> ", ipaddr_string(ndo, laddr))); + ND_PRINT((ndo, "%s (%d/%d", ipaddr_string(ndo, bp), + metric, thresh)); if (flags & DVMRP_NF_TUNNEL) - printf("/tunnel"); + ND_PRINT((ndo, "/tunnel")); if (flags & DVMRP_NF_SRCRT) - printf("/srcrt"); + ND_PRINT((ndo, "/srcrt")); if (flags & DVMRP_NF_QUERIER) - printf("/querier"); + ND_PRINT((ndo, "/querier")); if (flags & DVMRP_NF_DISABLED) - printf("/disabled"); + ND_PRINT((ndo, "/disabled")); if (flags & DVMRP_NF_DOWN) - printf("/down"); - printf(")]"); + ND_PRINT((ndo, "/down")); + ND_PRINT((ndo, ")]")); bp += 4; len -= 4; } if (ncount != -1) { - printf(" [|]"); + ND_PRINT((ndo, " [|]")); return (0); } } @@ -338,34 +336,40 @@ trunc: } static int -print_prune(register const u_char *bp) +print_prune(netdissect_options *ndo, + register const u_char *bp) { - TCHECK2(bp[0], 12); - printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); + ND_TCHECK2(bp[0], 12); + ND_PRINT((ndo, " src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4))); bp += 8; - (void)printf(" timer "); - relts_print(EXTRACT_32BITS(bp)); + ND_PRINT((ndo, " timer ")); + unsigned_relts_print(ndo, EXTRACT_32BITS(bp)); return (0); trunc: return (-1); } static int -print_graft(register const u_char *bp) +print_graft(netdissect_options *ndo, + register const u_char *bp) { - TCHECK2(bp[0], 8); - printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); + ND_TCHECK2(bp[0], 8); + ND_PRINT((ndo, " src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4))); return (0); trunc: return (-1); } static int -print_graft_ack(register const u_char *bp) +print_graft_ack(netdissect_options *ndo, + register const u_char *bp) { - TCHECK2(bp[0], 8); - printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); + ND_TCHECK2(bp[0], 8); + ND_PRINT((ndo, " src %s grp %s", ipaddr_string(ndo, bp), ipaddr_string(ndo, bp + 4))); return (0); trunc: return (-1); } +#ifdef __rtems__ +#include "rtems-bsd-tcpdump-print-dvmrp-data.h" +#endif /* __rtems__ */ |