diff --git a/usr.sbin/tcpdump/gmt2local.c b/usr.sbin/tcpdump/gmt2local.c new file mode 100644 index 000000000000..f521085aff79 --- /dev/null +++ b/usr.sbin/tcpdump/gmt2local.c @@ -0,0 +1,79 @@ +/* $NetBSD: gmt2local.c,v 1.1.1.1 1997/10/03 17:24:11 christos Exp $ */ + +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: gmt2local.c,v 1.2 97/01/23 22:31:25 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: gmt2local.c,v 1.1.1.1 1997/10/03 17:24:11 christos Exp $"); +#endif +#endif + +#include +#include + +#include +#ifdef TIME_WITH_SYS_TIME +#include +#endif + +#include "gnuc.h" +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" +#endif + +#include "gmt2local.h" + +/* + * Returns the difference between gmt and local time in seconds. + * Use gmtime() and localtime() to keep things simple. + */ +int32_t +gmt2local(time_t t) +{ + register int dt, dir; + register struct tm *gmt, *loc; + struct tm sgmt; + + if (t == 0) + t = time(NULL); + gmt = &sgmt; + *gmt = *gmtime(&t); + loc = localtime(&t); + dt = (loc->tm_hour - gmt->tm_hour) * 60 * 60 + + (loc->tm_min - gmt->tm_min) * 60; + + /* + * If the year or julian day is different, we span 00:00 GMT + * and must add or subtract a day. Check the year first to + * avoid problems when the julian day wraps. + */ + dir = loc->tm_year - gmt->tm_year; + if (dir == 0) + dir = loc->tm_yday - gmt->tm_yday; + dt += dir * 24 * 60 * 60; + + return (dt); +} diff --git a/usr.sbin/tcpdump/gmt2local.h b/usr.sbin/tcpdump/gmt2local.h new file mode 100644 index 000000000000..49915bdb5505 --- /dev/null +++ b/usr.sbin/tcpdump/gmt2local.h @@ -0,0 +1,29 @@ +/* $NetBSD: gmt2local.h,v 1.1.1.1 1997/10/03 17:25:06 christos Exp $ */ + +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) Header: gmt2local.h,v 1.2 97/01/23 22:31:40 leres Exp (LBL) + */ +#ifndef gmt2local_h +#define gmt2local_h + +int32_t gmt2local(time_t); +#endif diff --git a/usr.sbin/tcpdump/gnuc.h b/usr.sbin/tcpdump/gnuc.h new file mode 100644 index 000000000000..efaff3bee819 --- /dev/null +++ b/usr.sbin/tcpdump/gnuc.h @@ -0,0 +1,45 @@ +/* $NetBSD: gnuc.h,v 1.1.1.1 1997/10/03 17:25:06 christos Exp $ */ + +/* @(#) Header: gnuc.h,v 1.3 95/10/09 02:47:01 leres Exp (LBL) */ + +/* Define __P() macro, if necessary */ +#ifndef __P +#if __STDC__ +#define __P(protos) protos +#else +#define __P(protos) () +#endif +#endif + +/* inline foo */ +#ifdef __GNUC__ +#define inline __inline +#else +#define inline +#endif + +/* + * Handle new and old "dead" routine prototypes + * + * For example: + * + * __dead void foo(void) __attribute__((volatile)); + * + */ +#ifdef __GNUC__ +#ifndef __dead +#define __dead volatile +#endif +#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +#ifndef __attribute__ +#define __attribute__(args) +#endif +#endif +#else +#ifndef __dead +#define __dead +#endif +#ifndef __attribute__ +#define __attribute__(args) +#endif +#endif diff --git a/usr.sbin/tcpdump/igrp.h b/usr.sbin/tcpdump/igrp.h new file mode 100644 index 000000000000..580d10c8bc29 --- /dev/null +++ b/usr.sbin/tcpdump/igrp.h @@ -0,0 +1,38 @@ +/* $NetBSD: igrp.h,v 1.1.1.1 1997/10/03 17:25:06 christos Exp $ */ + +/* Cisco IGRP definitions */ + +/* IGRP Header */ + +struct igrphdr { +#ifdef WORDS_BIGENDIAN + u_char ig_v:4; /* protocol version number */ + u_char ig_op:4; /* opcode */ +#else + u_char ig_op:4; /* opcode */ + u_char ig_v:4; /* protocol version number */ +#endif + u_char ig_ed; /* edition number */ + u_short ig_as; /* autonomous system number */ + u_short ig_ni; /* number of subnet in local net */ + u_short ig_ns; /* number of networks in AS */ + u_short ig_nx; /* number of networks ouside AS */ + u_short ig_sum; /* checksum of IGRP header & data */ +}; + +#define IGRP_UPDATE 1 +#define IGRP_REQUEST 2 + +/* IGRP routing entry */ + +struct igrprte { + u_char igr_net[3]; /* 3 significant octets of IP address */ + u_char igr_dly[3]; /* delay in tens of microseconds */ + u_char igr_bw[3]; /* bandwidth in units of 1 kb/s */ + u_char igr_mtu[2]; /* MTU in octets */ + u_char igr_rel; /* percent packets successfully tx/rx */ + u_char igr_ld; /* percent of channel occupied */ + u_char igr_hct; /* hop count */ +}; + +#define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */ diff --git a/usr.sbin/tcpdump/machdep.c b/usr.sbin/tcpdump/machdep.c new file mode 100644 index 000000000000..882776503f11 --- /dev/null +++ b/usr.sbin/tcpdump/machdep.c @@ -0,0 +1,56 @@ +/* $NetBSD: machdep.c,v 1.1.1.1 1997/10/03 17:24:11 christos Exp $ */ + +/* + * Copyright (c) 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: machdep.c,v 1.3 96/12/10 23:24:28 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: machdep.c,v 1.1.1.1 1997/10/03 17:24:11 christos Exp $"); +#endif +#endif + +#include +#ifdef __osf__ +#include +#include +#endif + +#include + +#include "machdep.h" + +int +abort_on_misalignment(char *ebuf) +{ +#ifdef __osf__ + static int buf[2] = { SSIN_UACPROC, UAC_SIGBUS }; + + if (setsysinfo(SSI_NVPAIRS, (caddr_t)buf, 1, 0, 0) < 0) { + (void)sprintf(ebuf, "setsysinfo: %s", pcap_strerror(errno)); + return (-1); + } +#endif + return (0); +} diff --git a/usr.sbin/tcpdump/machdep.h b/usr.sbin/tcpdump/machdep.h new file mode 100644 index 000000000000..8bfda9618c14 --- /dev/null +++ b/usr.sbin/tcpdump/machdep.h @@ -0,0 +1,29 @@ +/* $NetBSD: machdep.h,v 1.1.1.1 1997/10/03 17:25:11 christos Exp $ */ + +/* + * Copyright (c) 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) Header: machdep.h,v 1.1 96/07/15 18:33:19 leres Exp (LBL) + */ +#ifndef tcpdump_machdep_h +#define tcpdump_machdep_h + +int abort_on_misalignment(char *); +#endif diff --git a/usr.sbin/tcpdump/netbios.h b/usr.sbin/tcpdump/netbios.h new file mode 100644 index 000000000000..60868139ae9d --- /dev/null +++ b/usr.sbin/tcpdump/netbios.h @@ -0,0 +1,18 @@ +/* $NetBSD: netbios.h,v 1.1.1.1 1997/10/03 17:25:12 christos Exp $ */ + +/* + * NETBIOS protocol formats + * + * @(#) Header: netbios.h,v 1.1 94/06/09 11:47:15 mccanne Exp + */ + +struct p8022Hdr { + u_char dsap; + u_char ssap; + u_char flags; +}; + +#define p8022Size 3 /* min 802.2 header size */ + +#define UI 0x03 /* 802.2 flags */ + diff --git a/usr.sbin/tcpdump/ppp.h b/usr.sbin/tcpdump/ppp.h new file mode 100644 index 000000000000..c2a4f8057723 --- /dev/null +++ b/usr.sbin/tcpdump/ppp.h @@ -0,0 +1,52 @@ +/* $NetBSD: ppp.h,v 1.1.1.1 1997/10/03 17:25:18 christos Exp $ */ + +/* @(#) Header: ppp.h,v 1.7 95/05/04 17:52:46 mccanne Exp (LBL) */ +/* + * Point to Point Protocol (PPP) RFC1331 + * + * Copyright 1989 by Carnegie Mellon. + * + * Permission to use, copy, modify, and distribute this program for any + * purpose and without fee is hereby granted, provided that this copyright + * and permission notice appear on all copies and supporting documentation, + * the name of Carnegie Mellon not be used in advertising or publicity + * pertaining to distribution of the program without specific prior + * permission, and notice be given in supporting documentation that copying + * and distribution is by permission of Carnegie Mellon and Stanford + * University. Carnegie Mellon makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + */ +#define PPP_ADDRESS 0xff /* The address byte value */ +#define PPP_CONTROL 0x03 /* The control byte value */ + +/* Protocol numbers */ +#define PPP_IP 0x0021 /* Raw IP */ +#define PPP_OSI 0x0023 /* OSI Network Layer */ +#define PPP_NS 0x0025 /* Xerox NS IDP */ +#define PPP_DECNET 0x0027 /* DECnet Phase IV */ +#define PPP_APPLE 0x0029 /* Appletalk */ +#define PPP_IPX 0x002b /* Novell IPX */ +#define PPP_VJC 0x002d /* Van Jacobson Compressed TCP/IP */ +#define PPP_VJNC 0x002f /* Van Jacobson Uncompressed TCP/IP */ +#define PPP_BRPDU 0x0031 /* Bridging PDU */ +#define PPP_STII 0x0033 /* Stream Protocol (ST-II) */ +#define PPP_VINES 0x0035 /* Banyan Vines */ + +#define PPP_HELLO 0x0201 /* 802.1d Hello Packets */ +#define PPP_LUXCOM 0x0231 /* Luxcom */ +#define PPP_SNS 0x0233 /* Sigma Network Systems */ + +#define PPP_IPCP 0x8021 /* IP Control Protocol */ +#define PPP_OSICP 0x8023 /* OSI Network Layer Control Protocol */ +#define PPP_NSCP 0x8025 /* Xerox NS IDP Control Protocol */ +#define PPP_DECNETCP 0x8027 /* DECnet Control Protocol */ +#define PPP_APPLECP 0x8029 /* Appletalk Control Protocol */ +#define PPP_IPXCP 0x802b /* Novell IPX Control Protocol */ +#define PPP_STIICP 0x8033 /* Strean Protocol Control Protocol */ +#define PPP_VINESCP 0x8035 /* Banyan Vines Control Protocol */ + +#define PPP_LCP 0xc021 /* Link Control Protocol */ +#define PPP_PAP 0xc023 /* Password Authentication Protocol */ +#define PPP_LQM 0xc025 /* Link Quality Monitoring */ +#define PPP_CHAP 0xc223 /* Challenge Handshake Authentication Protocol */ diff --git a/usr.sbin/tcpdump/print-atm.c b/usr.sbin/tcpdump/print-atm.c new file mode 100644 index 000000000000..dd28016adcea --- /dev/null +++ b/usr.sbin/tcpdump/print-atm.c @@ -0,0 +1,155 @@ +/* $NetBSD: print-atm.c,v 1.1.1.1 1997/10/03 17:24:14 christos Exp $ */ + +/* + * Copyright (c) 1994, 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-atm.c,v 1.9 97/05/28 12:52:40 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: print-atm.c,v 1.1.1.1 1997/10/03 17:24:14 christos Exp $"); +#endif +#endif + +#include +#include +#include + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "ethertype.h" + +/* + * This is the top level routine of the printer. 'p' is the points + * to the LLC/SNAP header of the packet, 'tvp' is the timestamp, + * 'length' is the length of the packet off the wire, and 'caplen' + * is the number of bytes actually captured. + */ +void +atm_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + u_int caplen = h->caplen; + u_int length = h->len; + u_short ethertype; + + ts_print(&h->ts); + + if (caplen < 8) { + printf("[|atm]"); + goto out; + } + if (p[0] != 0xaa || p[1] != 0xaa || p[2] != 0x03) { + /*XXX assume 802.6 MAC header from fore driver */ + if (eflag) + printf("%04x%04x %04x%04x ", + p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3], + p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7], + p[8] << 24 | p[9] << 16 | p[10] << 8 | p[11], + p[12] << 24 | p[13] << 16 | p[14] << 8 | p[15]); + p += 20; + length -= 20; + caplen -= 20; + } + ethertype = p[6] << 8 | p[7]; + if (eflag) + printf("%02x %02x %02x %02x-%02x-%02x %04x: ", + p[0], p[1], p[2], /* dsap/ssap/ctrl */ + p[3], p[4], p[5], /* manufacturer's code */ + ethertype); + + /* + * Some printers want to get back at the ethernet addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + packetp = p; + snapend = p + caplen; + + length -= 8; + caplen -= 8; + p += 8; + + switch (ethertype) { + + case ETHERTYPE_IP: + ip_print(p, length); + break; + + /*XXX this probably isn't right */ + case ETHERTYPE_ARP: + case ETHERTYPE_REVARP: + arp_print(p, length, caplen); + break; +#ifdef notyet + case ETHERTYPE_DN: + decnet_print(p, length, caplen); + break; + + case ETHERTYPE_ATALK: + if (vflag) + fputs("et1 ", stdout); + atalk_print(p, length); + break; + + case ETHERTYPE_AARP: + aarp_print(p, length); + break; + + case ETHERTYPE_LAT: + case ETHERTYPE_MOPRC: + case ETHERTYPE_MOPDL: + /* default_print for now */ +#endif + default: + /* ether_type not known, print raw packet */ + if (!eflag) + printf("%02x %02x %02x %02x-%02x-%02x %04x: ", + p[0], p[1], p[2], /* dsap/ssap/ctrl */ + p[3], p[4], p[5], /* manufacturer's code */ + ethertype); + if (!xflag && !qflag) + default_print(p, caplen); + } + if (xflag) + default_print(p, caplen); + out: + putchar('\n'); +} diff --git a/usr.sbin/tcpdump/print-dvmrp.c b/usr.sbin/tcpdump/print-dvmrp.c new file mode 100644 index 000000000000..dffae41abd0e --- /dev/null +++ b/usr.sbin/tcpdump/print-dvmrp.c @@ -0,0 +1,367 @@ +/* $NetBSD: print-dvmrp.c,v 1.1.1.1 1997/10/03 17:24:17 christos Exp $ */ + +/* + * Copyright (c) 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-dvmrp.c,v 1.13 96/12/10 23:16:30 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: print-dvmrp.c,v 1.1.1.1 1997/10/03 17:24:17 christos Exp $"); +#endif +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" + +/* + * DVMRP message types and flag values shamelessly stolen from + * mrouted/dvmrp.h. + */ +#define DVMRP_PROBE 1 /* for finding neighbors */ +#define DVMRP_REPORT 2 /* for reporting some or all routes */ +#define DVMRP_ASK_NEIGHBORS 3 /* sent by mapper, asking for a list */ + /* + * of this router's neighbors + */ +#define DVMRP_NEIGHBORS 4 /* response to such a request */ +#define DVMRP_ASK_NEIGHBORS2 5 /* as above, want new format reply */ +#define DVMRP_NEIGHBORS2 6 +#define DVMRP_PRUNE 7 /* prune message */ +#define DVMRP_GRAFT 8 /* graft message */ +#define DVMRP_GRAFT_ACK 9 /* graft acknowledgement */ + +/* + * 'flags' byte values in DVMRP_NEIGHBORS2 reply. + */ +#define DVMRP_NF_TUNNEL 0x01 /* neighbors reached via tunnel */ +#define DVMRP_NF_SRCRT 0x02 /* tunnel uses IP source routing */ +#define DVMRP_NF_DOWN 0x10 /* kernel state of interface */ +#define DVMRP_NF_DISABLED 0x20 /* administratively disabled */ +#define DVMRP_NF_QUERIER 0x40 /* I am the subnet's querier */ + +static void print_probe(const u_char *, const u_char *, u_int); +static void print_report(const u_char *, const u_char *, u_int); +static void print_neighbors(const u_char *, const u_char *, u_int); +static void print_neighbors2(const u_char *, const u_char *, u_int); +static void print_prune(const u_char *, const u_char *, u_int); +static void print_graft(const u_char *, const u_char *, u_int); +static void print_graft_ack(const u_char *, const u_char *, u_int); + +static u_int32_t target_level; + +void +dvmrp_print(register const u_char *bp, register u_int len) +{ + register const u_char *ep; + register u_char type; + + ep = (const u_char *)snapend; + if (bp >= ep) + return; + + type = bp[1]; + bp += 8; + /* + * Skip IGMP header + */ + + len -= 8; + + switch (type) { + + case DVMRP_PROBE: + printf(" Probe"); + if (vflag) + print_probe(bp, ep, len); + break; + + case DVMRP_REPORT: + printf(" Report"); + if (vflag) + print_report(bp, ep, len); + break; + + case DVMRP_ASK_NEIGHBORS: + printf(" Ask-neighbors(old)"); + break; + + case DVMRP_NEIGHBORS: + printf(" Neighbors(old)"); + print_neighbors(bp, ep, len); + break; + + case DVMRP_ASK_NEIGHBORS2: + printf(" Ask-neighbors2"); + break; + + case DVMRP_NEIGHBORS2: + printf(" Neighbors2"); + /* + * extract version and capabilities from IGMP group + * address field + */ + bp -= 4; + target_level = (bp[0] << 24) | (bp[1] << 16) | + (bp[2] << 8) | bp[3]; + bp += 4; + print_neighbors2(bp, ep, len); + break; + + case DVMRP_PRUNE: + printf(" Prune"); + print_prune(bp, ep, len); + break; + + case DVMRP_GRAFT: + printf(" Graft"); + print_graft(bp, ep, len); + break; + + case DVMRP_GRAFT_ACK: + printf(" Graft-ACK"); + print_graft_ack(bp, ep, len); + break; + + default: + printf(" [type %d]", type); + break; + } +} + +static void +print_report(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + register u_int32_t mask, origin; + register int metric, i, width, done; + + while (len > 0) { + if (len < 3) { + printf(" [|]"); + return; + } + mask = (u_int32_t)0xff << 24 | bp[0] << 16 | bp[1] << 8 | bp[2]; + width = 1; + if (bp[0]) + width = 2; + if (bp[1]) + width = 3; + if (bp[2]) + width = 4; + + printf("\n\tMask %s", intoa(htonl(mask))); + bp += 3; + len -= 3; + do { + if (bp + width + 1 > ep) { + printf(" [|]"); + return; + } + if (len < width + 1) { + printf("\n\t [Truncated Report]"); + return; + } + origin = 0; + for (i = 0; i < width; ++i) + origin = origin << 8 | *bp++; + for ( ; i < 4; ++i) + origin <<= 8; + + metric = *bp++; + done = metric & 0x80; + metric &= 0x7f; + printf("\n\t %s metric %d", intoa(htonl(origin)), + metric); + len -= width + 1; + } while (!done); + } +} + +#define GET_ADDR(to) (memcpy((char *)to, (char *)bp, 4), bp += 4) + +static void +print_probe(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + register u_int32_t genid; + u_char neighbor[4]; + + if ((len < 4) || ((bp + 4) > ep)) { + /* { (ctags) */ + printf(" [|}"); + return; + } + genid = (bp[0] << 24) | (bp[1] << 16) | (bp[2] << 8) | bp[3]; + bp += 4; + len -= 4; + printf("\n\tgenid %u", genid); + + while ((len > 0) && (bp < ep)) { + if ((len < 4) || ((bp + 4) > ep)) { + printf(" [|]"); + return; + } + GET_ADDR(neighbor); + len -= 4; + printf("\n\tneighbor %s", ipaddr_string(neighbor)); + } +} + +static void +print_neighbors(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + u_char laddr[4], neighbor[4]; + register u_char metric; + register u_char thresh; + register int ncount; + + while (len > 0 && bp < ep) { + if (len < 7 || (bp + 7) >= ep) { + printf(" [|]"); + return; + } + GET_ADDR(laddr); + metric = *bp++; + thresh = *bp++; + ncount = *bp++; + len -= 7; + while (--ncount >= 0 && (len >= 4) && (bp + 4) < ep) { + GET_ADDR(neighbor); + printf(" [%s ->", ipaddr_string(laddr)); + printf(" %s, (%d/%d)]", + ipaddr_string(neighbor), metric, thresh); + len -= 4; + } + } +} + +static void +print_neighbors2(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + u_char laddr[4], neighbor[4]; + register u_char metric, thresh, flags; + register int ncount; + + printf(" (v %d.%d):", + (int)target_level & 0xff, + (int)(target_level >> 8) & 0xff); + + while (len > 0 && bp < ep) { + if (len < 8 || (bp + 8) >= ep) { + printf(" [|]"); + return; + } + GET_ADDR(laddr); + metric = *bp++; + thresh = *bp++; + flags = *bp++; + ncount = *bp++; + len -= 8; + while (--ncount >= 0 && (len >= 4) && (bp + 4) <= ep) { + GET_ADDR(neighbor); + printf(" [%s -> ", ipaddr_string(laddr)); + printf("%s (%d/%d", ipaddr_string(neighbor), + metric, thresh); + if (flags & DVMRP_NF_TUNNEL) + printf("/tunnel"); + if (flags & DVMRP_NF_SRCRT) + printf("/srcrt"); + if (flags & DVMRP_NF_QUERIER) + printf("/querier"); + if (flags & DVMRP_NF_DISABLED) + printf("/disabled"); + if (flags & DVMRP_NF_DOWN) + printf("/down"); + printf(")]"); + len -= 4; + } + if (ncount != -1) { + printf(" [|]"); + return; + } + } +} + +static void +print_prune(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + union a { + u_char b[4]; + u_int32_t i; + } prune_timer; + + if (len < 12 || (bp + 12) > ep) { + printf(" [|]"); + return; + } + printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); + bp += 8; + GET_ADDR(prune_timer.b); + printf(" timer %d", (int)ntohl(prune_timer.i)); +} + +static void +print_graft(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + + if (len < 8 || (bp + 8) > ep) { + printf(" [|]"); + return; + } + printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); +} + +static void +print_graft_ack(register const u_char *bp, register const u_char *ep, + register u_int len) +{ + + if (len < 8 || (bp + 8) > ep) { + printf(" [|]"); + return; + } + printf(" src %s grp %s", ipaddr_string(bp), ipaddr_string(bp + 4)); +} diff --git a/usr.sbin/tcpdump/print-gre.c b/usr.sbin/tcpdump/print-gre.c new file mode 100644 index 000000000000..e3f9ed2d6ef2 --- /dev/null +++ b/usr.sbin/tcpdump/print-gre.c @@ -0,0 +1,148 @@ +/* $NetBSD: print-gre.c,v 1.1.1.1 1997/10/03 17:24:21 christos Exp $ */ + +/* + * Copyright (c) 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Lawrence Berkeley Laboratory, + * Berkeley, CA. The name of the University may not be used to + * endorse or promote products derived from this software without + * specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Initial contribution from John Hawkinson + * + * This module implements support for decoding GRE (Generic Routing + * Encapsulation) tunnels; they're documented in RFC1701 and RFC1702. + * This code only supports the IP encapsulation thereof. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-gre.c,v 1.4 96/12/10 23:28:23 leres Exp "; +#else +__RCSID("$NetBSD: print-gre.c,v 1.1.1.1 1997/10/03 17:24:21 christos Exp $"); +#endif +#endif + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "extract.h" /* must come after interface.h */ + +#define GRE_SIZE (20) + +struct gre { + u_short flags; + u_short proto; + union { + struct gre_ckof { + u_short cksum; + u_short offset; + } gre_ckof; + u_int32_t key; + u_int32_t seq; + } gre_void1; + union { + u_int32_t key; + u_int32_t seq; + u_int32_t routing; + } gre_void2; + union { + u_int32_t seq; + u_int32_t routing; + } gre_void3; + union { + u_int32_t routing; + } gre_void4; +}; + +#define GRE_CP 0x8000 /* Checksum Present */ +#define GRE_RP 0x4000 /* Routing Present */ +#define GRE_KP 0x2000 /* Key Present */ +#define GRE_SP 0x1000 /* Sequence Present */ + + +#define GREPROTO_IP 0x0800 + + +/* + * Deencapsulate and print a GRE-tunneled IP datagram + */ +void +gre_print(const u_char *bp, u_int length) +{ + const u_char *cp = bp + 4; + const struct gre *gre; + u_short flags, proto; + + gre = (const struct gre *)bp; + + if (length < GRE_SIZE) { + goto trunc; + } + flags = EXTRACT_16BITS(&gre->flags); + proto = EXTRACT_16BITS(&gre->proto); + + if (vflag) { + /* Decode the flags */ + putchar('['); + if (flags & GRE_CP) + putchar('C'); + if (flags & GRE_RP) + putchar('R'); + if (flags & GRE_KP) + putchar('K'); + if (flags & GRE_SP) + putchar('S'); + fputs("] ", stdout); + } + /* Checksum & Offset are present */ + if ((flags & GRE_CP) | (flags & GRE_RP)) + cp += 4; + + /* We don't support routing fields (variable length) now. Punt. */ + if (flags & GRE_RP) + return; + + if (flags & GRE_KP) + cp += 4; + if (flags & GRE_SP) + cp += 4; + + switch (proto) { + + case GREPROTO_IP: + ip_print(cp, length - ((cp - bp) / sizeof(u_char))); + break; + + default: + printf("gre-proto-0x%04X", proto); + break; + } + return; + +trunc: + fputs("[|gre]", stdout); + +} diff --git a/usr.sbin/tcpdump/print-igrp.c b/usr.sbin/tcpdump/print-igrp.c new file mode 100644 index 000000000000..73e1f3a307a7 --- /dev/null +++ b/usr.sbin/tcpdump/print-igrp.c @@ -0,0 +1,146 @@ +/* $NetBSD: print-igrp.c,v 1.1.1.1 1997/10/03 17:24:22 christos Exp $ */ + +/* + * Copyright (c) 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Initial contribution from Francis Dupont (francis.dupont@inria.fr) + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-igrp.c,v 1.8 97/05/28 12:52:47 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: print-igrp.c,v 1.1.1.1 1997/10/03 17:24:22 christos Exp $"); +#endif +#endif + +#include +#include /* concession to AIX */ +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "igrp.h" +#include "extract.h" /* must come after interface.h */ + +static void +igrp_entry_print(register struct igrprte *igr, register int is_interior, + register int is_exterior) +{ + register u_int delay, bandwidth; + u_int metric, mtu; + + if (is_interior) + printf(" *.%d.%d.%d", igr->igr_net[0], + igr->igr_net[1], igr->igr_net[2]); + else if (is_exterior) + printf(" X%d.%d.%d.0", igr->igr_net[0], + igr->igr_net[1], igr->igr_net[2]); + else + printf(" %d.%d.%d.0", igr->igr_net[0], + igr->igr_net[1], igr->igr_net[2]); + + delay = EXTRACT_24BITS(igr->igr_dly); + bandwidth = EXTRACT_24BITS(igr->igr_bw); + metric = bandwidth + delay; + if (metric > 0xffffff) + metric = 0xffffff; + mtu = EXTRACT_16BITS(igr->igr_mtu); + + printf(" d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops", + 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth, + igr->igr_rel, igr->igr_ld, metric, + mtu, igr->igr_hct); +} + +static struct tok op2str[] = { + { IGRP_UPDATE, "update" }, + { IGRP_REQUEST, "request" }, + { 0, NULL } +}; + +void +igrp_print(register const u_char *bp, u_int length, register const u_char *bp2) +{ + register struct igrphdr *hdr; + register struct ip *ip; + register u_char *cp; + u_int nint, nsys, next; + + hdr = (struct igrphdr *)bp; + ip = (struct ip *)bp2; + cp = (u_char *)(hdr + 1); + (void)printf("%s > %s: igrp: ", + ipaddr_string(&ip->ip_src), + ipaddr_string(&ip->ip_dst)); + + /* Header */ + TCHECK(*hdr); + nint = EXTRACT_16BITS(&hdr->ig_ni); + nsys = EXTRACT_16BITS(&hdr->ig_ns); + next = EXTRACT_16BITS(&hdr->ig_nx); + + (void)printf(" %s V%d edit=%d AS=%d (%d/%d/%d)", + tok2str(op2str, "op-#%d", hdr->ig_op), + hdr->ig_v, + hdr->ig_ed, + EXTRACT_16BITS(&hdr->ig_as), + nint, + nsys, + next); + + length -= sizeof(*hdr); + while (length >= IGRP_RTE_SIZE) { + if (nint > 0) { + TCHECK2(*cp, IGRP_RTE_SIZE); + igrp_entry_print((struct igrprte *)cp, 1, 0); + --nint; + } else if (nsys > 0) { + TCHECK2(*cp, IGRP_RTE_SIZE); + igrp_entry_print((struct igrprte *)cp, 0, 0); + --nsys; + } else if (next > 0) { + TCHECK2(*cp, IGRP_RTE_SIZE); + igrp_entry_print((struct igrprte *)cp, 0, 1); + --next; + } else { + (void)printf("[extra bytes %d]", length); + break; + } + cp += IGRP_RTE_SIZE; + length -= IGRP_RTE_SIZE; + } + if (nint == 0 && nsys == 0 && next == 0) + return; +trunc: + fputs("[|igrp]", stdout); +} diff --git a/usr.sbin/tcpdump/print-krb.c b/usr.sbin/tcpdump/print-krb.c new file mode 100644 index 000000000000..f830ee513013 --- /dev/null +++ b/usr.sbin/tcpdump/print-krb.c @@ -0,0 +1,295 @@ +/* $NetBSD: print-krb.c,v 1.1.1.1 1997/10/03 17:24:25 christos Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Initial contribution from John Hawkinson (jhawk@mit.edu). + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-krb.c,v 1.9 97/04/26 14:01:45 leres Exp "; +#else +__RCSID("$NetBSD: print-krb.c,v 1.1.1.1 1997/10/03 17:24:25 christos Exp $"); +#endif +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" + +const u_char *c_print(register const u_char *, register const u_char *); +const u_char *krb4_print_hdr(const u_char *); +void krb4_print(const u_char *); +void krb_print(const u_char *, u_int); + + +#define AUTH_MSG_KDC_REQUEST 1<<1 +#define AUTH_MSG_KDC_REPLY 2<<1 +#define AUTH_MSG_APPL_REQUEST 3<<1 +#define AUTH_MSG_APPL_REQUEST_MUTUAL 4<<1 +#define AUTH_MSG_ERR_REPLY 5<<1 +#define AUTH_MSG_PRIVATE 6<<1 +#define AUTH_MSG_SAFE 7<<1 +#define AUTH_MSG_APPL_ERR 8<<1 +#define AUTH_MSG_DIE 63<<1 + +#define KERB_ERR_OK 0 +#define KERB_ERR_NAME_EXP 1 +#define KERB_ERR_SERVICE_EXP 2 +#define KERB_ERR_AUTH_EXP 3 +#define KERB_ERR_PKT_VER 4 +#define KERB_ERR_NAME_MAST_KEY_VER 5 +#define KERB_ERR_SERV_MAST_KEY_VER 6 +#define KERB_ERR_BYTE_ORDER 7 +#define KERB_ERR_PRINCIPAL_UNKNOWN 8 +#define KERB_ERR_PRINCIPAL_NOT_UNIQUE 9 +#define KERB_ERR_NULL_KEY 10 + +struct krb { + u_char pvno; /* Protocol Version */ + u_char type; /* Type+B */ +}; + +static char tstr[] = " [|kerberos]"; + +static struct tok type2str[] = { + { AUTH_MSG_KDC_REQUEST, "KDC_REQUEST" }, + { AUTH_MSG_KDC_REPLY, "KDC_REPLY" }, + { AUTH_MSG_APPL_REQUEST, "APPL_REQUEST" }, + { AUTH_MSG_APPL_REQUEST_MUTUAL, "APPL_REQUEST_MUTUAL" }, + { AUTH_MSG_ERR_REPLY, "ERR_REPLY" }, + { AUTH_MSG_PRIVATE, "PRIVATE" }, + { AUTH_MSG_SAFE, "SAFE" }, + { AUTH_MSG_APPL_ERR, "APPL_ERR" }, + { AUTH_MSG_DIE, "DIE" }, + { 0, NULL } +}; + +static struct tok kerr2str[] = { + { KERB_ERR_OK, "OK" }, + { KERB_ERR_NAME_EXP, "NAME_EXP" }, + { KERB_ERR_SERVICE_EXP, "SERVICE_EXP" }, + { KERB_ERR_AUTH_EXP, "AUTH_EXP" }, + { KERB_ERR_PKT_VER, "PKT_VER" }, + { KERB_ERR_NAME_MAST_KEY_VER, "NAME_MAST_KEY_VER" }, + { KERB_ERR_SERV_MAST_KEY_VER, "SERV_MAST_KEY_VER" }, + { KERB_ERR_BYTE_ORDER, "BYTE_ORDER" }, + { KERB_ERR_PRINCIPAL_UNKNOWN, "PRINCIPAL_UNKNOWN" }, + { KERB_ERR_PRINCIPAL_NOT_UNIQUE,"PRINCIPAL_NOT_UNIQUE" }, + { KERB_ERR_NULL_KEY, "NULL_KEY"}, + { 0, NULL} +}; + + +/* little endian (unaligned) to host byte order */ +/* XXX need to look at this... */ +#define vtohlp(x) ((( ((char *)(x))[0] ) ) | \ + (( ((char *)(x))[1] ) << 8) | \ + (( ((char *)(x))[2] ) << 16) | \ + (( ((char *)(x))[3] ) << 24)) +#define vtohsp(x) ((( ((char *)(x))[0] ) ) | \ + (( ((char *)(x))[1] ) << 8)) +/* network (big endian) (unaligned) to host byte order */ +#define ntohlp(x) ((( ((char *)(x))[3] ) ) | \ + (( ((char *)(x))[2] ) << 8) | \ + (( ((char *)(x))[1] ) << 16) | \ + (( ((char *)(x))[0] ) << 24)) +#define ntohsp(x) ((( ((char *)(x))[1] ) ) | \ + (( ((char *)(x))[0] ) << 8)) + + + +const u_char * +c_print(register const u_char *s, register const u_char *ep) +{ + register u_char c; + register int flag; + + flag = 1; + while (s < ep) { + c = *s++; + if (c == '\0') { + flag = 0; + break; + } + if (!isascii(c)) { + c = toascii(c); + putchar('M'); + putchar('-'); + } + if (!isprint(c)) { + c ^= 0x40; /* DEL to ?, others to alpha */ + putchar('^'); + } + putchar(c); + } + if (flag) + return NULL; + return (s); +} + +const u_char * +krb4_print_hdr(const u_char *cp) +{ + cp += 2; + +#define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc + + PRINT; + putchar('.'); + PRINT; + putchar('@'); + PRINT; + return (cp); + +trunc: + fputs(tstr, stdout); + return (NULL); + +#undef PRINT +} + +void +krb4_print(const u_char *cp) +{ + register const struct krb *kp; + u_char type; + u_short len; + +#define PRINT if ((cp = c_print(cp, snapend)) == NULL) goto trunc +/* True if struct krb is little endian */ +#define IS_LENDIAN(kp) (((kp)->type & 0x01) != 0) +#define KTOHSP(kp, cp) (IS_LENDIAN(kp) ? vtohsp(cp) : ntohsp(cp)) + + kp = (struct krb *)cp; + + if ((&kp->type) >= snapend) { + fputs(tstr, stdout); + return; + } + + type = kp->type & (0xFF << 1); + + printf(" %s %s: ", + IS_LENDIAN(kp) ? "le" : "be", tok2str(type2str, NULL, type)); + + switch (type) { + + case AUTH_MSG_KDC_REQUEST: + if ((cp = krb4_print_hdr(cp)) == NULL) + return; + cp += 4; /* ctime */ + TCHECK(*cp); + printf(" %dmin ", *cp++ * 5); + PRINT; + putchar('.'); + PRINT; + break; + + case AUTH_MSG_APPL_REQUEST: + cp += 2; + TCHECK(*cp); + printf("v%d ", *cp++); + PRINT; + TCHECK(*cp); + printf(" (%d)", *cp++); + TCHECK(*cp); + printf(" (%d)", *cp); + break; + + case AUTH_MSG_KDC_REPLY: + if ((cp = krb4_print_hdr(cp)) == NULL) + return; + cp += 10; /* timestamp + n + exp + kvno */ + TCHECK2(*cp, sizeof(short)); + len = KTOHSP(kp, cp); + printf(" (%d)", len); + break; + + case AUTH_MSG_ERR_REPLY: + if ((cp = krb4_print_hdr(cp)) == NULL) + return; + cp += 4; /* timestamp */ + TCHECK2(*cp, sizeof(short)); + printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp))); + cp += 4; + PRINT; + break; + + default: + fputs("(unknown)", stdout); + break; + } + + return; +trunc: + fputs(tstr, stdout); +} + +void +krb_print(const u_char *dat, u_int length) +{ + register const struct krb *kp; + + kp = (struct krb *)dat; + + if (dat >= snapend) { + fputs(tstr, stdout); + return; + } + + switch (kp->pvno) { + + case 1: + case 2: + case 3: + printf(" v%d", kp->pvno); + break; + + case 4: + printf(" v%d", kp->pvno); + krb4_print((const u_char *)kp); + break; + + case 106: + case 107: + fputs(" v5", stdout); + /* Decode ASN.1 here "someday" */ + break; + } + return; +} diff --git a/usr.sbin/tcpdump/print-netbios.c b/usr.sbin/tcpdump/print-netbios.c new file mode 100644 index 000000000000..77dc3a4805f1 --- /dev/null +++ b/usr.sbin/tcpdump/print-netbios.c @@ -0,0 +1,106 @@ +/* $NetBSD: print-netbios.c,v 1.1.1.1 1997/10/03 17:24:26 christos Exp $ */ + +/* + * Copyright (c) 1994, 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Format and print NETBIOS packets. + * Contributed by Brad Parker (brad@fcr.com). + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-netbios.c,v 1.10 96/12/10 23:25:12 leres Exp "; +#else +__RCSID("$NetBSD: print-netbios.c,v 1.1.1.1 1997/10/03 17:24:26 christos Exp $"); +#endif +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __STDC__ +#include +#endif +#include +#include + +#include "interface.h" +#include "addrtoname.h" +#include "netbios.h" +#include "extract.h" + +/* + * Print NETBIOS packets. + */ +void +netbios_print(struct p8022Hdr *nb, u_int length) +{ + if (length < p8022Size) { + (void)printf(" truncated-netbios %d", length); + return; + } + + if (nb->flags == UI) { + (void)printf("802.1 UI "); + } else { + (void)printf("802.1 CONN "); + } + + if ((u_char *)(nb + 1) > snapend) { + printf(" [|netbios]"); + return; + } + +/* + netbios_decode(nb, (u_char *)nb + p8022Size, length - p8022Size); +*/ +} + +#ifdef never + (void)printf("%s.%d > ", + ipxaddr_string(EXTRACT_32BITS(ipx->srcNet), ipx->srcNode), + EXTRACT_16BITS(ipx->srcSkt)); + + (void)printf("%s.%d:", + ipxaddr_string(EXTRACT_32BITS(ipx->dstNet), ipx->dstNode), + EXTRACT_16BITS(ipx->dstSkt)); + + if ((u_char *)(ipx + 1) > snapend) { + printf(" [|ipx]"); + return; + } + + /* take length from ipx header */ + length = EXTRACT_16BITS(&ipx->length); + + ipx_decode(ipx, (u_char *)ipx + ipxSize, length - ipxSize); +#endif + diff --git a/usr.sbin/tcpdump/print-pim.c b/usr.sbin/tcpdump/print-pim.c new file mode 100644 index 000000000000..92874c36a514 --- /dev/null +++ b/usr.sbin/tcpdump/print-pim.c @@ -0,0 +1,107 @@ +/* $NetBSD: print-pim.c,v 1.1.1.1 1997/10/03 17:24:34 christos Exp $ */ + +/* + * Copyright (c) 1995, 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-pim.c,v 1.7 96/09/26 23:36:48 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: print-pim.c,v 1.1.1.1 1997/10/03 17:24:34 christos Exp $"); +#endif +#endif + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "interface.h" +#include "addrtoname.h" + +void +pim_print(register const u_char *bp, register u_int len) +{ + register const u_char *ep; + register u_char type; + + ep = (const u_char *)snapend; + if (bp >= ep) + return; + + type = bp[1]; + + switch (type) { + case 0: + (void)printf(" Query"); + break; + + case 1: + (void)printf(" Register"); + break; + + case 2: + (void)printf(" Register-Stop"); + break; + + case 3: + (void)printf(" Join/Prune"); + break; + + case 4: + (void)printf(" RP-reachable"); + break; + + case 5: + (void)printf(" Assert"); + break; + + case 6: + (void)printf(" Graft"); + break; + + case 7: + (void)printf(" Graft-ACK"); + break; + + case 8: + (void)printf(" Mode"); + break; + + default: + (void)printf(" [type %d]", type); + break; + } +} diff --git a/usr.sbin/tcpdump/print-raw.c b/usr.sbin/tcpdump/print-raw.c new file mode 100644 index 000000000000..0b4d35aaadf6 --- /dev/null +++ b/usr.sbin/tcpdump/print-raw.c @@ -0,0 +1,95 @@ +/* $NetBSD: print-raw.c,v 1.1.1.1 1997/10/03 17:24:35 christos Exp $ */ + +/* + * Copyright (c) 1996 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: print-raw.c,v 1.22 96/12/10 23:18:58 leres Locked (LBL)"; +#else +__RCSID("$NetBSD: print-raw.c,v 1.1.1.1 1997/10/03 17:24:35 christos Exp $"); +#endif +#endif + +#include +#include +#include +#include +#include + +#if __STDC__ +struct mbuf; +struct rtentry; +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "addrtoname.h" +#include "interface.h" + +#ifndef AF_NS +#define AF_NS 6 /* XEROX NS protocols */ +#endif + +/* + * The DLT_RAW packet has no header. It contains a raw IP packet. + */ + +void +raw_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) +{ + u_int length = h->len; + u_int caplen = h->caplen; + + ts_print(&h->ts); + + /* + * Some printers want to get back at the link level addresses, + * and/or check that they're not walking off the end of the packet. + * Rather than pass them all the way down, we set these globals. + */ + packetp = p; + snapend = p + caplen; + + if (eflag) + printf("ip: "); + + ip_print(p, length); + + if (xflag) + default_print(p, caplen); + putchar('\n'); +} diff --git a/usr.sbin/tcpdump/savestr.c b/usr.sbin/tcpdump/savestr.c new file mode 100644 index 000000000000..cef8eb42133f --- /dev/null +++ b/usr.sbin/tcpdump/savestr.c @@ -0,0 +1,74 @@ +/* $NetBSD: savestr.c,v 1.1.1.1 1997/10/03 17:24:49 christos Exp $ */ + +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: savestr.c,v 1.2 97/05/09 14:52:31 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: savestr.c,v 1.1.1.1 1997/10/03 17:24:49 christos Exp $"); +#endif +#endif + +#include + +#ifdef HAVE_MALLOC_H +#include +#endif +#include +#include + +#include "gnuc.h" +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" +#endif + +#include "savestr.h" + +/* A replacement for strdup() that cuts down on malloc() overhead */ +char * +savestr(register const char *str) +{ + register u_int size; + register char *p; + static char *strptr = NULL; + static u_int strsize = 0; + + size = strlen(str) + 1; + if (size > strsize) { + strsize = 1024; + if (strsize < size) + strsize = size; + strptr = (char *)malloc(strsize); + if (strptr == NULL) { + fprintf(stderr, "savestr: malloc\n"); + exit(1); + } + } + (void)strcpy(strptr, str); + p = strptr; + strptr += size; + strsize -= size; + return (p); +} diff --git a/usr.sbin/tcpdump/savestr.h b/usr.sbin/tcpdump/savestr.h new file mode 100644 index 000000000000..c67af2a4ce28 --- /dev/null +++ b/usr.sbin/tcpdump/savestr.h @@ -0,0 +1,26 @@ +/* $NetBSD: savestr.h,v 1.1.1.1 1997/10/03 17:25:18 christos Exp $ */ + +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) Header: savestr.h,v 1.1 97/04/22 13:30:21 leres Exp (LBL) + */ + +extern char *savestr(const char *); diff --git a/usr.sbin/tcpdump/setsignal.c b/usr.sbin/tcpdump/setsignal.c new file mode 100644 index 000000000000..f0551abb67f7 --- /dev/null +++ b/usr.sbin/tcpdump/setsignal.c @@ -0,0 +1,85 @@ +/* $NetBSD: setsignal.c,v 1.1.1.1 1997/10/03 17:24:50 christos Exp $ */ + +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include +#ifndef lint +#if 0 +static const char rcsid[] = + "@(#) Header: setsignal.c,v 1.4 97/06/15 13:20:29 leres Exp (LBL)"; +#else +__RCSID("$NetBSD: setsignal.c,v 1.1.1.1 1997/10/03 17:24:50 christos Exp $"); +#endif +#endif + +#include + +#ifdef HAVE_MEMORY_H +#include +#endif +#include +#ifdef HAVE_SIGACTION +#include +#endif + +#include "gnuc.h" +#ifdef HAVE_OS_PROTO_H +#include "os-proto.h" +#endif + +#include "setsignal.h" + +/* + * An os independent signal() with BSD semantics, e.g. the signal + * catcher is restored following service of the signal. + * + * When sigset() is available, signal() has SYSV semantics and sigset() + * has BSD semantics and call interface. Unfortunately, Linux does not + * have sigset() so we use the more complicated sigaction() interface + * there. + * + * Did I mention that signals suck? + */ +RETSIGTYPE +(*setsignal (int sig, RETSIGTYPE (*func)(int)))(int) +{ +#ifdef HAVE_SIGACTION + struct sigaction old, new; + + memset(&new, 0, sizeof(new)); + new.sa_handler = func; +#ifdef SA_RESTART + new.sa_flags |= SA_RESTART; +#endif + if (sigaction(sig, &new, &old) < 0) + return (SIG_ERR); + return (old.sa_handler); + +#else +#ifdef HAVE_SIGSET + return (sigset(sig, func)); +#else + return (signal(sig, func)); +#endif +#endif +} + diff --git a/usr.sbin/tcpdump/setsignal.h b/usr.sbin/tcpdump/setsignal.h new file mode 100644 index 000000000000..0b7a8c27f390 --- /dev/null +++ b/usr.sbin/tcpdump/setsignal.h @@ -0,0 +1,29 @@ +/* $NetBSD: setsignal.h,v 1.1.1.1 1997/10/03 17:25:18 christos Exp $ */ + +/* + * Copyright (c) 1997 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * @(#) Header: setsignal.h,v 1.2 97/06/13 13:10:44 leres Exp (LBL) + */ +#ifndef setsignal_h +#define setsignal_h + +RETSIGTYPE (*setsignal(int, RETSIGTYPE (*)(int)))(int); +#endif