From 8052502f69480852fa9ccecf3788125a3d1c6aaf Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 3 Aug 2001 16:44:47 +0000 Subject: [PATCH] network_cmds-85.tar.gz --- Makefile | 6 +- PB.project | 3 - arp.tproj/arp.c | 19 +- ftpd.tproj/ftpcmd.y | 2 +- ifconfig.tproj/ifconfig.c | 5 +- ipfw.tproj/ipfw.c | 2 +- netstat.tproj/inet.c | 4 +- netstat.tproj/unix.c | 4 +- pcap/Makefile | 63 - pcap/Makefile.postamble | 122 -- pcap/Makefile.preamble | 130 -- pcap/PB.project | 48 - pcap/bpf_filter.c | 546 -------- pcap/bpf_image.c | 315 ----- pcap/etherent.c | 182 --- pcap/ethertype.h | 100 -- pcap/gencode.c | 1843 -------------------------- pcap/gencode.h | 196 --- pcap/grammar.y | 280 ---- pcap/inet.c | 249 ---- pcap/nametoaddr.c | 394 ------ pcap/optimize.c | 2029 ----------------------------- pcap/pcap-bpf.c | 273 ---- pcap/pcap-int.h | 129 -- pcap/pcap-namedb.h | 101 -- pcap/pcap.c | 219 ---- pcap/pcap.h | 166 --- pcap/savefile.c | 362 ----- pcap/scanner.l | 198 --- portmap.tproj/Makefile | 48 - portmap.tproj/Makefile.postamble | 110 -- portmap.tproj/Makefile.preamble | 113 -- portmap.tproj/PB.project | 41 - portmap.tproj/portmap.8 | 110 -- portmap.tproj/portmap.c | 661 ---------- rwhod.tproj/rwhod.c | 15 +- tcpdump.tproj/Makefile | 63 - tcpdump.tproj/Makefile.postamble | 123 -- tcpdump.tproj/Makefile.preamble | 130 -- tcpdump.tproj/PB.project | 98 -- tcpdump.tproj/addrtoname.c | 779 ----------- tcpdump.tproj/addrtoname.h | 59 - tcpdump.tproj/appletalk.h | 190 --- tcpdump.tproj/bootp.h | 132 -- tcpdump.tproj/bpf_dump.c | 88 -- tcpdump.tproj/decnet.h | 476 ------- tcpdump.tproj/ethertype.h | 99 -- tcpdump.tproj/extract.h | 80 -- tcpdump.tproj/fddi.h | 92 -- tcpdump.tproj/gnuc.h | 66 - tcpdump.tproj/igrp.h | 59 - tcpdump.tproj/interface.h | 230 ---- tcpdump.tproj/ipx.h | 52 - tcpdump.tproj/llc.h | 143 -- tcpdump.tproj/machdep.c | 72 - tcpdump.tproj/machdep.h | 50 - tcpdump.tproj/mib.h | 1279 ------------------ tcpdump.tproj/netbios.h | 39 - tcpdump.tproj/nfs.h | 470 ------- tcpdump.tproj/nfsfh.h | 57 - tcpdump.tproj/nfsv2.h | 285 ---- tcpdump.tproj/ntp.h | 140 -- tcpdump.tproj/os-solaris2.h | 77 -- tcpdump.tproj/os-sunos4.h | 238 ---- tcpdump.tproj/os-ultrix4.h | 62 - tcpdump.tproj/ospf.h | 246 ---- tcpdump.tproj/parsenfsfh.c | 443 ------- tcpdump.tproj/print-arp.c | 153 --- tcpdump.tproj/print-atalk.c | 595 --------- tcpdump.tproj/print-atm.c | 171 --- tcpdump.tproj/print-bootp.c | 371 ------ tcpdump.tproj/print-decnet.c | 798 ------------ tcpdump.tproj/print-domain.c | 423 ------ tcpdump.tproj/print-dvmrp.c | 383 ------ tcpdump.tproj/print-egp.c | 377 ------ tcpdump.tproj/print-ether.c | 219 ---- tcpdump.tproj/print-fddi.c | 377 ------ tcpdump.tproj/print-gre.c | 164 --- tcpdump.tproj/print-icmp.c | 377 ------ tcpdump.tproj/print-igrp.c | 161 --- tcpdump.tproj/print-ip.c | 547 -------- tcpdump.tproj/print-ipx.c | 238 ---- tcpdump.tproj/print-isoclns.c | 340 ----- tcpdump.tproj/print-krb.c | 317 ----- tcpdump.tproj/print-llc.c | 216 --- tcpdump.tproj/print-netbios.c | 122 -- tcpdump.tproj/print-nfs.c | 891 ------------- tcpdump.tproj/print-ntp.c | 307 ----- tcpdump.tproj/print-null.c | 142 -- tcpdump.tproj/print-ospf.c | 603 --------- tcpdump.tproj/print-pim.c | 123 -- tcpdump.tproj/print-ppp.c | 128 -- tcpdump.tproj/print-rip.c | 182 --- tcpdump.tproj/print-skip.c | 943 -------------- tcpdump.tproj/print-sl.c | 280 ---- tcpdump.tproj/print-snmp.c | 1063 --------------- tcpdump.tproj/print-sunrpc.c | 155 --- tcpdump.tproj/print-tcp.c | 383 ------ tcpdump.tproj/print-tftp.c | 162 --- tcpdump.tproj/print-udp.c | 464 ------- tcpdump.tproj/print-wb.c | 456 ------- tcpdump.tproj/strcasecmp.c | 112 -- tcpdump.tproj/tcpdump.c | 451 ------- tcpdump.tproj/util.c | 352 ----- tcpdump.tproj/version.c | 27 - tcpdump.tproj/vfprintf.c | 85 -- telnetd.tproj/Makefile | 4 +- telnetd.tproj/authenc.c | 114 -- telnetd.tproj/defs.h | 29 +- telnetd.tproj/ext.h | 43 +- telnetd.tproj/global.c | 27 +- telnetd.tproj/pathnames.h | 26 +- telnetd.tproj/slc.c | 72 +- telnetd.tproj/state.c | 186 +-- telnetd.tproj/strlcpy.c | 74 ++ telnetd.tproj/sys_term.c | 399 +++--- telnetd.tproj/telnetd.8 | 224 ++-- telnetd.tproj/telnetd.c | 460 +++---- telnetd.tproj/telnetd.h | 24 - telnetd.tproj/termstat.c | 121 +- telnetd.tproj/utility.c | 630 +++------ telnetd.tproj/vasprintf.c | 65 + tftpd.tproj/tftpd.8 | 130 +- tftpd.tproj/tftpd.c | 148 ++- timed.tproj/timed.tproj/readmsg.c | 28 +- 125 files changed, 1251 insertions(+), 30716 deletions(-) delete mode 100644 pcap/Makefile delete mode 100644 pcap/Makefile.postamble delete mode 100644 pcap/Makefile.preamble delete mode 100644 pcap/PB.project delete mode 100644 pcap/bpf_filter.c delete mode 100644 pcap/bpf_image.c delete mode 100644 pcap/etherent.c delete mode 100644 pcap/ethertype.h delete mode 100644 pcap/gencode.c delete mode 100644 pcap/gencode.h delete mode 100644 pcap/grammar.y delete mode 100644 pcap/inet.c delete mode 100644 pcap/nametoaddr.c delete mode 100644 pcap/optimize.c delete mode 100644 pcap/pcap-bpf.c delete mode 100644 pcap/pcap-int.h delete mode 100644 pcap/pcap-namedb.h delete mode 100644 pcap/pcap.c delete mode 100644 pcap/pcap.h delete mode 100644 pcap/savefile.c delete mode 100644 pcap/scanner.l delete mode 100644 portmap.tproj/Makefile delete mode 100644 portmap.tproj/Makefile.postamble delete mode 100644 portmap.tproj/Makefile.preamble delete mode 100644 portmap.tproj/PB.project delete mode 100644 portmap.tproj/portmap.8 delete mode 100644 portmap.tproj/portmap.c delete mode 100644 tcpdump.tproj/Makefile delete mode 100644 tcpdump.tproj/Makefile.postamble delete mode 100644 tcpdump.tproj/Makefile.preamble delete mode 100644 tcpdump.tproj/PB.project delete mode 100644 tcpdump.tproj/addrtoname.c delete mode 100644 tcpdump.tproj/addrtoname.h delete mode 100644 tcpdump.tproj/appletalk.h delete mode 100644 tcpdump.tproj/bootp.h delete mode 100644 tcpdump.tproj/bpf_dump.c delete mode 100644 tcpdump.tproj/decnet.h delete mode 100644 tcpdump.tproj/ethertype.h delete mode 100644 tcpdump.tproj/extract.h delete mode 100644 tcpdump.tproj/fddi.h delete mode 100644 tcpdump.tproj/gnuc.h delete mode 100644 tcpdump.tproj/igrp.h delete mode 100644 tcpdump.tproj/interface.h delete mode 100644 tcpdump.tproj/ipx.h delete mode 100644 tcpdump.tproj/llc.h delete mode 100644 tcpdump.tproj/machdep.c delete mode 100644 tcpdump.tproj/machdep.h delete mode 100644 tcpdump.tproj/mib.h delete mode 100644 tcpdump.tproj/netbios.h delete mode 100644 tcpdump.tproj/nfs.h delete mode 100644 tcpdump.tproj/nfsfh.h delete mode 100644 tcpdump.tproj/nfsv2.h delete mode 100644 tcpdump.tproj/ntp.h delete mode 100644 tcpdump.tproj/os-solaris2.h delete mode 100644 tcpdump.tproj/os-sunos4.h delete mode 100644 tcpdump.tproj/os-ultrix4.h delete mode 100644 tcpdump.tproj/ospf.h delete mode 100644 tcpdump.tproj/parsenfsfh.c delete mode 100644 tcpdump.tproj/print-arp.c delete mode 100644 tcpdump.tproj/print-atalk.c delete mode 100644 tcpdump.tproj/print-atm.c delete mode 100644 tcpdump.tproj/print-bootp.c delete mode 100644 tcpdump.tproj/print-decnet.c delete mode 100644 tcpdump.tproj/print-domain.c delete mode 100644 tcpdump.tproj/print-dvmrp.c delete mode 100644 tcpdump.tproj/print-egp.c delete mode 100644 tcpdump.tproj/print-ether.c delete mode 100644 tcpdump.tproj/print-fddi.c delete mode 100644 tcpdump.tproj/print-gre.c delete mode 100644 tcpdump.tproj/print-icmp.c delete mode 100644 tcpdump.tproj/print-igrp.c delete mode 100644 tcpdump.tproj/print-ip.c delete mode 100644 tcpdump.tproj/print-ipx.c delete mode 100644 tcpdump.tproj/print-isoclns.c delete mode 100644 tcpdump.tproj/print-krb.c delete mode 100644 tcpdump.tproj/print-llc.c delete mode 100644 tcpdump.tproj/print-netbios.c delete mode 100644 tcpdump.tproj/print-nfs.c delete mode 100644 tcpdump.tproj/print-ntp.c delete mode 100644 tcpdump.tproj/print-null.c delete mode 100644 tcpdump.tproj/print-ospf.c delete mode 100644 tcpdump.tproj/print-pim.c delete mode 100644 tcpdump.tproj/print-ppp.c delete mode 100644 tcpdump.tproj/print-rip.c delete mode 100644 tcpdump.tproj/print-skip.c delete mode 100644 tcpdump.tproj/print-sl.c delete mode 100644 tcpdump.tproj/print-snmp.c delete mode 100644 tcpdump.tproj/print-sunrpc.c delete mode 100644 tcpdump.tproj/print-tcp.c delete mode 100644 tcpdump.tproj/print-tftp.c delete mode 100644 tcpdump.tproj/print-udp.c delete mode 100644 tcpdump.tproj/print-wb.c delete mode 100644 tcpdump.tproj/strcasecmp.c delete mode 100644 tcpdump.tproj/tcpdump.c delete mode 100644 tcpdump.tproj/util.c delete mode 100644 tcpdump.tproj/version.c delete mode 100644 tcpdump.tproj/vfprintf.c delete mode 100644 telnetd.tproj/authenc.c create mode 100644 telnetd.tproj/strlcpy.c create mode 100644 telnetd.tproj/vasprintf.c diff --git a/Makefile b/Makefile index b8719cd..9577f9a 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,12 @@ SUBPROJECTS = timed.tproj bootparams TOOLS = arp.tproj domainname.tproj ftp.tproj ftpd.tproj identd.tproj\ ifconfig.tproj inetd.tproj logger.tproj netstat.tproj\ - nfsd.tproj nfsiod.tproj nfsstat.tproj ping.tproj portmap.tproj\ + nfsd.tproj nfsiod.tproj nfsstat.tproj ping.tproj \ rarpd.tproj rbootd.tproj rcp.tproj rexecd.tproj rlogin.tproj\ rlogind.tproj route.tproj routed.tproj rpcinfo.tproj rsh.tproj\ rshd.tproj ruptime.tproj rwho.tproj rwhod.tproj slattach.tproj\ sliplogin.tproj spray.tproj startslip.tproj syslogd.tproj\ - talk.tproj talkd.tproj tcpdump.tproj telnet.tproj\ + talk.tproj talkd.tproj telnet.tproj\ telnetd.tproj tftp.tproj tftpd.tproj traceroute.tproj\ trpt.tproj trsp.tproj uucpd.tproj wall.tproj ypbind.tproj\ ypcat.tproj ypmatch.tproj yppoll.tproj yppush.tproj\ @@ -29,7 +29,7 @@ TOOLS = arp.tproj domainname.tproj ftp.tproj ftpd.tproj identd.tproj\ makedbm.tproj revnetgroup.tproj rpc_yppasswdd.tproj\ stdethers.tproj stdhosts.tproj natd.tproj ipfw.tproj -LIBRARIES = alias pcap +LIBRARIES = alias LEGACIES = newclient.tproj ypinit.tproj diff --git a/PB.project b/PB.project index 3015bd3..53c29a2 100644 --- a/PB.project +++ b/PB.project @@ -3,7 +3,6 @@ OTHER_SOURCES = (Makefile, Makefile.include, Makefile.preamble); SUBPROJECTS = ( alias, - pcap, timed.tproj, arp.tproj, bootparams, @@ -20,7 +19,6 @@ nfsiod.tproj, nfsstat.tproj, ping.tproj, - portmap.tproj, rarpd.tproj, rbootd.tproj, rcp.tproj, @@ -42,7 +40,6 @@ syslogd.tproj, talk.tproj, talkd.tproj, - tcpdump.tproj, telnet.tproj, telnetd.tproj, tftp.tproj, diff --git a/arp.tproj/arp.c b/arp.tproj/arp.c index 4e932b4..d366781 100644 --- a/arp.tproj/arp.c +++ b/arp.tproj/arp.c @@ -99,6 +99,7 @@ static char sccsid[] = "@(#)arp.c 8.3 (Berkeley) 4/28/95"; static int pid; static int nflag; +static int aflag = 0; static int s = -1; int delete __P((char *, char *)); @@ -123,8 +124,8 @@ main(argc, argv) while ((ch = getopt(argc, argv, "ands")) != EOF) switch((char)ch) { case 'a': - dump(0); - exit(0); + aflag = 1; + break; case 'd': if (argc < 3 || argc > 4) usage(); @@ -132,7 +133,7 @@ main(argc, argv) exit(0); case 'n': nflag = 1; - continue; + break; case 's': if (argc < 4 || argc > 7) usage(); @@ -141,6 +142,14 @@ main(argc, argv) default: usage(); } + if( aflag ) { + dump(0); + exit(0); + } + if( nflag && (argc == 3) ) { + get(argv[2]); + exit(0); + } if (argc != 2) usage(); get(argv[1]); @@ -478,8 +487,8 @@ ether_aton(a, n) void usage() { - printf("usage: arp hostname\n"); - printf(" arp -a [kernel] [kernel_memory]\n"); + printf("usage: arp [-n] hostname\n"); + printf(" arp [-n] -a\n"); printf(" arp -d hostname\n"); printf(" arp -s hostname ether_addr [temp] [pub]\n"); printf(" arp -f filename\n"); diff --git a/ftpd.tproj/ftpcmd.y b/ftpd.tproj/ftpcmd.y index 3fa4a6d..2ab1638 100644 --- a/ftpd.tproj/ftpcmd.y +++ b/ftpd.tproj/ftpcmd.y @@ -674,7 +674,7 @@ cmd | SYST check_login CRLF { if ($2) -#ifdef unix +#if defined(unix) || defined(__APPLE__) #ifdef BSD reply(215, "UNIX Type: L%d Version: BSD-%d", NBBY, BSD); diff --git a/ifconfig.tproj/ifconfig.c b/ifconfig.tproj/ifconfig.c index 0165a69..a69654e 100644 --- a/ifconfig.tproj/ifconfig.c +++ b/ifconfig.tproj/ifconfig.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #endif static const char rcsid[] = - "$Id: ifconfig.c,v 1.1.1.2 2000/01/11 01:48:49 wsanchez Exp $"; + "$Id: ifconfig.c,v 1.2 2001/08/03 16:27:01 vlubet Exp $"; #endif /* not lint */ #include @@ -89,7 +89,7 @@ int setaddr; int setipdst; int doalias; int clearaddr; -int newaddr = 1; +int newaddr; struct afswtch; @@ -510,6 +510,7 @@ setifaddr(addr, param, s, afp) * The address interpretation may depend on the flags, * and the flags may change when the address is set. */ + newaddr = 1; setaddr++; if (doalias == 0) clearaddr = 1; diff --git a/ipfw.tproj/ipfw.c b/ipfw.tproj/ipfw.c index 7992ec4..4779940 100644 --- a/ipfw.tproj/ipfw.c +++ b/ipfw.tproj/ipfw.c @@ -16,7 +16,7 @@ * * NEW command line interface for IP firewall facility * - * $Id: ipfw.c,v 1.2 2000/06/07 04:22:47 lindak Exp $ + * $Id: ipfw.c,v 1.4 2001/07/17 22:59:33 lindak Exp $ * */ diff --git a/netstat.tproj/inet.c b/netstat.tproj/inet.c index 0c2250a..37d869f 100644 --- a/netstat.tproj/inet.c +++ b/netstat.tproj/inet.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; */ static const char rcsid[] = - "$Id: inet.c,v 1.1.1.2 2000/01/11 01:48:52 wsanchez Exp $"; + "$Id: inet.c,v 1.2 2001/07/31 05:54:11 wsanchez Exp $"; #endif /* not lint */ #include @@ -216,7 +216,7 @@ protopr(proto, name) printf("Some %s sockets may have been created.\n", name); } else { - printf("Some %s sockets may have been created or deleted", + printf("Some %s sockets may have been created or deleted\n", name); } } diff --git a/netstat.tproj/unix.c b/netstat.tproj/unix.c index c61c855..541c716 100644 --- a/netstat.tproj/unix.c +++ b/netstat.tproj/unix.c @@ -59,7 +59,7 @@ static char sccsid[] = "@(#)unix.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: unix.c,v 1.1.1.2 2000/01/11 01:48:53 wsanchez Exp $"; + "$Id: unix.c,v 1.2 2001/07/31 05:54:11 wsanchez Exp $"; #endif /* not lint */ /* @@ -140,7 +140,7 @@ unixpr() printf("Some %s sockets may have been created.\n", socktype[type]); } else { - printf("Some %s sockets may have been created or deleted", + printf("Some %s sockets may have been created or deleted\n", socktype[type]); } } diff --git a/pcap/Makefile b/pcap/Makefile deleted file mode 100644 index 9f3d6f9..0000000 --- a/pcap/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = pcap - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Library - -HFILES = ethertype.h gencode.h pcap-int.h pcap-namedb.h pcap.h - -OTHERLINKED = grammar.y scanner.l - -CFILES = bpf_filter.c bpf_image.c etherent.c gencode.c inet.c\ - nametoaddr.c optimize.c pcap-bpf.c pcap.c savefile.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - -OTHERLINKEDOFILES = grammar.o scanner.o - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CURRENTLY_ACTIVE_VERSION = YES -DEPLOY_WITH_VERSION_NAME = A -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = library.make -NEXTSTEP_INSTALLDIR = /usr/lib -WINDOWS_INSTALLDIR = LOCAL_DEVELOPER_DIR/Libraries -PDO_UNIX_INSTALLDIR = /usr/lib -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -NEXTSTEP_PB_CFLAGS = -traditional-cpp -PROJECT_HEADERS = pcap.h pcap-namedb.h - - - -NEXTSTEP_BUILD_OUTPUT_DIR = /tmp/$(USER)/BUILD - -WINDOWS_PUBLIC_HEADERS_DIR = LOCAL_DEVELOPER_DIR/Headers/$(NAME) - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/pcap/Makefile.postamble b/pcap/Makefile.postamble deleted file mode 100644 index 36381d4..0000000 --- a/pcap/Makefile.postamble +++ /dev/null @@ -1,122 +0,0 @@ -############################################################################### -# NeXT Makefile.postamble -# Copyright 1996, NeXT Software, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project, sub-project, bundle, or -# palette. Each node in the project's tree of sub-projects and bundles -# should have it's own Makefile.preamble and Makefile.postamble. Additional -# rules (e.g., after_install) that are defined by the developer should be -# defined in this file. -# -############################################################################### -# -# Here are the variables exported by the common "app" makefiles that can be -# used in any customizations you make to the template below: -# -# PRODUCT_ROOT - Name of the directory to which resources are copied. -# OFILE_DIR - Directory into which .o object files are generated. -# (Note that this name is calculated based on the target -# architectures specified in Project Builder). -# DERIVED_SRC_DIR - Directory used for all other derived files -# ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations -# -# NAME - name of application, bundle, subproject, palette, etc. -# LANGUAGE - langage in which the project is written (default "English") -# LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES - non-localized resources of project -# PROJECTVERSION - version of ProjectBuilder project (NS3.X = 1.1, NS4.0 = 2.0) -# ICONSECTIONS - Specifies icon sections when linking executable -# -# CLASSES - Class implementation files in project. -# HFILES - Header files in project. -# MFILES - Other Objective-C source files in project. -# CFILES - Other C source files in project. -# PSWFILES - .psw files in the project -# PSWMFILES - .pswm files in the project -# SUBPROJECTS - Subprojects of this project -# BUNDLES - Bundle subprojects of this project -# OTHERSRCS - Other miscellaneous sources of this project -# OTHERLINKED - Source files not matching a standard source extention -# -# LIBS - Libraries to link with when making app target -# DEBUG_LIBS - Libraries to link with when making debug target -# PROF_LIBS - Libraries to link with when making profile target -# OTHERLINKEDOFILES - Other relocatable files to (always) link in. -# -# APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles -# MAKEFILEDIR - Directory in which to find $(MAKEFILE) -# MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) -# INSTALLDIR - Directory app will be installed into by 'install' target -# -############################################################################### - - -# Change defaults assumed by the standard makefiles here. Edit the -# following default values as appropriate. (Note that if no Makefile.postamble -# exists, these values will have defaults set in common.make). - -# Versioning of frameworks, libraries, bundles, and palettes: -#CURRENTLY_ACTIVE_VERSION = YES - # Set to "NO" to produce a compatibility binary -#DEPLOY_WITH_VERSION_NAME = A - # This should be incremented as your API changes. -#COMPATIBILITY_PROJECT_VERSION = 1 - # This should be incremented as your API grows. -#CURRENT_PROJECT_VERSION = 1 - # Defaults to using the "vers_string" hack. - -# Some compiler flags can be easily overridden here, but onlytake effect at -# the top-level: -#OPTIMIZATION_CFLAG = -O -#DEBUG_SYMBOLS_CFLAG = -g -#WARNING_CFLAGS = -Wmost -#DEBUG_BUILD_CFLAGS = -DDEBUG -#PROFILE_BUILD_CFLAGS = -pg -DPROFILE - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Flags passed to yacc -#YFLAGS = -d - -# Library and Framework projects only: -# 1. If you want something other than the default .dylib name, override it here -#DYLIB_INSTALL_NAME = lib$(NAME).dylib - -# 2. If you want to change the -install_name flag from the absolute path to the development area, change it here. One good choice is the installation directory. Another one might be none at all. -#DYLIB_INSTALL_DIR = $(INSTALLDIR) - -# Ownership and permissions of files installed by 'install' target -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - -# Options to strip for various project types. Note: -S strips debugging symbols -# (executables can be stripped down further with -x or, if they load no bundles, with no -# options at all). -#APP_STRIP_OPTS = -S -#TOOL_STRIP_OPTS = -S -#LIBRARY_STRIP_OPTS = -S - # for .a archives -#DYNAMIC_STRIP_OPTS = -S - # for bundles and shared libraries - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. "Official" -# user-defined rules are: -# * before_install -# * after_install -# * after_installhdrs -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# -# Note: on MS Windows, executables, have an extension, so rules and dependencies -# for generated tools should use $(EXECUTABLE_EXT) on the end. diff --git a/pcap/Makefile.preamble b/pcap/Makefile.preamble deleted file mode 100644 index 0e03ce1..0000000 --- a/pcap/Makefile.preamble +++ /dev/null @@ -1,130 +0,0 @@ -############################################################################### -# NeXT Makefile.preamble -# Copyright 1996, NeXT Software, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project. Each node in a project -# tree of sub-projects, tools, etc. should have its own Makefile.preamble and -# Makefile.postamble. -# -############################################################################### -## Configure the flags passed to $(CC) here. These flags will also be -## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and -## -L flags in ProjectBuilder's Build Options inspector if at all possible. -## To change the default flags that get passed to ${CC} -## (e.g. change -O to -O2), see Makefile.postamble. - -# Flags passed to compiler (in addition to -g, -O, etc) -OTHER_CFLAGS = -# Flags passed to ld (in addition to -ObjC, etc.) -OTHER_LDFLAGS += -seg1addr 0x59400000 -# Flags passed to libtool when building libraries -OTHER_LIBTOOL_FLAGS = -# For ordering named sections on NEXTSTEP (see ld(1)) -SECTORDER_FLAGS = - -# If you do not want any headers exported before compilations begin, -# uncomment the following line. This can be a big time saver. -#SKIP_EXPORTING_HEADERS = YES - -# Stuff related to exporting headers from this project that isn't already -# handled by PB. -OTHER_PUBLIC_HEADERS = -OTHER_PROJECT_HEADERS = -OTHER_PRIVATE_HEADERS = - -# Set these two macros if you want a precomp to be built as part of -# installation. The cc -precomp will be run in the public header directory -# on the specified public header files with the specified additional flags. -PUBLIC_PRECOMPILED_HEADERS = -PUBLIC_PRECOMPILED_HEADERS_CFLAGS = - -# Set this for library projects if you want to publish header files. If your -# app or tool project exports headers Don't -# include $(DSTROOT); this is added for you automatically. -PUBLIC_HEADER_DIR = -PRIVATE_HEADER_DIR = - -# If, in a subproject, you want to append to the parent's PUBLIC_HEADER_DIR# -# (say, to add a subdirectory like "/sys"), you can use: -PUBLIC_HEADER_DIR_SUFFIX = -PRIVATE_HEADER_DIR_SUFFIX = - -# Set this for dynamic library projects on platforms where code which references -# a dynamic library must link against an import library (i.e., Windows NT) -# Don't include $(DSTROOT); this is added for you automatically. -IMPORT_LIBRARY_DIR = - -# Additional (non-localized) resources for this project, which can be generated -OTHER_RESOURCES = - -# Uncomment this to produce a static archive-style (.a) library -#LIBRARY_STYLE = STATIC - -# Set this to YES if you don't want a final libtool call for a library/framework. -BUILD_OFILES_LIST_ONLY = - -# Additional relocatables to be linked into this project -OTHER_OFILES = -# Additional libraries to link against -OTHER_LIBS = -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -## Configure how things get built here. Additional dependencies, source files, -## derived files, and build order should be specified here. - -# Other dependencies of this project -OTHER_PRODUCT_DEPENDS = -# Built *before* building subprojects/bundles -OTHER_INITIAL_TARGETS = -# Other source files maintained by .pre/postamble -OTHER_SOURCEFILES = -# Additional files to be removed by `make clean' -OTHER_GARBAGE = - -# Targets to build before installation -OTHER_INSTALL_DEPENDS = - -# More obscure flags you might want to set for pswrap, yacc, lex, etc. -PSWFLAGS = -YFLAGS = -LFLAGS = - -## Delete this line if you want fast and loose cleans that will not remove -## things like precomps and user-defined OTHER_GARBAGE in subprojects. -CLEAN_ALL_SUBPROJECTS = YES - -## Add more obscure source files here to cause them to be automatically -## processed by the appropriate tool. Note that these files should also be -## added to "Supporting Files" in ProjectBuilder. The desired .o files that -## result from these files should also be added to OTHER_OFILES above so they -## will be linked in. - -# .msg files that should have msgwrap run on them -MSGFILES = -# .defs files that should have mig run on them -DEFSFILES = -# .mig files (no .defs files) that should have mig run on them -MIGFILES = -# .x files that should have rpcgen run on them -RPCFILES = - -## Add additional Help directories here (add them to the project as "Other -## Resources" in Project Builder) so that they will be compressed into .store -## files and copied into the app wrapper. If the help directories themselves -## need to also be in the app wrapper, then a cp command will need to be added -## in an after_install target. -OTHER_HELP_DIRS = - -# After you have saved your project using the 4.0 PB, you will automatically -# start using the makefiles in $(SYSTEM_DEVELOPER_DIR)/Makefiles/project. If you should -# need to revert back to the old 3.3 Makefile behavior, override MAKEFILEDIR to -# be $(SYSTEM_DEVELOPER_DIR)/Makefiles/app. - -# Don't add more rules here unless you want the first one to be the default -# target for make! Put all your targets in Makefile.postamble. - diff --git a/pcap/PB.project b/pcap/PB.project deleted file mode 100644 index cb13890..0000000 --- a/pcap/PB.project +++ /dev/null @@ -1,48 +0,0 @@ -{ - CURRENTLY_ACTIVE_VERSION = YES; - DEPLOY_WITH_VERSION_NAME = A; - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - CLASSES = (); - FRAMEWORKS = (); - H_FILES = (ethertype.h, gencode.h, "pcap-int.h", "pcap-namedb.h", pcap.h); - OTHER_LINKED = ( - bpf_filter.c, - bpf_image.c, - etherent.c, - gencode.c, - grammar.y, - inet.c, - nametoaddr.c, - optimize.c, - "pcap-bpf.c", - pcap.c, - savefile.c, - scanner.l - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - PROJECT_HEADERS = (pcap.h, "pcap-namedb.h"); - SUBPROJECTS = (); - }; - LANGUAGE = English; - LOCALIZABLE_FILES = {}; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/tmp/$(USER)/BUILD"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-traditional-cpp"; - NEXTSTEP_INSTALLDIR = /usr/lib; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = /bin/gnumake; - PDO_UNIX_INSTALLDIR = /usr/lib; - PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = pcap; - PROJECTTYPE = Library; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_INSTALLDIR = LOCAL_DEVELOPER_DIR/Libraries; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; - WINDOWS_PUBLICHEADERSDIR = "LOCAL_DEVELOPER_DIR/Headers/$(NAME)"; -} diff --git a/pcap/bpf_filter.c b/pcap/bpf_filter.c deleted file mode 100644 index dca0d0a..0000000 --- a/pcap/bpf_filter.c +++ /dev/null @@ -1,546 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1992, 1993 - * 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 -#include -#include - -#if defined(sparc) || defined(hppa) -#define BPF_ALIGN -#endif - -#ifndef BPF_ALIGN -#define EXTRACT_SHORT(p) ((u_short)ntohs(*(u_short *)p)) -#define EXTRACT_LONG(p) (ntohl(*(u_int32_t *)p)) -#else -#define EXTRACT_SHORT(p)\ - ((u_short)\ - ((u_short)*((u_char *)p+0)<<8|\ - (u_short)*((u_char *)p+1)<<0)) -#define EXTRACT_LONG(p)\ - ((u_int32_t)*((u_char *)p+0)<<24|\ - (u_int32_t)*((u_char *)p+1)<<16|\ - (u_int32_t)*((u_char *)p+2)<<8|\ - (u_int32_t)*((u_char *)p+3)<<0) -#endif - -#ifdef KERNEL -#include -#define MINDEX(m, k) \ -{ \ - register int len = m->m_len; \ - \ - while (k >= len) { \ - k -= len; \ - m = m->m_next; \ - if (m == 0) \ - return 0; \ - len = m->m_len; \ - } \ -} - -static int -m_xword(m, k, err) - register struct mbuf *m; - register int k, *err; -{ - register int len; - register u_char *cp, *np; - register struct mbuf *m0; - - len = m->m_len; - while (k >= len) { - k -= len; - m = m->m_next; - if (m == 0) - goto bad; - len = m->m_len; - } - cp = mtod(m, u_char *) + k; - if (len - k >= 4) { - *err = 0; - return EXTRACT_LONG(cp); - } - m0 = m->m_next; - if (m0 == 0 || m0->m_len + len - k < 4) - goto bad; - *err = 0; - np = mtod(m0, u_char *); - switch (len - k) { - - case 1: - return (cp[k] << 24) | (np[0] << 16) | (np[1] << 8) | np[2]; - - case 2: - return (cp[k] << 24) | (cp[k + 1] << 16) | (np[0] << 8) | - np[1]; - - default: - return (cp[k] << 24) | (cp[k + 1] << 16) | (cp[k + 2] << 8) | - np[0]; - } - bad: - *err = 1; - return 0; -} - -static int -m_xhalf(m, k, err) - register struct mbuf *m; - register int k, *err; -{ - register int len; - register u_char *cp; - register struct mbuf *m0; - - len = m->m_len; - while (k >= len) { - k -= len; - m = m->m_next; - if (m == 0) - goto bad; - len = m->m_len; - } - cp = mtod(m, u_char *) + k; - if (len - k >= 2) { - *err = 0; - return EXTRACT_SHORT(cp); - } - m0 = m->m_next; - if (m0 == 0) - goto bad; - *err = 0; - return (cp[k] << 8) | mtod(m0, u_char *)[0]; - bad: - *err = 1; - return 0; -} -#endif - -#include - -/* - * Execute the filter program starting at pc on the packet p - * wirelen is the length of the original packet - * buflen is the amount of data present - */ -u_int -bpf_filter(pc, p, wirelen, buflen) - register struct bpf_insn *pc; - register u_char *p; - u_int wirelen; - register u_int buflen; -{ - register u_int32_t A, X; - register int k; - int32_t mem[BPF_MEMWORDS]; - - if (pc == 0) - /* - * No filter means accept all. - */ - return (u_int)-1; -#ifdef lint - A = 0; - X = 0; -#endif - --pc; - while (1) { - ++pc; - switch (pc->code) { - - default: -#ifdef KERNEL - return 0; -#else - abort(); -#endif - case BPF_RET|BPF_K: - return (u_int)pc->k; - - case BPF_RET|BPF_A: - return (u_int)A; - - case BPF_LD|BPF_W|BPF_ABS: - k = pc->k; - if (k + sizeof(int32_t) > buflen) { -#ifdef KERNEL - int merr; - - if (buflen != 0) - return 0; - A = m_xword((struct mbuf *)p, k, &merr); - if (merr != 0) - return 0; - continue; -#else - return 0; -#endif - } -#ifdef BPF_ALIGN - if (((int)(p + k) & 3) != 0) - A = EXTRACT_LONG(&p[k]); - else -#endif - A = ntohl(*(long *)(p + k)); - continue; - - case BPF_LD|BPF_H|BPF_ABS: - k = pc->k; - if (k + sizeof(short) > buflen) { -#ifdef KERNEL - int merr; - - if (buflen != 0) - return 0; - A = m_xhalf((struct mbuf *)p, k, &merr); - continue; -#else - return 0; -#endif - } - A = EXTRACT_SHORT(&p[k]); - continue; - - case BPF_LD|BPF_B|BPF_ABS: - k = pc->k; - if (k >= buflen) { -#ifdef KERNEL - register struct mbuf *m; - - if (buflen != 0) - return 0; - m = (struct mbuf *)p; - MINDEX(m, k); - A = mtod(m, u_char *)[k]; - continue; -#else - return 0; -#endif - } - A = p[k]; - continue; - - case BPF_LD|BPF_W|BPF_LEN: - A = wirelen; - continue; - - case BPF_LDX|BPF_W|BPF_LEN: - X = wirelen; - continue; - - case BPF_LD|BPF_W|BPF_IND: - k = X + pc->k; - if (k + sizeof(int32_t) > buflen) { -#ifdef KERNEL - int merr; - - if (buflen != 0) - return 0; - A = m_xword((struct mbuf *)p, k, &merr); - if (merr != 0) - return 0; - continue; -#else - return 0; -#endif - } -#ifdef BPF_ALIGN - if (((int)(p + k) & 3) != 0) - A = EXTRACT_LONG(&p[k]); - else -#endif - A = ntohl(*(long *)(p + k)); - continue; - - case BPF_LD|BPF_H|BPF_IND: - k = X + pc->k; - if (k + sizeof(short) > buflen) { -#ifdef KERNEL - int merr; - - if (buflen != 0) - return 0; - A = m_xhalf((struct mbuf *)p, k, &merr); - if (merr != 0) - return 0; - continue; -#else - return 0; -#endif - } - A = EXTRACT_SHORT(&p[k]); - continue; - - case BPF_LD|BPF_B|BPF_IND: - k = X + pc->k; - if (k >= buflen) { -#ifdef KERNEL - register struct mbuf *m; - - if (buflen != 0) - return 0; - m = (struct mbuf *)p; - MINDEX(m, k); - A = mtod(m, char *)[k]; - continue; -#else - return 0; -#endif - } - A = p[k]; - continue; - - case BPF_LDX|BPF_MSH|BPF_B: - k = pc->k; - if (k >= buflen) { -#ifdef KERNEL - register struct mbuf *m; - - if (buflen != 0) - return 0; - m = (struct mbuf *)p; - MINDEX(m, k); - X = (mtod(m, char *)[k] & 0xf) << 2; - continue; -#else - return 0; -#endif - } - X = (p[pc->k] & 0xf) << 2; - continue; - - case BPF_LD|BPF_IMM: - A = pc->k; - continue; - - case BPF_LDX|BPF_IMM: - X = pc->k; - continue; - - case BPF_LD|BPF_MEM: - A = mem[pc->k]; - continue; - - case BPF_LDX|BPF_MEM: - X = mem[pc->k]; - continue; - - case BPF_ST: - mem[pc->k] = A; - continue; - - case BPF_STX: - mem[pc->k] = X; - continue; - - case BPF_JMP|BPF_JA: - pc += pc->k; - continue; - - case BPF_JMP|BPF_JGT|BPF_K: - pc += (A > pc->k) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JGE|BPF_K: - pc += (A >= pc->k) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JEQ|BPF_K: - pc += (A == pc->k) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JSET|BPF_K: - pc += (A & pc->k) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JGT|BPF_X: - pc += (A > X) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JGE|BPF_X: - pc += (A >= X) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JEQ|BPF_X: - pc += (A == X) ? pc->jt : pc->jf; - continue; - - case BPF_JMP|BPF_JSET|BPF_X: - pc += (A & X) ? pc->jt : pc->jf; - continue; - - case BPF_ALU|BPF_ADD|BPF_X: - A += X; - continue; - - case BPF_ALU|BPF_SUB|BPF_X: - A -= X; - continue; - - case BPF_ALU|BPF_MUL|BPF_X: - A *= X; - continue; - - case BPF_ALU|BPF_DIV|BPF_X: - if (X == 0) - return 0; - A /= X; - continue; - - case BPF_ALU|BPF_AND|BPF_X: - A &= X; - continue; - - case BPF_ALU|BPF_OR|BPF_X: - A |= X; - continue; - - case BPF_ALU|BPF_LSH|BPF_X: - A <<= X; - continue; - - case BPF_ALU|BPF_RSH|BPF_X: - A >>= X; - continue; - - case BPF_ALU|BPF_ADD|BPF_K: - A += pc->k; - continue; - - case BPF_ALU|BPF_SUB|BPF_K: - A -= pc->k; - continue; - - case BPF_ALU|BPF_MUL|BPF_K: - A *= pc->k; - continue; - - case BPF_ALU|BPF_DIV|BPF_K: - A /= pc->k; - continue; - - case BPF_ALU|BPF_AND|BPF_K: - A &= pc->k; - continue; - - case BPF_ALU|BPF_OR|BPF_K: - A |= pc->k; - continue; - - case BPF_ALU|BPF_LSH|BPF_K: - A <<= pc->k; - continue; - - case BPF_ALU|BPF_RSH|BPF_K: - A >>= pc->k; - continue; - - case BPF_ALU|BPF_NEG: - A = -A; - continue; - - case BPF_MISC|BPF_TAX: - X = A; - continue; - - case BPF_MISC|BPF_TXA: - A = X; - continue; - } - } -} - -#ifdef KERNEL -/* - * Return true if the 'fcode' is a valid filter program. - * The constraints are that each jump be forward and to a valid - * code. The code must terminate with either an accept or reject. - * 'valid' is an array for use by the routine (it must be at least - * 'len' bytes long). - * - * The kernel needs to be able to verify an application's filter code. - * Otherwise, a bogus program could easily crash the system. - */ -int -bpf_validate(f, len) - struct bpf_insn *f; - int len; -{ - register int i; - register struct bpf_insn *p; - - for (i = 0; i < len; ++i) { - /* - * Check that that jumps are forward, and within - * the code block. - */ - p = &f[i]; - if (BPF_CLASS(p->code) == BPF_JMP) { - register int from = i + 1; - - if (BPF_OP(p->code) == BPF_JA) { - if (from + p->k >= len) - return 0; - } - else if (from + p->jt >= len || from + p->jf >= len) - return 0; - } - /* - * Check that memory operations use valid addresses. - */ - if ((BPF_CLASS(p->code) == BPF_ST || - (BPF_CLASS(p->code) == BPF_LD && - (p->code & 0xe0) == BPF_MEM)) && - (p->k >= BPF_MEMWORDS || p->k < 0)) - return 0; - /* - * Check for constant division by 0. - */ - if (p->code == (BPF_ALU|BPF_DIV|BPF_K) && p->k == 0) - return 0; - } - return BPF_CLASS(f[len - 1].code) == BPF_RET; -} -#endif diff --git a/pcap/bpf_image.c b/pcap/bpf_image.c deleted file mode 100644 index f5177d9..0000000 --- a/pcap/bpf_image.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD */ - -/* - * Copyright (c) 1990, 1991, 1992, 1994, 1995 - * 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. - */ - -#ifndef lint -static char rcsid[] = - "@(#) Header: bpf_image.c,v 1.19 95/11/26 14:02:36 leres Exp (LBL)"; -#endif - -#include -#include - -#include - -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -char * -bpf_image(p, n) - struct bpf_insn *p; - int n; -{ - int v; - char *fmt, *op; - static char image[256]; - char operand[64]; - - v = p->k; - switch (p->code) { - - default: - op = "unimp"; - fmt = "0x%x"; - v = p->code; - break; - - case BPF_RET|BPF_K: - op = "ret"; - fmt = "#%d"; - break; - - case BPF_RET|BPF_A: - op = "ret"; - fmt = ""; - break; - - case BPF_LD|BPF_W|BPF_ABS: - op = "ld"; - fmt = "[%d]"; - break; - - case BPF_LD|BPF_H|BPF_ABS: - op = "ldh"; - fmt = "[%d]"; - break; - - case BPF_LD|BPF_B|BPF_ABS: - op = "ldb"; - fmt = "[%d]"; - break; - - case BPF_LD|BPF_W|BPF_LEN: - op = "ld"; - fmt = "#pktlen"; - break; - - case BPF_LD|BPF_W|BPF_IND: - op = "ld"; - fmt = "[x + %d]"; - break; - - case BPF_LD|BPF_H|BPF_IND: - op = "ldh"; - fmt = "[x + %d]"; - break; - - case BPF_LD|BPF_B|BPF_IND: - op = "ldb"; - fmt = "[x + %d]"; - break; - - case BPF_LD|BPF_IMM: - op = "ld"; - fmt = "#0x%x"; - break; - - case BPF_LDX|BPF_IMM: - op = "ldx"; - fmt = "#0x%x"; - break; - - case BPF_LDX|BPF_MSH|BPF_B: - op = "ldxb"; - fmt = "4*([%d]&0xf)"; - break; - - case BPF_LD|BPF_MEM: - op = "ld"; - fmt = "M[%d]"; - break; - - case BPF_LDX|BPF_MEM: - op = "ldx"; - fmt = "M[%d]"; - break; - - case BPF_ST: - op = "st"; - fmt = "M[%d]"; - break; - - case BPF_STX: - op = "stx"; - fmt = "M[%d]"; - break; - - case BPF_JMP|BPF_JA: - op = "ja"; - fmt = "%d"; - v = n + 1 + p->k; - break; - - case BPF_JMP|BPF_JGT|BPF_K: - op = "jgt"; - fmt = "#0x%x"; - break; - - case BPF_JMP|BPF_JGE|BPF_K: - op = "jge"; - fmt = "#0x%x"; - break; - - case BPF_JMP|BPF_JEQ|BPF_K: - op = "jeq"; - fmt = "#0x%x"; - break; - - case BPF_JMP|BPF_JSET|BPF_K: - op = "jset"; - fmt = "#0x%x"; - break; - - case BPF_JMP|BPF_JGT|BPF_X: - op = "jgt"; - fmt = "x"; - break; - - case BPF_JMP|BPF_JGE|BPF_X: - op = "jge"; - fmt = "x"; - break; - - case BPF_JMP|BPF_JEQ|BPF_X: - op = "jeq"; - fmt = "x"; - break; - - case BPF_JMP|BPF_JSET|BPF_X: - op = "jset"; - fmt = "x"; - break; - - case BPF_ALU|BPF_ADD|BPF_X: - op = "add"; - fmt = "x"; - break; - - case BPF_ALU|BPF_SUB|BPF_X: - op = "sub"; - fmt = "x"; - break; - - case BPF_ALU|BPF_MUL|BPF_X: - op = "mul"; - fmt = "x"; - break; - - case BPF_ALU|BPF_DIV|BPF_X: - op = "div"; - fmt = "x"; - break; - - case BPF_ALU|BPF_AND|BPF_X: - op = "and"; - fmt = "x"; - break; - - case BPF_ALU|BPF_OR|BPF_X: - op = "or"; - fmt = "x"; - break; - - case BPF_ALU|BPF_LSH|BPF_X: - op = "lsh"; - fmt = "x"; - break; - - case BPF_ALU|BPF_RSH|BPF_X: - op = "rsh"; - fmt = "x"; - break; - - case BPF_ALU|BPF_ADD|BPF_K: - op = "add"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_SUB|BPF_K: - op = "sub"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_MUL|BPF_K: - op = "mul"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_DIV|BPF_K: - op = "div"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_AND|BPF_K: - op = "and"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_OR|BPF_K: - op = "or"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_LSH|BPF_K: - op = "lsh"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_RSH|BPF_K: - op = "rsh"; - fmt = "#%d"; - break; - - case BPF_ALU|BPF_NEG: - op = "neg"; - fmt = ""; - break; - - case BPF_MISC|BPF_TAX: - op = "tax"; - fmt = ""; - break; - - case BPF_MISC|BPF_TXA: - op = "txa"; - fmt = ""; - break; - } - (void)sprintf(operand, fmt, v); - (void)sprintf(image, - (BPF_CLASS(p->code) == BPF_JMP && - BPF_OP(p->code) != BPF_JA) ? - "(%03d) %-8s %-16s jt %d\tjf %d" - : "(%03d) %-8s %s", - n, op, operand, n + 1 + p->jt, n + 1 + p->jf); - return image; -} diff --git a/pcap/etherent.c b/pcap/etherent.c deleted file mode 100644 index 3b2347e..0000000 --- a/pcap/etherent.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: etherent.c,v 1.5 1996/09/16 02:33:04 tholo Exp $ */ - -/* - * Copyright (c) 1990, 1993, 1994, 1995 - * 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. - */ -#ifndef lint -static char rcsid[] = - "@(#) Header: etherent.c,v 1.18 95/10/07 03:08:12 leres Exp (LBL)"; -#endif - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -static __inline int xdtoi(int); -static __inline int skip_space(FILE *); -static __inline int skip_line(FILE *); - -/* Hex digit to integer. */ -static __inline int -xdtoi(c) - register int c; -{ - if (isdigit(c)) - return c - '0'; - else if (islower(c)) - return c - 'a' + 10; - else - return c - 'A' + 10; -} - -static __inline int -skip_space(f) - FILE *f; -{ - int c; - - do { - c = getc(f); - } while (isspace(c) && c != '\n'); - - return c; -} - -static __inline int -skip_line(f) - FILE *f; -{ - int c; - - do - c = getc(f); - while (c != '\n' && c != EOF); - - return c; -} - -struct pcap_etherent * -pcap_next_etherent(FILE *fp) -{ - register int c, d, i; - char *bp; - static struct pcap_etherent e; - - memset((char *)&e, 0, sizeof(e)); - do { - /* Find addr */ - c = skip_space(fp); - if (c == '\n') - continue; - - /* If this is a comment, or first thing on line - cannot be etehrnet address, skip the line. */ - if (!isxdigit(c)) { - c = skip_line(fp); - continue; - } - - /* must be the start of an address */ - for (i = 0; i < 6; i += 1) { - d = xdtoi(c); - c = getc(fp); - if (isxdigit(c)) { - d <<= 4; - d |= xdtoi(c); - c = getc(fp); - } - e.addr[i] = d; - if (c != ':') - break; - c = getc(fp); - } - if (c == EOF) - break; - - /* Must be whitespace */ - if (!isspace(c)) { - c = skip_line(fp); - continue; - } - c = skip_space(fp); - - /* hit end of line... */ - if (c == '\n') - continue; - - if (c == '#') { - c = skip_line(fp); - continue; - } - - /* pick up name */ - bp = e.name; - /* Use 'd' to prevent buffer overflow. */ - d = sizeof(e.name) - 1; - do { - *bp++ = c; - c = getc(fp); - } while (!isspace(c) && c != EOF && --d > 0); - *bp = '\0'; - - /* Eat trailing junk */ - if (c != '\n') - (void)skip_line(fp); - - return &e; - - } while (c != EOF); - - return (NULL); -} diff --git a/pcap/ethertype.h b/pcap/ethertype.h deleted file mode 100644 index 0a046fa..0000000 --- a/pcap/ethertype.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD */ -/* $NetBSD: ethertype.h,v 1.2 1995/03/06 11:38:17 mycroft Exp $ */ - -/* - * Copyright (c) 1993, 1994 - * 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: ethertype.h,v 1.2 94/06/14 20:03:27 leres Exp (LBL) - */ - -/* Map between Ethernet protocol types and names */ - -/* Add other Ethernet packet types here */ -#ifndef ETHERTYPE_SPRITE -#define ETHERTYPE_SPRITE 0x0500 -#endif -#ifndef ETHERTYPE_MOPDL -#define ETHERTYPE_MOPDL 0x6001 -#endif -#ifndef ETHERTYPE_MOPRC -#define ETHERTYPE_MOPRC 0x6002 -#endif -#ifndef ETHERTYPE_DN -#define ETHERTYPE_DN 0x6003 -#endif -#ifndef ETHERTYPE_LAT -#define ETHERTYPE_LAT 0x6004 -#endif -#ifndef ETHERTYPE_LANBRIDGE -#define ETHERTYPE_LANBRIDGE 0x8038 -#endif -#ifndef ETHERTYPE_DECDNS -#define ETHERTYPE_DECDNS 0x803c -#endif -#ifndef ETHERTYPE_DECDTS -#define ETHERTYPE_DECDTS 0x803e -#endif -#ifndef ETHERTYPE_VEXP -#define ETHERTYPE_VEXP 0x805b -#endif -#ifndef ETHERTYPE_VPROD -#define ETHERTYPE_VPROD 0x805c -#endif -#ifndef ETHERTYPE_LOOPBACK -#define ETHERTYPE_LOOPBACK 0x9000 -#endif - -#ifndef ETHERTYPE_ATALK -#define ETHERTYPE_ATALK 0x809b /* XXX */ -#endif -#ifndef ETHERTYPE_AARP -#define ETHERTYPE_AARP 0x80f3 -#endif -#ifndef ETHERTYPE_NS -#define ETHERTYPE_NS 0x0600 -#endif - -#ifndef ETHERTYPE_REVARP -#define ETHERTYPE_REVARP 0x8035 -#endif - diff --git a/pcap/gencode.c b/pcap/gencode.c deleted file mode 100644 index dfcd9e4..0000000 --- a/pcap/gencode.c +++ /dev/null @@ -1,1843 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: gencode.c,v 1.5 1996/09/16 02:33:05 tholo Exp $ */ - -/* - * Copyright (c) 1990, 1991, 1992, 1993, 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. - */ -#ifndef lint -static char rcsid[] = - "@(#) Header: gencode.c,v 1.81 96/06/19 23:09:09 leres Exp (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#if __STDC__ -#include -#else -#include -#endif - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -#include "gencode.h" - -#ifndef ETHERTYPE_REVARP -#define ETHERTYPE_REVARP 0x8035 -#endif -#ifndef ETHERTYPE_MOPDL -#define ETHERTYPE_MOPDL 0x6001 -#endif -#ifndef ETHERTYPE_MOPRC -#define ETHERTYPE_MOPRC 0x6002 -#endif -#ifndef ETHERTYPE_DN -#define ETHERTYPE_DN 0x6003 -#endif -#ifndef ETHERTYPE_LAT -#define ETHERTYPE_LAT 0x6004 -#endif - -#define JMP(c) ((c)|BPF_JMP|BPF_K) - -/* Locals */ -static jmp_buf top_ctx; -static pcap_t *bpf_pcap; - -/* XXX */ -#ifdef PCAP_FDDIPAD -int pcap_fddipad = PCAP_FDDIPAD; -#else -int pcap_fddipad; -#endif -#ifndef DLT_ATM_RFC1483 -#define DLT_ATM_RFC1483 11 -#endif - - -/* VARARGS */ -__dead void -#if __STDC__ -bpf_error(const char *fmt, ...) -#else -bpf_error(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - if (bpf_pcap != NULL) - (void)vsprintf(pcap_geterr(bpf_pcap), fmt, ap); - va_end(ap); - longjmp(top_ctx, 1); - /* NOTREACHED */ -} - -static void init_linktype(int); - -static int alloc_reg(void); -static void free_reg(int); - -static struct block *root; - -/* - * We divy out chunks of memory rather than call malloc each time so - * we don't have to worry about leaking memory. It's probably - * not a big deal if all this memory was wasted but it this ever - * goes into a library that would probably not be a good idea. - */ -#define NCHUNKS 16 -#define CHUNK0SIZE 1024 -struct chunk { - u_int n_left; - void *m; -}; - -static struct chunk chunks[NCHUNKS]; -static int cur_chunk; - -static void *newchunk(u_int); -static void freechunks(void); -static __inline struct block *new_block(int); -static __inline struct slist *new_stmt(int); -static struct block *gen_retblk(int); -static __inline void syntax(void); - -static void backpatch(struct block *, struct block *); -static void merge(struct block *, struct block *); -static struct block *gen_cmp(u_int, u_int, bpf_int32); -static struct block *gen_mcmp(u_int, u_int, bpf_int32, bpf_u_int32); -static struct block *gen_bcmp(u_int, u_int, u_char *); -static struct block *gen_uncond(int); -static __inline struct block *gen_true(void); -static __inline struct block *gen_false(void); -static struct block *gen_linktype(int); -static struct block *gen_hostop(bpf_u_int32, bpf_u_int32, int, int, u_int, u_int); -static struct block *gen_ehostop(u_char *, int); -static struct block *gen_fhostop(u_char *, int); -static struct block *gen_dnhostop(bpf_u_int32, int, u_int); -static struct block *gen_host(bpf_u_int32, bpf_u_int32, int, int); -static struct block *gen_gateway(u_char *, bpf_u_int32 **, int, int); -static struct block *gen_ipfrag(void); -static struct block *gen_portatom(int, bpf_int32); -struct block *gen_portop(int, int, int); -static struct block *gen_port(int, int, int); -static int lookup_proto(char *, int); -static struct block *gen_proto(int, int, int); -static bpf_u_int32 net_mask(bpf_u_int32 *); -static struct slist *xfer_to_x(struct arth *); -static struct slist *xfer_to_a(struct arth *); -static struct block *gen_len(int, int); - -static void * -newchunk(n) - u_int n; -{ - struct chunk *cp; - int k, size; - - /* XXX Round up to nearest long. */ - n = (n + sizeof(long) - 1) & ~(sizeof(long) - 1); - - cp = &chunks[cur_chunk]; - if (n > cp->n_left) { - ++cp, k = ++cur_chunk; - if (k >= NCHUNKS) - bpf_error("out of memory"); - size = CHUNK0SIZE << k; - cp->m = (void *)malloc(size); - memset((char *)cp->m, 0, size); - cp->n_left = size; - if (n > size) - bpf_error("out of memory"); - } - cp->n_left -= n; - return (void *)((char *)cp->m + cp->n_left); -} - -static void -freechunks() -{ - int i; - - cur_chunk = 0; - for (i = 0; i < NCHUNKS; ++i) - if (chunks[i].m != NULL) { - free(chunks[i].m); - chunks[i].m = NULL; - } -} - -/* - * A strdup whose allocations are freed after code generation is over. - */ -char * -sdup(s) - char *s; -{ - int n = strlen(s) + 1; - char *cp = newchunk(n); - strcpy(cp, s); - return (cp); -} - -static __inline struct block * -new_block(code) - int code; -{ - struct block *p; - - p = (struct block *)newchunk(sizeof(*p)); - p->s.code = code; - p->head = p; - - return p; -} - -static __inline struct slist * -new_stmt(code) - int code; -{ - struct slist *p; - - p = (struct slist *)newchunk(sizeof(*p)); - p->s.code = code; - - return p; -} - -static struct block * -gen_retblk(v) - int v; -{ - struct block *b = new_block(BPF_RET|BPF_K); - - b->s.k = v; - return b; -} - -static __inline void -syntax() -{ - bpf_error("syntax error in filter expression"); -} - -static bpf_u_int32 netmask; -static int snaplen; - -int -pcap_compile(pcap_t *p, struct bpf_program *program, - char *buf, int optimize, bpf_u_int32 mask) -{ - extern int n_errors; - int len; - - n_errors = 0; - root = NULL; - bpf_pcap = p; - if (setjmp(top_ctx)) { - freechunks(); - return (-1); - } - - netmask = mask; - snaplen = pcap_snapshot(p); - - lex_init(buf ? buf : ""); - init_linktype(pcap_datalink(p)); - (void)pcap_parse(); - - if (n_errors) - syntax(); - - if (root == NULL) - root = gen_retblk(snaplen); - - if (optimize) { - bpf_optimize(&root); - if (root == NULL || - (root->s.code == (BPF_RET|BPF_K) && root->s.k == 0)) - bpf_error("expression rejects all packets"); - } - program->bf_insns = icode_to_fcode(root, &len); - program->bf_len = len; - - freechunks(); - return (0); -} - -/* - * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates - * which of the jt and jf fields has been resolved and which is a pointer - * back to another unresolved block (or nil). At least one of the fields - * in each block is already resolved. - */ -static void -backpatch(list, target) - struct block *list, *target; -{ - struct block *next; - - while (list) { - if (!list->sense) { - next = JT(list); - JT(list) = target; - } else { - next = JF(list); - JF(list) = target; - } - list = next; - } -} - -/* - * Merge the lists in b0 and b1, using the 'sense' field to indicate - * which of jt and jf is the link. - */ -static void -merge(b0, b1) - struct block *b0, *b1; -{ - register struct block **p = &b0; - - /* Find end of list. */ - while (*p) - p = !((*p)->sense) ? &JT(*p) : &JF(*p); - - /* Concatenate the lists. */ - *p = b1; -} - -void -finish_parse(p) - struct block *p; -{ - backpatch(p, gen_retblk(snaplen)); - p->sense = !p->sense; - backpatch(p, gen_retblk(0)); - root = p->head; -} - -void -gen_and(b0, b1) - struct block *b0, *b1; -{ - backpatch(b0, b1->head); - b0->sense = !b0->sense; - b1->sense = !b1->sense; - merge(b1, b0); - b1->sense = !b1->sense; - b1->head = b0->head; -} - -void -gen_or(b0, b1) - struct block *b0, *b1; -{ - b0->sense = !b0->sense; - backpatch(b0, b1->head); - b0->sense = !b0->sense; - merge(b1, b0); - b1->head = b0->head; -} - -void -gen_not(b) - struct block *b; -{ - b->sense = !b->sense; -} - -static struct block * -gen_cmp(offset, size, v) - u_int offset, size; - bpf_int32 v; -{ - struct slist *s; - struct block *b; - - s = new_stmt(BPF_LD|BPF_ABS|size); - s->s.k = offset; - - b = new_block(JMP(BPF_JEQ)); - b->stmts = s; - b->s.k = v; - - return b; -} - -static struct block * -gen_mcmp(offset, size, v, mask) - u_int offset, size; - bpf_int32 v; - bpf_u_int32 mask; -{ - struct block *b = gen_cmp(offset, size, v); - struct slist *s; - - if (mask != 0xffffffff) { - s = new_stmt(BPF_ALU|BPF_AND|BPF_K); - s->s.k = mask; - b->stmts->next = s; - } - return b; -} - -static struct block * -gen_bcmp(offset, size, v) - u_int offset, size; - u_char *v; -{ - struct block *b, *tmp; - - b = NULL; - while (size >= 4) { - u_char *p = &v[size - 4]; - bpf_int32 w = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; - tmp = gen_cmp(offset + size - 4, BPF_W, w); - if (b != NULL) - gen_and(b, tmp); - b = tmp; - size -= 4; - } - while (size >= 2) { - u_char *p = &v[size - 2]; - bpf_int32 w = (p[0] << 8) | p[1]; - tmp = gen_cmp(offset + size - 2, BPF_H, w); - if (b != NULL) - gen_and(b, tmp); - b = tmp; - size -= 2; - } - if (size > 0) { - tmp = gen_cmp(offset, BPF_B, (bpf_int32)v[0]); - if (b != NULL) - gen_and(b, tmp); - b = tmp; - } - return b; -} - -/* - * Various code constructs need to know the layout of the data link - * layer. These variables give the necessary offsets. off_linktype - * is set to -1 for no encapsulation, in which case, IP is assumed. - */ -static u_int off_linktype; -static u_int off_nl; -static int linktype; - -static void -init_linktype(type) - int type; -{ - linktype = type; - - switch (type) { - - case DLT_EN10MB: - off_linktype = 12; - off_nl = 14; - return; - - case DLT_SLIP: - /* - * SLIP doesn't have a link level type. The 16 byte - * header is hacked into our SLIP driver. - */ - off_linktype = -1; - off_nl = 16; - return; - - case DLT_NULL: - off_linktype = -1; - off_nl = 0; - return; - - case DLT_PPP: - off_linktype = 2; - off_nl = 4; - return; - - case DLT_FDDI: - /* - * FDDI doesn't really have a link-level type field. - * We assume that SSAP = SNAP is being used and pick - * out the encapsulated Ethernet type. - */ - off_linktype = 19; -#ifdef PCAP_FDDIPAD - off_linktype += pcap_fddipad; -#endif - off_nl = 21; -#ifdef PCAP_FDDIPAD - off_nl += pcap_fddipad; -#endif - return; - - case DLT_IEEE802: - off_linktype = 20; - off_nl = 22; - return; - - case DLT_ATM_RFC1483: - /* - * assume routed, non-ISO PDUs - * (i.e., LLC = 0xAA-AA-03, OUT = 0x00-00-00) - */ - off_linktype = 6; - off_nl = 8; - return; - } - bpf_error("unknown data link type 0x%x", linktype); - /* NOTREACHED */ -} - -static struct block * -gen_uncond(rsense) - int rsense; -{ - struct block *b; - struct slist *s; - - s = new_stmt(BPF_LD|BPF_IMM); - s->s.k = !rsense; - b = new_block(JMP(BPF_JEQ)); - b->stmts = s; - - return b; -} - -static __inline struct block * -gen_true() -{ - return gen_uncond(1); -} - -static __inline struct block * -gen_false() -{ - return gen_uncond(0); -} - -static struct block * -gen_linktype(proto) - int proto; -{ - switch (linktype) { - case DLT_SLIP: - if (proto == ETHERTYPE_IP) - return gen_true(); - else - return gen_false(); - - case DLT_PPP: - if (proto == ETHERTYPE_IP) - proto = 0x0021; /* XXX - need ppp.h defs */ - break; - - case DLT_NULL: - /* XXX */ - if (proto == ETHERTYPE_IP) - return (gen_cmp(0, BPF_W, (bpf_int32)AF_INET)); - else - return gen_false(); - } - return gen_cmp(off_linktype, BPF_H, (bpf_int32)proto); -} - -static struct block * -gen_hostop(addr, mask, dir, proto, src_off, dst_off) - bpf_u_int32 addr; - bpf_u_int32 mask; - int dir, proto; - u_int src_off, dst_off; -{ - struct block *b0, *b1; - u_int offset; - - switch (dir) { - - case Q_SRC: - offset = src_off; - break; - - case Q_DST: - offset = dst_off; - break; - - case Q_AND: - b0 = gen_hostop(addr, mask, Q_SRC, proto, src_off, dst_off); - b1 = gen_hostop(addr, mask, Q_DST, proto, src_off, dst_off); - gen_and(b0, b1); - return b1; - - case Q_OR: - case Q_DEFAULT: - b0 = gen_hostop(addr, mask, Q_SRC, proto, src_off, dst_off); - b1 = gen_hostop(addr, mask, Q_DST, proto, src_off, dst_off); - gen_or(b0, b1); - return b1; - - default: - abort(); - } - b0 = gen_linktype(proto); - b1 = gen_mcmp(offset, BPF_W, (bpf_int32)addr, mask); - gen_and(b0, b1); - return b1; -} - -static struct block * -gen_ehostop(eaddr, dir) - u_char *eaddr; - int dir; -{ - struct block *b0, *b1; - - switch (dir) { - case Q_SRC: - return gen_bcmp(6, 6, eaddr); - - case Q_DST: - return gen_bcmp(0, 6, eaddr); - - case Q_AND: - b0 = gen_ehostop(eaddr, Q_SRC); - b1 = gen_ehostop(eaddr, Q_DST); - gen_and(b0, b1); - return b1; - - case Q_DEFAULT: - case Q_OR: - b0 = gen_ehostop(eaddr, Q_SRC); - b1 = gen_ehostop(eaddr, Q_DST); - gen_or(b0, b1); - return b1; - } - abort(); - /* NOTREACHED */ -} - -/* - * Like gen_ehostop, but for DLT_FDDI - */ -static struct block * -gen_fhostop(eaddr, dir) - u_char *eaddr; - int dir; -{ - struct block *b0, *b1; - - switch (dir) { - case Q_SRC: -#ifdef PCAP_FDDIPAD - return gen_bcmp(6 + 1 + pcap_fddipad, 6, eaddr); -#else - return gen_bcmp(6 + 1, 6, eaddr); -#endif - - case Q_DST: -#ifdef PCAP_FDDIPAD - return gen_bcmp(0 + 1 + pcap_fddipad, 6, eaddr); -#else - return gen_bcmp(0 + 1, 6, eaddr); -#endif - - case Q_AND: - b0 = gen_fhostop(eaddr, Q_SRC); - b1 = gen_fhostop(eaddr, Q_DST); - gen_and(b0, b1); - return b1; - - case Q_DEFAULT: - case Q_OR: - b0 = gen_fhostop(eaddr, Q_SRC); - b1 = gen_fhostop(eaddr, Q_DST); - gen_or(b0, b1); - return b1; - } - abort(); - /* NOTREACHED */ -} - -/* - * This is quite tricky because there may be pad bytes in front of the - * DECNET header, and then there are two possible data packet formats that - * carry both src and dst addresses, plus 5 packet types in a format that - * carries only the src node, plus 2 types that use a different format and - * also carry just the src node. - * - * Yuck. - * - * Instead of doing those all right, we just look for data packets with - * 0 or 1 bytes of padding. If you want to look at other packets, that - * will require a lot more hacking. - * - * To add support for filtering on DECNET "areas" (network numbers) - * one would want to add a "mask" argument to this routine. That would - * make the filter even more inefficient, although one could be clever - * and not generate masking instructions if the mask is 0xFFFF. - */ -static struct block * -gen_dnhostop(addr, dir, base_off) - bpf_u_int32 addr; - int dir; - u_int base_off; -{ - struct block *b0, *b1, *b2, *tmp; - u_int offset_lh; /* offset if long header is received */ - u_int offset_sh; /* offset if short header is received */ - - switch (dir) { - - case Q_DST: - offset_sh = 1; /* follows flags */ - offset_lh = 7; /* flgs,darea,dsubarea,HIORD */ - break; - - case Q_SRC: - offset_sh = 3; /* follows flags, dstnode */ - offset_lh = 15; /* flgs,darea,dsubarea,did,sarea,ssub,HIORD */ - break; - - case Q_AND: - /* Inefficient because we do our Calvinball dance twice */ - b0 = gen_dnhostop(addr, Q_SRC, base_off); - b1 = gen_dnhostop(addr, Q_DST, base_off); - gen_and(b0, b1); - return b1; - - case Q_OR: - case Q_DEFAULT: - /* Inefficient because we do our Calvinball dance twice */ - b0 = gen_dnhostop(addr, Q_SRC, base_off); - b1 = gen_dnhostop(addr, Q_DST, base_off); - gen_or(b0, b1); - return b1; - - default: - abort(); - } - b0 = gen_linktype(ETHERTYPE_DN); - /* Check for pad = 1, long header case */ - tmp = gen_mcmp(base_off + 2, BPF_H, - (bpf_int32)ntohs(0x0681), (bpf_int32)ntohs(0x07FF)); - b1 = gen_cmp(base_off + 2 + 1 + offset_lh, - BPF_H, (bpf_int32)ntohs(addr)); - gen_and(tmp, b1); - /* Check for pad = 0, long header case */ - tmp = gen_mcmp(base_off + 2, BPF_B, (bpf_int32)0x06, (bpf_int32)0x7); - b2 = gen_cmp(base_off + 2 + offset_lh, BPF_H, (bpf_int32)ntohs(addr)); - gen_and(tmp, b2); - gen_or(b2, b1); - /* Check for pad = 1, short header case */ - tmp = gen_mcmp(base_off + 2, BPF_H, - (bpf_int32)ntohs(0x0281), (bpf_int32)ntohs(0x07FF)); - b2 = gen_cmp(base_off + 2 + 1 + offset_sh, - BPF_H, (bpf_int32)ntohs(addr)); - gen_and(tmp, b2); - gen_or(b2, b1); - /* Check for pad = 0, short header case */ - tmp = gen_mcmp(base_off + 2, BPF_B, (bpf_int32)0x02, (bpf_int32)0x7); - b2 = gen_cmp(base_off + 2 + offset_sh, BPF_H, (bpf_int32)ntohs(addr)); - gen_and(tmp, b2); - gen_or(b2, b1); - - /* Combine with test for linktype */ - gen_and(b0, b1); - return b1; -} - -static struct block * -gen_host(addr, mask, proto, dir) - bpf_u_int32 addr; - bpf_u_int32 mask; - int proto; - int dir; -{ - struct block *b0, *b1; - - switch (proto) { - - case Q_DEFAULT: - b0 = gen_host(addr, mask, Q_IP, dir); - b1 = gen_host(addr, mask, Q_ARP, dir); - gen_or(b0, b1); - b0 = gen_host(addr, mask, Q_RARP, dir); - gen_or(b1, b0); - return b0; - - case Q_IP: - return gen_hostop(addr, mask, dir, ETHERTYPE_IP, - off_nl + 12, off_nl + 16); - - case Q_RARP: - return gen_hostop(addr, mask, dir, ETHERTYPE_REVARP, - off_nl + 14, off_nl + 24); - - case Q_ARP: - return gen_hostop(addr, mask, dir, ETHERTYPE_ARP, - off_nl + 14, off_nl + 24); - - case Q_TCP: - bpf_error("'tcp' modifier applied to host"); - - case Q_UDP: - bpf_error("'udp' modifier applied to host"); - - case Q_ICMP: - bpf_error("'icmp' modifier applied to host"); - - case Q_IGMP: - bpf_error("'igmp' modifier applied to host"); - - case Q_DECNET: - return gen_dnhostop(addr, dir, off_nl); - - case Q_LAT: - bpf_error("LAT host filtering not implemented"); - - case Q_MOPDL: - bpf_error("MOPDL host filtering not implemented"); - - case Q_MOPRC: - bpf_error("MOPRC host filtering not implemented"); - - default: - abort(); - } - /* NOTREACHED */ -} - -static struct block * -gen_gateway(eaddr, alist, proto, dir) - u_char *eaddr; - bpf_u_int32 **alist; - int proto; - int dir; -{ - struct block *b0, *b1, *tmp; - - if (dir != 0) - bpf_error("direction applied to 'gateway'"); - - switch (proto) { - case Q_DEFAULT: - case Q_IP: - case Q_ARP: - case Q_RARP: - if (linktype == DLT_EN10MB) - b0 = gen_ehostop(eaddr, Q_OR); - else if (linktype == DLT_FDDI) - b0 = gen_fhostop(eaddr, Q_OR); - else - bpf_error( - "'gateway' supported only on ethernet or FDDI"); - - b1 = gen_host(**alist++, 0xffffffffL, proto, Q_OR); - while (*alist) { - tmp = gen_host(**alist++, 0xffffffffL, proto, Q_OR); - gen_or(b1, tmp); - b1 = tmp; - } - gen_not(b1); - gen_and(b0, b1); - return b1; - } - bpf_error("illegal modifier of 'gateway'"); - /* NOTREACHED */ -} - -struct block * -gen_proto_abbrev(proto) - int proto; -{ - struct block *b0, *b1; - - switch (proto) { - - case Q_TCP: - b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)IPPROTO_TCP); - gen_and(b0, b1); - break; - - case Q_UDP: - b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)IPPROTO_UDP); - gen_and(b0, b1); - break; - - case Q_ICMP: - b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)IPPROTO_ICMP); - gen_and(b0, b1); - break; - - case Q_IGMP: - b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)2); - gen_and(b0, b1); - break; - - case Q_IP: - b1 = gen_linktype(ETHERTYPE_IP); - break; - - case Q_ARP: - b1 = gen_linktype(ETHERTYPE_ARP); - break; - - case Q_RARP: - b1 = gen_linktype(ETHERTYPE_REVARP); - break; - - case Q_LINK: - bpf_error("link layer applied in wrong context"); - - case Q_DECNET: - b1 = gen_linktype(ETHERTYPE_DN); - break; - - case Q_LAT: - b1 = gen_linktype(ETHERTYPE_LAT); - break; - - case Q_MOPDL: - b1 = gen_linktype(ETHERTYPE_MOPDL); - break; - - case Q_MOPRC: - b1 = gen_linktype(ETHERTYPE_MOPRC); - break; - - default: - abort(); - } - return b1; -} - -static struct block * -gen_ipfrag() -{ - struct slist *s; - struct block *b; - - /* not ip frag */ - s = new_stmt(BPF_LD|BPF_H|BPF_ABS); - s->s.k = off_nl + 6; - b = new_block(JMP(BPF_JSET)); - b->s.k = 0x1fff; - b->stmts = s; - gen_not(b); - - return b; -} - -static struct block * -gen_portatom(off, v) - int off; - bpf_int32 v; -{ - struct slist *s; - struct block *b; - - s = new_stmt(BPF_LDX|BPF_MSH|BPF_B); - s->s.k = off_nl; - - s->next = new_stmt(BPF_LD|BPF_IND|BPF_H); - s->next->s.k = off_nl + off; - - b = new_block(JMP(BPF_JEQ)); - b->stmts = s; - b->s.k = v; - - return b; -} - -struct block * -gen_portop(port, proto, dir) - int port, proto, dir; -{ - struct block *b0, *b1, *tmp; - - /* ip proto 'proto' */ - tmp = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)proto); - b0 = gen_ipfrag(); - gen_and(tmp, b0); - - switch (dir) { - case Q_SRC: - b1 = gen_portatom(0, (bpf_int32)port); - break; - - case Q_DST: - b1 = gen_portatom(2, (bpf_int32)port); - break; - - case Q_OR: - case Q_DEFAULT: - tmp = gen_portatom(0, (bpf_int32)port); - b1 = gen_portatom(2, (bpf_int32)port); - gen_or(tmp, b1); - break; - - case Q_AND: - tmp = gen_portatom(0, (bpf_int32)port); - b1 = gen_portatom(2, (bpf_int32)port); - gen_and(tmp, b1); - break; - - default: - abort(); - } - gen_and(b0, b1); - - return b1; -} - -static struct block * -gen_port(port, ip_proto, dir) - int port; - int ip_proto; - int dir; -{ - struct block *b0, *b1, *tmp; - - /* ether proto ip */ - b0 = gen_linktype(ETHERTYPE_IP); - - switch (ip_proto) { - case IPPROTO_UDP: - case IPPROTO_TCP: - b1 = gen_portop(port, ip_proto, dir); - break; - - case PROTO_UNDEF: - tmp = gen_portop(port, IPPROTO_TCP, dir); - b1 = gen_portop(port, IPPROTO_UDP, dir); - gen_or(tmp, b1); - break; - - default: - abort(); - } - gen_and(b0, b1); - return b1; -} - -static int -lookup_proto(name, proto) - char *name; - int proto; -{ - int v; - - switch (proto) { - case Q_DEFAULT: - case Q_IP: - v = pcap_nametoproto(name); - if (v == PROTO_UNDEF) - bpf_error("unknown ip proto '%s'", name); - break; - - case Q_LINK: - /* XXX should look up h/w protocol type based on linktype */ - v = pcap_nametoeproto(name); - if (v == PROTO_UNDEF) - bpf_error("unknown ether proto '%s'", name); - break; - - default: - v = PROTO_UNDEF; - break; - } - return v; -} - -static struct block * -gen_proto(v, proto, dir) - int v; - int proto; - int dir; -{ - struct block *b0, *b1; - - if (dir != Q_DEFAULT) - bpf_error("direction applied to 'proto'"); - - switch (proto) { - case Q_DEFAULT: - case Q_IP: - b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 9, BPF_B, (bpf_int32)v); - gen_and(b0, b1); - return b1; - - case Q_ARP: - bpf_error("arp does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_RARP: - bpf_error("rarp does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_DECNET: - bpf_error("decnet encapsulation is not specifiable"); - /* NOTREACHED */ - - case Q_LAT: - bpf_error("lat does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_MOPRC: - bpf_error("moprc does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_MOPDL: - bpf_error("mopdl does not encapsulate another protocol"); - /* NOTREACHED */ - - case Q_LINK: - return gen_linktype(v); - - case Q_UDP: - bpf_error("'udp proto' is bogus"); - /* NOTREACHED */ - - case Q_TCP: - bpf_error("'tcp proto' is bogus"); - /* NOTREACHED */ - - case Q_ICMP: - bpf_error("'icmp proto' is bogus"); - /* NOTREACHED */ - - case Q_IGMP: - bpf_error("'igmp proto' is bogus"); - /* NOTREACHED */ - - default: - abort(); - /* NOTREACHED */ - } - /* NOTREACHED */ -} - -/* - * Left justify 'addr' and return its resulting network mask. - */ -static bpf_u_int32 -net_mask(addr) - bpf_u_int32 *addr; -{ - register bpf_u_int32 m = 0xffffffff; - - if (*addr) - while ((*addr & 0xff000000) == 0) - *addr <<= 8, m <<= 8; - - return m; -} - -struct block * -gen_scode(name, q) - char *name; - struct qual q; -{ - int proto = q.proto; - int dir = q.dir; - u_char *eaddr; - bpf_u_int32 mask, addr, **alist; - struct block *b, *tmp; - int port, real_proto; - - switch (q.addr) { - - case Q_NET: - addr = pcap_nametonetaddr(name); - if (addr == 0) - bpf_error("unknown network '%s'", name); - mask = net_mask(&addr); - return gen_host(addr, mask, proto, dir); - - case Q_DEFAULT: - case Q_HOST: - if (proto == Q_LINK) { - switch (linktype) { - - case DLT_EN10MB: - eaddr = pcap_ether_hostton(name); - if (eaddr == NULL) - bpf_error( - "unknown ether host '%s'", name); - return gen_ehostop(eaddr, dir); - - case DLT_FDDI: - eaddr = pcap_ether_hostton(name); - if (eaddr == NULL) - bpf_error( - "unknown FDDI host '%s'", name); - return gen_fhostop(eaddr, dir); - - default: - bpf_error( - "only ethernet/FDDI supports link-level host name"); - break; - } - } else if (proto == Q_DECNET) { - unsigned short dn_addr = __pcap_nametodnaddr(name); - /* - * I don't think DECNET hosts can be multihomed, so - * there is no need to build up a list of addresses - */ - return (gen_host(dn_addr, 0, proto, dir)); - } else { - alist = pcap_nametoaddr(name); - if (alist == NULL || *alist == NULL) - bpf_error("unknown host '%s'", name); - b = gen_host(**alist++, 0xffffffffL, proto, dir); - while (*alist) { - tmp = gen_host(**alist++, 0xffffffffL, - proto, dir); - gen_or(b, tmp); - b = tmp; - } - return b; - } - - case Q_PORT: - if (proto != Q_DEFAULT && proto != Q_UDP && proto != Q_TCP) - bpf_error("illegal qualifier of 'port'"); - if (pcap_nametoport(name, &port, &real_proto) == 0) - bpf_error("unknown port '%s'", name); - if (proto == Q_UDP) { - if (real_proto == IPPROTO_TCP) - bpf_error("port '%s' is tcp", name); - else - /* override PROTO_UNDEF */ - real_proto = IPPROTO_UDP; - } - if (proto == Q_TCP) { - if (real_proto == IPPROTO_UDP) - bpf_error("port '%s' is udp", name); - else - /* override PROTO_UNDEF */ - real_proto = IPPROTO_TCP; - } - return gen_port(port, real_proto, dir); - - case Q_GATEWAY: - eaddr = pcap_ether_hostton(name); - if (eaddr == NULL) - bpf_error("unknown ether host: %s", name); - - alist = pcap_nametoaddr(name); - if (alist == NULL || *alist == NULL) - bpf_error("unknown host '%s'", name); - return gen_gateway(eaddr, alist, proto, dir); - - case Q_PROTO: - real_proto = lookup_proto(name, proto); - if (real_proto >= 0) - return gen_proto(real_proto, proto, dir); - else - bpf_error("unknown protocol: %s", name); - - case Q_UNDEF: - syntax(); - /* NOTREACHED */ - } - abort(); - /* NOTREACHED */ -} - -struct block * -gen_ncode(v, q) - bpf_u_int32 v; - struct qual q; -{ - bpf_u_int32 mask; - int proto = q.proto; - int dir = q.dir; - - switch (q.addr) { - - case Q_DEFAULT: - case Q_HOST: - case Q_NET: - if (proto == Q_DECNET) - return gen_host(v, 0, proto, dir); - else if (proto == Q_LINK) { - bpf_error("illegal link layer address"); - } else { - mask = net_mask(&v); - return gen_host(v, mask, proto, dir); - } - - case Q_PORT: - if (proto == Q_UDP) - proto = IPPROTO_UDP; - else if (proto == Q_TCP) - proto = IPPROTO_TCP; - else if (proto == Q_DEFAULT) - proto = PROTO_UNDEF; - else - bpf_error("illegal qualifier of 'port'"); - - return gen_port((int)v, proto, dir); - - case Q_GATEWAY: - bpf_error("'gateway' requires a name"); - /* NOTREACHED */ - - case Q_PROTO: - return gen_proto((int)v, proto, dir); - - case Q_UNDEF: - syntax(); - /* NOTREACHED */ - - default: - abort(); - /* NOTREACHED */ - } - /* NOTREACHED */ -} - -struct block * -gen_ecode(eaddr, q) - u_char *eaddr; - struct qual q; -{ - if ((q.addr == Q_HOST || q.addr == Q_DEFAULT) && q.proto == Q_LINK) { - if (linktype == DLT_EN10MB) - return gen_ehostop(eaddr, (int)q.dir); - if (linktype == DLT_FDDI) - return gen_fhostop(eaddr, (int)q.dir); - } - bpf_error("ethernet address used in non-ether expression"); - /* NOTREACHED */ -} - -void -sappend(s0, s1) - struct slist *s0, *s1; -{ - /* - * This is definitely not the best way to do this, but the - * lists will rarely get long. - */ - while (s0->next) - s0 = s0->next; - s0->next = s1; -} - -static struct slist * -xfer_to_x(a) - struct arth *a; -{ - struct slist *s; - - s = new_stmt(BPF_LDX|BPF_MEM); - s->s.k = a->regno; - return s; -} - -static struct slist * -xfer_to_a(a) - struct arth *a; -{ - struct slist *s; - - s = new_stmt(BPF_LD|BPF_MEM); - s->s.k = a->regno; - return s; -} - -struct arth * -gen_load(proto, index, size) - int proto; - struct arth *index; - int size; -{ - struct slist *s, *tmp; - struct block *b; - int regno = alloc_reg(); - - free_reg(index->regno); - switch (size) { - - default: - bpf_error("data size must be 1, 2, or 4"); - - case 1: - size = BPF_B; - break; - - case 2: - size = BPF_H; - break; - - case 4: - size = BPF_W; - break; - } - switch (proto) { - default: - bpf_error("unsupported index operation"); - - case Q_LINK: - s = xfer_to_x(index); - tmp = new_stmt(BPF_LD|BPF_IND|size); - sappend(s, tmp); - sappend(index->s, s); - break; - - case Q_IP: - case Q_ARP: - case Q_RARP: - case Q_DECNET: - case Q_LAT: - case Q_MOPRC: - case Q_MOPDL: - /* XXX Note that we assume a fixed link link header here. */ - s = xfer_to_x(index); - tmp = new_stmt(BPF_LD|BPF_IND|size); - tmp->s.k = off_nl; - sappend(s, tmp); - sappend(index->s, s); - - b = gen_proto_abbrev(proto); - if (index->b) - gen_and(index->b, b); - index->b = b; - break; - - case Q_TCP: - case Q_UDP: - case Q_ICMP: - case Q_IGMP: - s = new_stmt(BPF_LDX|BPF_MSH|BPF_B); - s->s.k = off_nl; - sappend(s, xfer_to_a(index)); - sappend(s, new_stmt(BPF_ALU|BPF_ADD|BPF_X)); - sappend(s, new_stmt(BPF_MISC|BPF_TAX)); - sappend(s, tmp = new_stmt(BPF_LD|BPF_IND|size)); - tmp->s.k = off_nl; - sappend(index->s, s); - - gen_and(gen_proto_abbrev(proto), b = gen_ipfrag()); - if (index->b) - gen_and(index->b, b); - index->b = b; - break; - } - index->regno = regno; - s = new_stmt(BPF_ST); - s->s.k = regno; - sappend(index->s, s); - - return index; -} - -struct block * -gen_relation(code, a0, a1, reversed) - int code; - struct arth *a0, *a1; - int reversed; -{ - struct slist *s0, *s1, *s2; - struct block *b, *tmp; - - s0 = xfer_to_x(a1); - s1 = xfer_to_a(a0); - s2 = new_stmt(BPF_ALU|BPF_SUB|BPF_X); - b = new_block(JMP(code)); - if (code == BPF_JGT || code == BPF_JGE) { - reversed = !reversed; - b->s.k = 0x80000000; - } - if (reversed) - gen_not(b); - - sappend(s1, s2); - sappend(s0, s1); - sappend(a1->s, s0); - sappend(a0->s, a1->s); - - b->stmts = a0->s; - - free_reg(a0->regno); - free_reg(a1->regno); - - /* 'and' together protocol checks */ - if (a0->b) { - if (a1->b) { - gen_and(a0->b, tmp = a1->b); - } - else - tmp = a0->b; - } else - tmp = a1->b; - - if (tmp) - gen_and(tmp, b); - - return b; -} - -struct arth * -gen_loadlen() -{ - int regno = alloc_reg(); - struct arth *a = (struct arth *)newchunk(sizeof(*a)); - struct slist *s; - - s = new_stmt(BPF_LD|BPF_LEN); - s->next = new_stmt(BPF_ST); - s->next->s.k = regno; - a->s = s; - a->regno = regno; - - return a; -} - -struct arth * -gen_loadi(val) - int val; -{ - struct arth *a; - struct slist *s; - int reg; - - a = (struct arth *)newchunk(sizeof(*a)); - - reg = alloc_reg(); - - s = new_stmt(BPF_LD|BPF_IMM); - s->s.k = val; - s->next = new_stmt(BPF_ST); - s->next->s.k = reg; - a->s = s; - a->regno = reg; - - return a; -} - -struct arth * -gen_neg(a) - struct arth *a; -{ - struct slist *s; - - s = xfer_to_a(a); - sappend(a->s, s); - s = new_stmt(BPF_ALU|BPF_NEG); - s->s.k = 0; - sappend(a->s, s); - s = new_stmt(BPF_ST); - s->s.k = a->regno; - sappend(a->s, s); - - return a; -} - -struct arth * -gen_arth(code, a0, a1) - int code; - struct arth *a0, *a1; -{ - struct slist *s0, *s1, *s2; - - s0 = xfer_to_x(a1); - s1 = xfer_to_a(a0); - s2 = new_stmt(BPF_ALU|BPF_X|code); - - sappend(s1, s2); - sappend(s0, s1); - sappend(a1->s, s0); - sappend(a0->s, a1->s); - - free_reg(a1->regno); - - s0 = new_stmt(BPF_ST); - a0->regno = s0->s.k = alloc_reg(); - sappend(a0->s, s0); - - return a0; -} - -/* - * Here we handle simple allocation of the scratch registers. - * If too many registers are alloc'd, the allocator punts. - */ -static int regused[BPF_MEMWORDS]; -static int curreg; - -/* - * Return the next free register. - */ -static int -alloc_reg() -{ - int n = BPF_MEMWORDS; - - while (--n >= 0) { - if (regused[curreg]) - curreg = (curreg + 1) % BPF_MEMWORDS; - else { - regused[curreg] = 1; - return curreg; - } - } - bpf_error("too many registers needed to evaluate expression"); - /* NOTREACHED */ -} - -/* - * Return a register to the table so it can - * be used later. - */ -static void -free_reg(n) - int n; -{ - regused[n] = 0; -} - -static struct block * -gen_len(jmp, n) - int jmp, n; -{ - struct slist *s; - struct block *b; - - s = new_stmt(BPF_LD|BPF_LEN); - b = new_block(JMP(jmp)); - b->stmts = s; - b->s.k = n; - - return b; -} - -struct block * -gen_greater(n) - int n; -{ - return gen_len(BPF_JGE, n); -} - -struct block * -gen_less(n) - int n; -{ - struct block *b; - - b = gen_len(BPF_JGT, n); - gen_not(b); - - return b; -} - -struct block * -gen_byteop(op, idx, val) - int op, idx, val; -{ - struct block *b; - struct slist *s; - - switch (op) { - default: - abort(); - - case '=': - return gen_cmp((u_int)idx, BPF_B, (bpf_int32)val); - - case '<': - b = gen_cmp((u_int)idx, BPF_B, (bpf_int32)val); - b->s.code = JMP(BPF_JGE); - gen_not(b); - return b; - - case '>': - b = gen_cmp((u_int)idx, BPF_B, (bpf_int32)val); - b->s.code = JMP(BPF_JGT); - return b; - - case '|': - s = new_stmt(BPF_ALU|BPF_OR|BPF_K); - break; - - case '&': - s = new_stmt(BPF_ALU|BPF_AND|BPF_K); - break; - } - s->s.k = val; - b = new_block(JMP(BPF_JEQ)); - b->stmts = s; - gen_not(b); - - return b; -} - -struct block * -gen_broadcast(proto) - int proto; -{ - bpf_u_int32 hostmask; - struct block *b0, *b1, *b2; - static u_char ebroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - - switch (proto) { - - case Q_DEFAULT: - case Q_LINK: - if (linktype == DLT_EN10MB) - return gen_ehostop(ebroadcast, Q_DST); - if (linktype == DLT_FDDI) - return gen_fhostop(ebroadcast, Q_DST); - bpf_error("not a broadcast link"); - break; - - case Q_IP: - b0 = gen_linktype(ETHERTYPE_IP); - hostmask = ~netmask; - b1 = gen_mcmp(off_nl + 16, BPF_W, (bpf_int32)0, hostmask); - b2 = gen_mcmp(off_nl + 16, BPF_W, - (bpf_int32)(~0 & hostmask), hostmask); - gen_or(b1, b2); - gen_and(b0, b2); - return b2; - } - bpf_error("only ether/ip broadcast filters supported"); -} - -struct block * -gen_multicast(proto) - int proto; -{ - register struct block *b0, *b1; - register struct slist *s; - - switch (proto) { - - case Q_DEFAULT: - case Q_LINK: - if (linktype == DLT_EN10MB) { - /* ether[0] & 1 != 0 */ - s = new_stmt(BPF_LD|BPF_B|BPF_ABS); - s->s.k = 0; - b0 = new_block(JMP(BPF_JSET)); - b0->s.k = 1; - b0->stmts = s; - return b0; - } - - if (linktype == DLT_FDDI) { - /* XXX TEST THIS: MIGHT NOT PORT PROPERLY XXX */ - /* fddi[1] & 1 != 0 */ - s = new_stmt(BPF_LD|BPF_B|BPF_ABS); - s->s.k = 1; - b0 = new_block(JMP(BPF_JSET)); - b0->s.k = 1; - b0->stmts = s; - return b0; - } - /* Link not known to support multicasts */ - break; - - case Q_IP: - b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 16, BPF_B, (bpf_int32)224); - b1->s.code = JMP(BPF_JGE); - gen_and(b0, b1); - return b1; - } - bpf_error("only IP multicast filters supported on ethernet/FDDI"); -} - -/* - * generate command for inbound/outbound. It's here so we can - * make it link-type specific. 'dir' = 0 implies "inbound", - * = 1 implies "outbound". - */ -struct block * -gen_inbound(dir) - int dir; -{ - register struct block *b0; - - b0 = gen_relation(BPF_JEQ, - gen_load(Q_LINK, gen_loadi(0), 1), - gen_loadi(0), - dir); - return (b0); -} diff --git a/pcap/gencode.h b/pcap/gencode.h deleted file mode 100644 index 33cb995..0000000 --- a/pcap/gencode.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: gencode.h,v 1.4 1996/07/12 13:19:08 mickey Exp $ */ - -/* - * Copyright (c) 1990, 1991, 1992, 1993, 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. - * - * @(#) Header: gencode.h,v 1.33 96/06/23 02:21:09 leres Exp (LBL) - */ - -/* Address qualifiers. */ - -#define Q_HOST 1 -#define Q_NET 2 -#define Q_PORT 3 -#define Q_GATEWAY 4 -#define Q_PROTO 5 - -/* Protocol qualifiers. */ - -#define Q_LINK 1 -#define Q_IP 2 -#define Q_ARP 3 -#define Q_RARP 4 -#define Q_TCP 5 -#define Q_UDP 6 -#define Q_ICMP 7 -#define Q_IGMP 8 - -#define Q_DECNET 9 -#define Q_LAT 10 -#define Q_MOPRC 11 -#define Q_MOPDL 12 - -/* Directional qualifiers. */ - -#define Q_SRC 1 -#define Q_DST 2 -#define Q_OR 3 -#define Q_AND 4 - -#define Q_DEFAULT 0 -#define Q_UNDEF 255 - -struct stmt { - int code; - bpf_int32 k; -}; - -struct slist { - struct stmt s; - struct slist *next; -}; - -/* - * A bit vector to represent definition sets. We assume TOT_REGISTERS - * is smaller than 8*sizeof(atomset). - */ -typedef bpf_u_int32 atomset; -#define ATOMMASK(n) (1 << (n)) -#define ATOMELEM(d, n) (d & ATOMMASK(n)) - -/* - * An unbounded set. - */ -typedef bpf_u_int32 *uset; - -/* - * Total number of atomic entities, including accumulator (A) and index (X). - * We treat all these guys similarly during flow analysis. - */ -#define N_ATOMS (BPF_MEMWORDS+2) - -struct edge { - int id; - int code; - uset edom; - struct block *succ; - struct block *pred; - struct edge *next; /* link list of incoming edges for a node */ -}; - -struct block { - int id; - struct slist *stmts; /* side effect stmts */ - struct stmt s; /* branch stmt */ - int mark; - int longjt; /* jt branch requires long jump */ - int longjf; /* jf branch requires long jump */ - int level; - int offset; - int sense; - struct edge et; - struct edge ef; - struct block *head; - struct block *link; /* link field used by optimizer */ - uset dom; - uset closure; - struct edge *in_edges; - atomset def, kill; - atomset in_use; - atomset out_use; - int oval; - int val[N_ATOMS]; -}; - -struct arth { - struct block *b; /* protocol checks */ - struct slist *s; /* stmt list */ - int regno; /* virtual register number of result */ -}; - -struct qual { - unsigned char addr; - unsigned char proto; - unsigned char dir; - unsigned char pad; -}; - -struct arth *gen_loadi(int); -struct arth *gen_load(int, struct arth *, int); -struct arth *gen_loadlen(void); -struct arth *gen_neg(struct arth *); -struct arth *gen_arth(int, struct arth *, struct arth *); - -void gen_and(struct block *, struct block *); -void gen_or(struct block *, struct block *); -void gen_not(struct block *); - -struct block *gen_scode(char *, struct qual); -struct block *gen_ecode(u_char *, struct qual); -struct block *gen_ncode(bpf_u_int32, struct qual); -struct block *gen_proto_abbrev(int); -struct block *gen_relation(int, struct arth *, struct arth *, int); -struct block *gen_less(int); -struct block *gen_greater(int); -struct block *gen_byteop(int, int, int); -struct block *gen_broadcast(int); -struct block *gen_multicast(int); -struct block *gen_inbound(int); - -void bpf_optimize(struct block **); -#if __STDC__ -__dead void bpf_error(const char *, ...) - __attribute__((volatile, format (printf, 1, 2))); -#endif - -void finish_parse(struct block *); -char *sdup(char *); - -struct bpf_insn *icode_to_fcode(struct block *, int *); -int pcap_parse(void); -void lex_init(char *); -void sappend(struct slist *, struct slist *); - -/* XXX */ -#define JT(b) ((b)->et.succ) -#define JF(b) ((b)->ef.succ) diff --git a/pcap/grammar.y b/pcap/grammar.y deleted file mode 100644 index 529ca97..0000000 --- a/pcap/grammar.y +++ /dev/null @@ -1,280 +0,0 @@ -%{ -/* $OpenBSD: grammar.y,v 1.4 1996/07/12 13:19:09 mickey Exp $ */ - -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - * - */ -#ifndef lint -static char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/pcap/grammar.y,v 1.1.1.1 1999/05/02 03:57:54 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif - -#include -#include - -#include -#include - -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" -#include "gencode.h" - -#define QSET(q, p, d, a) (q).proto = (p),\ - (q).dir = (d),\ - (q).addr = (a) - -int n_errors = 0; - -static struct qual qerr = { Q_UNDEF, Q_UNDEF, Q_UNDEF, Q_UNDEF }; - -static void -yyerror(char *msg) -{ - ++n_errors; - bpf_error(msg); - /* NOTREACHED */ -} - -#ifndef YYBISON -int yyparse(void); - -int -pcap_parse() -{ - return (yyparse()); -} -#endif - -%} - -%union { - int i; - u_long h; - u_char *e; - char *s; - struct stmt *stmt; - struct arth *a; - struct { - struct qual q; - struct block *b; - } blk; - struct block *rblk; -} - -%type expr id nid pid term rterm qid -%type head -%type pqual dqual aqual ndaqual -%type arth narth -%type byteop pname pnum relop irelop -%type and or paren not null prog -%type other - -%token DST SRC HOST GATEWAY -%token NET PORT LESS GREATER PROTO BYTE -%token ARP RARP IP TCP UDP ICMP IGMP -%token DECNET LAT MOPRC MOPDL -%token TK_BROADCAST TK_MULTICAST -%token NUM INBOUND OUTBOUND -%token LINK -%token GEQ LEQ NEQ -%token ID EID HID -%token LSH RSH -%token LEN - -%type ID -%type EID -%type HID -%type NUM - -%left OR AND -%nonassoc '!' -%left '|' -%left '&' -%left LSH RSH -%left '+' '-' -%left '*' '/' -%nonassoc UMINUS -%% -prog: null expr -{ - finish_parse($2.b); -} - | null - ; -null: /* null */ { $$.q = qerr; } - ; -expr: term - | expr and term { gen_and($1.b, $3.b); $$ = $3; } - | expr and id { gen_and($1.b, $3.b); $$ = $3; } - | expr or term { gen_or($1.b, $3.b); $$ = $3; } - | expr or id { gen_or($1.b, $3.b); $$ = $3; } - ; -and: AND { $$ = $0; } - ; -or: OR { $$ = $0; } - ; -id: nid - | pnum { $$.b = gen_ncode((u_long)$1, - $$.q = $0.q); } - | paren pid ')' { $$ = $2; } - ; -nid: ID { $$.b = gen_scode($1, $$.q = $0.q); } - | HID { - /* Decide how to parse HID based on proto */ - $$.q = $0.q; - switch ($$.q.proto) { - case Q_DECNET: - $$.b = - gen_ncode(__pcap_atodn((char *)$1), - $$.q); - break; - default: - $$.b = - gen_ncode(__pcap_atoin((char *)$1), - $$.q); - break; - } - } - | EID { $$.b = gen_ecode($1, $$.q = $0.q); } - | not id { gen_not($2.b); $$ = $2; } - ; -not: '!' { $$ = $0; } - ; -paren: '(' { $$ = $0; } - ; -pid: nid - | qid and id { gen_and($1.b, $3.b); $$ = $3; } - | qid or id { gen_or($1.b, $3.b); $$ = $3; } - ; -qid: pnum { $$.b = gen_ncode((u_long)$1, - $$.q = $0.q); } - | pid - ; -term: rterm - | not term { gen_not($2.b); $$ = $2; } - ; -head: pqual dqual aqual { QSET($$.q, $1, $2, $3); } - | pqual dqual { QSET($$.q, $1, $2, Q_DEFAULT); } - | pqual aqual { QSET($$.q, $1, Q_DEFAULT, $2); } - | pqual PROTO { QSET($$.q, $1, Q_DEFAULT, Q_PROTO); } - | pqual ndaqual { QSET($$.q, $1, Q_DEFAULT, $2); } - ; -rterm: head id { $$ = $2; } - | paren expr ')' { $$.b = $2.b; $$.q = $1.q; } - | pname { $$.b = gen_proto_abbrev($1); $$.q = qerr; } - | arth relop arth { $$.b = gen_relation($2, $1, $3, 0); - $$.q = qerr; } - | arth irelop arth { $$.b = gen_relation($2, $1, $3, 1); - $$.q = qerr; } - | other { $$.b = $1; $$.q = qerr; } - ; -/* protocol level qualifiers */ -pqual: pname - | { $$ = Q_DEFAULT; } - ; -/* 'direction' qualifiers */ -dqual: SRC { $$ = Q_SRC; } - | DST { $$ = Q_DST; } - | SRC OR DST { $$ = Q_OR; } - | DST OR SRC { $$ = Q_OR; } - | SRC AND DST { $$ = Q_AND; } - | DST AND SRC { $$ = Q_AND; } - ; -/* address type qualifiers */ -aqual: HOST { $$ = Q_HOST; } - | NET { $$ = Q_NET; } - | PORT { $$ = Q_PORT; } - ; -/* non-directional address type qualifiers */ -ndaqual: GATEWAY { $$ = Q_GATEWAY; } - ; -pname: LINK { $$ = Q_LINK; } - | IP { $$ = Q_IP; } - | ARP { $$ = Q_ARP; } - | RARP { $$ = Q_RARP; } - | TCP { $$ = Q_TCP; } - | UDP { $$ = Q_UDP; } - | ICMP { $$ = Q_ICMP; } - | IGMP { $$ = Q_IGMP; } - | DECNET { $$ = Q_DECNET; } - | LAT { $$ = Q_LAT; } - | MOPDL { $$ = Q_MOPDL; } - | MOPRC { $$ = Q_MOPRC; } - ; -other: pqual TK_BROADCAST { $$ = gen_broadcast($1); } - | pqual TK_MULTICAST { $$ = gen_multicast($1); } - | LESS NUM { $$ = gen_less($2); } - | GREATER NUM { $$ = gen_greater($2); } - | BYTE NUM byteop NUM { $$ = gen_byteop($3, $2, $4); } - | INBOUND { $$ = gen_inbound(0); } - | OUTBOUND { $$ = gen_inbound(1); } - ; -relop: '>' { $$ = BPF_JGT; } - | GEQ { $$ = BPF_JGE; } - | '=' { $$ = BPF_JEQ; } - ; -irelop: LEQ { $$ = BPF_JGT; } - | '<' { $$ = BPF_JGE; } - | NEQ { $$ = BPF_JEQ; } - ; -arth: pnum { $$ = gen_loadi($1); } - | narth - ; -narth: pname '[' arth ']' { $$ = gen_load($1, $3, 1); } - | pname '[' arth ':' NUM ']' { $$ = gen_load($1, $3, $5); } - | arth '+' arth { $$ = gen_arth(BPF_ADD, $1, $3); } - | arth '-' arth { $$ = gen_arth(BPF_SUB, $1, $3); } - | arth '*' arth { $$ = gen_arth(BPF_MUL, $1, $3); } - | arth '/' arth { $$ = gen_arth(BPF_DIV, $1, $3); } - | arth '&' arth { $$ = gen_arth(BPF_AND, $1, $3); } - | arth '|' arth { $$ = gen_arth(BPF_OR, $1, $3); } - | arth LSH arth { $$ = gen_arth(BPF_LSH, $1, $3); } - | arth RSH arth { $$ = gen_arth(BPF_RSH, $1, $3); } - | '-' arth %prec UMINUS { $$ = gen_neg($2); } - | paren narth ')' { $$ = $2; } - | LEN { $$ = gen_loadlen(); } - ; -byteop: '&' { $$ = '&'; } - | '|' { $$ = '|'; } - | '<' { $$ = '<'; } - | '>' { $$ = '>'; } - | '=' { $$ = '='; } - ; -pnum: NUM - | paren pnum ')' { $$ = $2; } - ; -%% diff --git a/pcap/inet.c b/pcap/inet.c deleted file mode 100644 index 50afec5..0000000 --- a/pcap/inet.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: inet.c,v 1.6 1997/01/24 19:17:25 deraadt 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char rcsid[] = - "@(#) Header: inet.c,v 1.16 96/06/23 14:28:22 leres Exp (LBL)"; -#endif - -#include -#include -#include -#include -#ifdef HAVE_SYS_SOCKIO_H -#include -#endif - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -/* Not all systems have IFF_LOOPBACK */ -#ifdef IFF_LOOPBACK -#define ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK) -#else -#define ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0) -#endif - -/* - * Return the name of a network interface attached to the system, or NULL - * if none can be found. The interface must be configured up; the - * lowest unit number is preferred; loopback is ignored. - */ -char * -pcap_lookupdev(errbuf) - register char *errbuf; -{ - register int fd, minunit, n; - register char *cp, *ibuf = NULL; - register struct ifreq *ifrp, *ifend, *ifnext, *mp; - struct ifconf ifc; - struct ifreq ifr; - static char device[sizeof(ifrp->ifr_name) + 1]; - int len = 8192; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - (void)sprintf(errbuf, "socket: %s", pcap_strerror(errno)); - return (NULL); - } - while (1) { - ifc.ifc_len = len; - ifc.ifc_buf = ibuf = realloc(ibuf, len); - if (ibuf == NULL) { - close(fd); - return (NULL); - } - if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0) { - (void)close(fd); - free(ibuf); - return (NULL); - } - if (ifc.ifc_len + sizeof(ifr) < len) - break; - len *= 2; - } - - ifrp = (struct ifreq *)ibuf; - ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len); - - mp = NULL; - minunit = 666; - for (; ifrp < ifend; ifrp = ifnext) { -#if BSD - 0 >= 199006 - n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name); - if (n < sizeof(*ifrp)) - ifnext = ifrp + 1; - else - ifnext = (struct ifreq *)((char *)ifrp + n); - if (ifrp->ifr_addr.sa_family != AF_INET) - continue; -#else - ifnext = ifrp + 1; -#endif - /* - * Need a template to preserve address info that is - * used below to locate the next entry. (Otherwise, - * SIOCGIFFLAGS stomps over it because the requests - * are returned in a union.) - */ - strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); - if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { - (void)sprintf(errbuf, "SIOCGIFFLAGS: %s", - pcap_strerror(errno)); - (void)close(fd); - free(ibuf); - return (NULL); - } - - /* Must be up and not the loopback */ - if ((ifr.ifr_flags & IFF_UP) == 0 || ISLOOPBACK(&ifr)) - continue; - - for (cp = ifrp->ifr_name; !isdigit(*cp); ++cp) - continue; - n = atoi(cp); - if (n < minunit) { - minunit = n; - mp = ifrp; - } - } - free(ibuf); - (void)close(fd); - if (mp == NULL) { - (void)strcpy(errbuf, "no suitable device found"); - return (NULL); - } - - (void)strncpy(device, mp->ifr_name, sizeof(device) - 1); - device[sizeof(device) - 1] = '\0'; - return (device); -} - -int -pcap_lookupnet(device, netp, maskp, errbuf) - register char *device; - register bpf_u_int32 *netp, *maskp; - register char *errbuf; -{ - register int fd; - register struct sockaddr_in *sin; - struct ifreq ifr; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - (void)sprintf(errbuf, "socket: %s", pcap_strerror(errno)); - return (-1); - } - memset(&ifr, 0, sizeof(ifr)); -#ifdef linux - /* XXX Work around Linux kernel bug */ - ifr.ifr_addr.sa_family = AF_INET; -#endif - (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); - if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) { - (void)sprintf(errbuf, "SIOCGIFADDR: %s: %s", - device, pcap_strerror(errno)); - (void)close(fd); - return (-1); - } - sin = (struct sockaddr_in *)&ifr.ifr_addr; - *netp = sin->sin_addr.s_addr; - if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) { - (void)sprintf(errbuf, "SIOCGIFNETMASK: %s: %s", - device, pcap_strerror(errno)); - (void)close(fd); - return (-1); - } - (void)close(fd); - *maskp = sin->sin_addr.s_addr; - if (*maskp == 0) { - if (IN_CLASSA(*netp)) - *maskp = IN_CLASSA_NET; - else if (IN_CLASSB(*netp)) - *maskp = IN_CLASSB_NET; - else if (IN_CLASSC(*netp)) - *maskp = IN_CLASSC_NET; - else { - (void)sprintf(errbuf, "inet class for 0x%x unknown", - *netp); - return (-1); - } - } - *netp &= *maskp; - return (0); -} diff --git a/pcap/nametoaddr.c b/pcap/nametoaddr.c deleted file mode 100644 index 3ce8008..0000000 --- a/pcap/nametoaddr.c +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: nametoaddr.c,v 1.5 1996/09/16 02:33:06 tholo Exp $ */ - -/* - * Copyright (c) 1990, 1991, 1992, 1993, 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. - * - * Name to id translation routines used by the scanner. - * These functions are not time critical. - */ - -#ifndef lint -static char rcsid[] = - "@(#) Header: nametoaddr.c,v 1.38 96/06/17 02:42:50 leres Exp (LBL)"; -#endif - -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" -#include "gencode.h" - -#ifndef NTOHL -#define NTOHL(x) (x) = ntohl(x) -#define NTOHS(x) (x) = ntohs(x) -#endif - -static __inline int xdtoi(int); - -/* - * Convert host name to internet address. - * Return 0 upon failure. - */ -bpf_u_int32 ** -pcap_nametoaddr(const char *name) -{ -#ifndef h_addr - static bpf_u_int32 *hlist[2]; -#endif - bpf_u_int32 **p; - struct hostent *hp; - - if ((hp = gethostbyname(name)) != NULL) { -#ifndef h_addr - hlist[0] = (bpf_u_int32 *)hp->h_addr; - NTOHL(hp->h_addr); - return hlist; -#else - for (p = (bpf_u_int32 **)hp->h_addr_list; *p; ++p) - NTOHL(**p); - return (bpf_u_int32 **)hp->h_addr_list; -#endif - } - else - return 0; -} - -/* - * Convert net name to internet address. - * Return 0 upon failure. - */ -bpf_u_int32 -pcap_nametonetaddr(const char *name) -{ - struct netent *np; - - if ((np = getnetbyname(name)) != NULL) - return np->n_net; - else - return 0; -} - -/* - * Convert a port name to its port and protocol numbers. - * We assume only TCP or UDP. - * Return 0 upon failure. - */ -int -pcap_nametoport(const char *name, int *port, int *proto) -{ - struct servent *sp; - char *other; - - sp = getservbyname(name, (char *)0); - if (sp != NULL) { - NTOHS(sp->s_port); - *port = sp->s_port; - *proto = pcap_nametoproto(sp->s_proto); - /* - * We need to check /etc/services for ambiguous entries. - * If we find the ambiguous entry, and it has the - * same port number, change the proto to PROTO_UNDEF - * so both TCP and UDP will be checked. - */ - if (*proto == IPPROTO_TCP) - other = "udp"; - else - other = "tcp"; - - sp = getservbyname(name, other); - if (sp != 0) { - NTOHS(sp->s_port); -#ifdef notdef - if (*port != sp->s_port) - /* Can't handle ambiguous names that refer - to different port numbers. */ - warning("ambiguous port %s in /etc/services", - name); -#endif - *proto = PROTO_UNDEF; - } - return 1; - } -#if defined(ultrix) || defined(__osf__) - /* Special hack in case NFS isn't in /etc/services */ - if (strcmp(name, "nfs") == 0) { - *port = 2049; - *proto = PROTO_UNDEF; - return 1; - } -#endif - return 0; -} - -int -pcap_nametoproto(const char *str) -{ - struct protoent *p; - - p = getprotobyname(str); - if (p != 0) - return p->p_proto; - else - return PROTO_UNDEF; -} - -#include "ethertype.h" - -struct eproto { - char *s; - u_short p; -}; - -/* Static data base of ether protocol types. */ -struct eproto eproto_db[] = { - { "pup", ETHERTYPE_PUP }, - { "xns", ETHERTYPE_NS }, - { "ip", ETHERTYPE_IP }, - { "arp", ETHERTYPE_ARP }, - { "rarp", ETHERTYPE_REVARP }, - { "sprite", ETHERTYPE_SPRITE }, - { "mopdl", ETHERTYPE_MOPDL }, - { "moprc", ETHERTYPE_MOPRC }, - { "decnet", ETHERTYPE_DN }, - { "lat", ETHERTYPE_LAT }, - { "lanbridge", ETHERTYPE_LANBRIDGE }, - { "vexp", ETHERTYPE_VEXP }, - { "vprod", ETHERTYPE_VPROD }, - { "atalk", ETHERTYPE_ATALK }, - { "atalkarp", ETHERTYPE_AARP }, - { "loopback", ETHERTYPE_LOOPBACK }, - { "decdts", ETHERTYPE_DECDTS }, - { "decdns", ETHERTYPE_DECDNS }, - { (char *)0, 0 } -}; - -int -pcap_nametoeproto(const char *s) -{ - struct eproto *p = eproto_db; - - while (p->s != 0) { - if (strcmp(p->s, s) == 0) - return p->p; - p += 1; - } - return PROTO_UNDEF; -} - -/* Hex digit to integer. */ -static __inline int -xdtoi(c) - register int c; -{ - if (isdigit(c)) - return c - '0'; - else if (islower(c)) - return c - 'a' + 10; - else - return c - 'A' + 10; -} - -bpf_u_int32 -__pcap_atoin(const char *s) -{ - bpf_u_int32 addr = 0; - u_int n; - - while (1) { - n = 0; - while (*s && *s != '.') - n = n * 10 + *s++ - '0'; - addr <<= 8; - addr |= n & 0xff; - if (*s == '\0') - return addr; - ++s; - } - /* NOTREACHED */ -} - -bpf_u_int32 -__pcap_atodn(const char *s) -{ -#define AREASHIFT 10 -#define AREAMASK 0176000 -#define NODEMASK 01777 - - bpf_u_int32 addr = 0; - u_int node, area; - - if (sscanf((char *)s, "%d.%d", &area, &node) != 2) - bpf_error("malformed decnet address '%s'", s); - - addr = (area << AREASHIFT) & AREAMASK; - addr |= (node & NODEMASK); - - return(addr); -} - -/* - * Convert 's' which has the form "xx:xx:xx:xx:xx:xx" into a new - * ethernet address. Assumes 's' is well formed. - */ -u_char * -pcap_ether_aton(const char *s) -{ - register u_char *ep, *e; - register u_int d; - - e = ep = (u_char *)malloc(6); - - while (*s) { - if (*s == ':') - s += 1; - d = xdtoi(*s++); - if (isxdigit(*s)) { - d <<= 4; - d |= xdtoi(*s++); - } - *ep++ = d; - } - - return (e); -} - -#ifndef HAVE_ETHER_HOSTTON -/* Roll our own */ -u_char * -pcap_ether_hostton(const char *name) -{ - register struct pcap_etherent *ep; - register u_char *ap; - static FILE *fp = NULL; - static init = 0; - - if (!init) { - fp = fopen(PCAP_ETHERS_FILE, "r"); - ++init; - if (fp == NULL) - return (NULL); - } else if (fp == NULL) - return (NULL); - else - rewind(fp); - - while ((ep = pcap_next_etherent(fp)) != NULL) { - if (strcmp(ep->name, name) == 0) { - ap = (u_char *)malloc(6); - if (ap != NULL) { - memcpy(ap, ep->addr, 6); - return (ap); - } - break; - } - } - return (NULL); -} -#else - -#ifndef sgi -extern int ether_hostton(char *, struct ether_addr *); -#endif - -/* Use the os supplied routines */ -u_char * -pcap_ether_hostton(const char *name) -{ - register u_char *ap; - u_char a[6]; - - ap = NULL; - if (ether_hostton((char *)name, (struct ether_addr *)a) == 0) { - ap = (u_char *)malloc(6); - if (ap != NULL) - memcpy(ap, a, 6); - } - return (ap); -} -#endif - -u_short -__pcap_nametodnaddr(const char *name) -{ -#ifdef DECNETLIB - struct nodeent *getnodebyname(); - struct nodeent *nep; - unsigned short res; - - nep = getnodebyname(name); - if (nep == ((struct nodeent *)0)) - bpf_error("unknown decnet host name '%s'\n", name); - - memcpy((char *)&res, (char *)nep->n_addr, sizeof(unsigned short)); - return(res); -#else - bpf_error("decnet name support not included, '%s' cannot be translated\n", - name); -#ifdef lint - return 0; -#endif -#endif -} diff --git a/pcap/optimize.c b/pcap/optimize.c deleted file mode 100644 index e78ce1c..0000000 --- a/pcap/optimize.c +++ /dev/null @@ -1,2029 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: optimize.c,v 1.5 1996/09/16 02:33:07 tholo Exp $ */ - -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1993, 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. - * - * Optimization module for tcpdump intermediate representation. - */ -#ifndef lint -static char rcsid[] = - "@(#) Header: optimize.c,v 1.58 96/06/16 22:36:59 leres Exp (LBL)"; -#endif - -#include -#include - -#include - -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" -#include "gencode.h" - -#ifdef BDEBUG -extern int dflag; -#endif - -#define A_ATOM BPF_MEMWORDS -#define X_ATOM (BPF_MEMWORDS+1) - -#define NOP -1 - -/* - * This define is used to represent *both* the accumulator and - * x register in use-def computations. - * Currently, the use-def code assumes only one definition per instruction. - */ -#define AX_ATOM N_ATOMS - -/* - * A flag to indicate that further optimization is needed. - * Iterative passes are continued until a given pass yields no - * branch movement. - */ -static int done; - -/* - * A block is marked if only if its mark equals the current mark. - * Rather than traverse the code array, marking each item, 'cur_mark' is - * incremented. This automatically makes each element unmarked. - */ -static int cur_mark; -#define isMarked(p) ((p)->mark == cur_mark) -#define unMarkAll() cur_mark += 1 -#define Mark(p) ((p)->mark = cur_mark) - -static void opt_init(struct block *); -static void opt_cleanup(void); - -static void make_marks(struct block *); -static void mark_code(struct block *); - -static void intern_blocks(struct block *); - -static int eq_slist(struct slist *, struct slist *); - -static void find_levels_r(struct block *); - -static void find_levels(struct block *); -static void find_dom(struct block *); -static void propedom(struct edge *); -static void find_edom(struct block *); -static void find_closure(struct block *); -static int atomuse(struct stmt *); -static int atomdef(struct stmt *); -static void compute_local_ud(struct block *); -static void find_ud(struct block *); -static void init_val(void); -static int F(int, int, int); -static __inline void vstore(struct stmt *, int *, int, int); -static void opt_blk(struct block *, int); -static int use_conflict(struct block *, struct block *); -static void opt_j(struct edge *); -static void or_pullup(struct block *); -static void and_pullup(struct block *); -static void opt_blks(struct block *, int); -static __inline void link_inedge(struct edge *, struct block *); -static void find_inedges(struct block *); -static void opt_root(struct block **); -static void opt_loop(struct block *, int); -static void fold_op(struct stmt *, int, int); -static __inline struct slist *this_op(struct slist *); -static void opt_not(struct block *); -static void opt_peep(struct block *); -static void opt_stmt(struct stmt *, int[], int); -static void deadstmt(struct stmt *, struct stmt *[]); -static void opt_deadstores(struct block *); -static void opt_blk(struct block *, int); -static int use_conflict(struct block *, struct block *); -static void opt_j(struct edge *); -static struct block *fold_edge(struct block *, struct edge *); -static __inline int eq_blk(struct block *, struct block *); -static int slength(struct slist *); -static int count_blocks(struct block *); -static void number_blks_r(struct block *); -static int count_stmts(struct block *); -static int convert_code_r(struct block *); -#ifdef BDEBUG -static void opt_dump(struct block *); -#endif - -static int n_blocks; -struct block **blocks; -static int n_edges; -struct edge **edges; - -/* - * A bit vector set representation of the dominators. - * We round up the set size to the next power of two. - */ -static int nodewords; -static int edgewords; -struct block **levels; -bpf_u_int32 *space; -#define BITS_PER_WORD (8*sizeof(bpf_u_int32)) -/* - * True if a is in uset {p} - */ -#define SET_MEMBER(p, a) \ -((p)[(unsigned)(a) / BITS_PER_WORD] & (1 << ((unsigned)(a) % BITS_PER_WORD))) - -/* - * Add 'a' to uset p. - */ -#define SET_INSERT(p, a) \ -(p)[(unsigned)(a) / BITS_PER_WORD] |= (1 << ((unsigned)(a) % BITS_PER_WORD)) - -/* - * Delete 'a' from uset p. - */ -#define SET_DELETE(p, a) \ -(p)[(unsigned)(a) / BITS_PER_WORD] &= ~(1 << ((unsigned)(a) % BITS_PER_WORD)) - -/* - * a := a intersect b - */ -#define SET_INTERSECT(a, b, n)\ -{\ - register bpf_u_int32 *_x = a, *_y = b;\ - register int _n = n;\ - while (--_n >= 0) *_x++ &= *_y++;\ -} - -/* - * a := a - b - */ -#define SET_SUBTRACT(a, b, n)\ -{\ - register bpf_u_int32 *_x = a, *_y = b;\ - register int _n = n;\ - while (--_n >= 0) *_x++ &=~ *_y++;\ -} - -/* - * a := a union b - */ -#define SET_UNION(a, b, n)\ -{\ - register bpf_u_int32 *_x = a, *_y = b;\ - register int _n = n;\ - while (--_n >= 0) *_x++ |= *_y++;\ -} - -static uset all_dom_sets; -static uset all_closure_sets; -static uset all_edge_sets; - -#ifndef MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -static void -find_levels_r(b) - struct block *b; -{ - int level; - - if (isMarked(b)) - return; - - Mark(b); - b->link = 0; - - if (JT(b)) { - find_levels_r(JT(b)); - find_levels_r(JF(b)); - level = MAX(JT(b)->level, JF(b)->level) + 1; - } else - level = 0; - b->level = level; - b->link = levels[level]; - levels[level] = b; -} - -/* - * Level graph. The levels go from 0 at the leaves to - * N_LEVELS at the root. The levels[] array points to the - * first node of the level list, whose elements are linked - * with the 'link' field of the struct block. - */ -static void -find_levels(root) - struct block *root; -{ - memset((char *)levels, 0, n_blocks * sizeof(*levels)); - unMarkAll(); - find_levels_r(root); -} - -/* - * Find dominator relationships. - * Assumes graph has been leveled. - */ -static void -find_dom(root) - struct block *root; -{ - int i; - struct block *b; - bpf_u_int32 *x; - - /* - * Initialize sets to contain all nodes. - */ - x = all_dom_sets; - i = n_blocks * nodewords; - while (--i >= 0) - *x++ = ~0; - /* Root starts off empty. */ - for (i = nodewords; --i >= 0;) - root->dom[i] = 0; - - /* root->level is the highest level no found. */ - for (i = root->level; i >= 0; --i) { - for (b = levels[i]; b; b = b->link) { - SET_INSERT(b->dom, b->id); - if (JT(b) == 0) - continue; - SET_INTERSECT(JT(b)->dom, b->dom, nodewords); - SET_INTERSECT(JF(b)->dom, b->dom, nodewords); - } - } -} - -static void -propedom(ep) - struct edge *ep; -{ - SET_INSERT(ep->edom, ep->id); - if (ep->succ) { - SET_INTERSECT(ep->succ->et.edom, ep->edom, edgewords); - SET_INTERSECT(ep->succ->ef.edom, ep->edom, edgewords); - } -} - -/* - * Compute edge dominators. - * Assumes graph has been leveled and predecessors established. - */ -static void -find_edom(root) - struct block *root; -{ - int i; - uset x; - struct block *b; - - x = all_edge_sets; - for (i = n_edges * edgewords; --i >= 0; ) - x[i] = ~0; - - /* root->level is the highest level no found. */ - memset(root->et.edom, 0, edgewords * sizeof(*(uset)0)); - memset(root->ef.edom, 0, edgewords * sizeof(*(uset)0)); - for (i = root->level; i >= 0; --i) { - for (b = levels[i]; b != 0; b = b->link) { - propedom(&b->et); - propedom(&b->ef); - } - } -} - -/* - * Find the backwards transitive closure of the flow graph. These sets - * are backwards in the sense that we find the set of nodes that reach - * a given node, not the set of nodes that can be reached by a node. - * - * Assumes graph has been leveled. - */ -static void -find_closure(root) - struct block *root; -{ - int i; - struct block *b; - - /* - * Initialize sets to contain no nodes. - */ - memset((char *)all_closure_sets, 0, - n_blocks * nodewords * sizeof(*all_closure_sets)); - - /* root->level is the highest level no found. */ - for (i = root->level; i >= 0; --i) { - for (b = levels[i]; b; b = b->link) { - SET_INSERT(b->closure, b->id); - if (JT(b) == 0) - continue; - SET_UNION(JT(b)->closure, b->closure, nodewords); - SET_UNION(JF(b)->closure, b->closure, nodewords); - } - } -} - -/* - * Return the register number that is used by s. If A and X are both - * used, return AX_ATOM. If no register is used, return -1. - * - * The implementation should probably change to an array access. - */ -static int -atomuse(s) - struct stmt *s; -{ - register int c = s->code; - - if (c == NOP) - return -1; - - switch (BPF_CLASS(c)) { - - case BPF_RET: - return (BPF_RVAL(c) == BPF_A) ? A_ATOM : - (BPF_RVAL(c) == BPF_X) ? X_ATOM : -1; - - case BPF_LD: - case BPF_LDX: - return (BPF_MODE(c) == BPF_IND) ? X_ATOM : - (BPF_MODE(c) == BPF_MEM) ? s->k : -1; - - case BPF_ST: - return A_ATOM; - - case BPF_STX: - return X_ATOM; - - case BPF_JMP: - case BPF_ALU: - if (BPF_SRC(c) == BPF_X) - return AX_ATOM; - return A_ATOM; - - case BPF_MISC: - return BPF_MISCOP(c) == BPF_TXA ? X_ATOM : A_ATOM; - } - abort(); - /* NOTREACHED */ -} - -/* - * Return the register number that is defined by 's'. We assume that - * a single stmt cannot define more than one register. If no register - * is defined, return -1. - * - * The implementation should probably change to an array access. - */ -static int -atomdef(s) - struct stmt *s; -{ - if (s->code == NOP) - return -1; - - switch (BPF_CLASS(s->code)) { - - case BPF_LD: - case BPF_ALU: - return A_ATOM; - - case BPF_LDX: - return X_ATOM; - - case BPF_ST: - case BPF_STX: - return s->k; - - case BPF_MISC: - return BPF_MISCOP(s->code) == BPF_TAX ? X_ATOM : A_ATOM; - } - return -1; -} - -static void -compute_local_ud(b) - struct block *b; -{ - struct slist *s; - atomset def = 0, use = 0, kill = 0; - int atom; - - for (s = b->stmts; s; s = s->next) { - if (s->s.code == NOP) - continue; - atom = atomuse(&s->s); - if (atom >= 0) { - if (atom == AX_ATOM) { - if (!ATOMELEM(def, X_ATOM)) - use |= ATOMMASK(X_ATOM); - if (!ATOMELEM(def, A_ATOM)) - use |= ATOMMASK(A_ATOM); - } - else if (atom < N_ATOMS) { - if (!ATOMELEM(def, atom)) - use |= ATOMMASK(atom); - } - else - abort(); - } - atom = atomdef(&s->s); - if (atom >= 0) { - if (!ATOMELEM(use, atom)) - kill |= ATOMMASK(atom); - def |= ATOMMASK(atom); - } - } - if (!ATOMELEM(def, A_ATOM) && BPF_CLASS(b->s.code) == BPF_JMP) - use |= ATOMMASK(A_ATOM); - - b->def = def; - b->kill = kill; - b->in_use = use; -} - -/* - * Assume graph is already leveled. - */ -static void -find_ud(root) - struct block *root; -{ - int i, maxlevel; - struct block *p; - - /* - * root->level is the highest level no found; - * count down from there. - */ - maxlevel = root->level; - for (i = maxlevel; i >= 0; --i) - for (p = levels[i]; p; p = p->link) { - compute_local_ud(p); - p->out_use = 0; - } - - for (i = 1; i <= maxlevel; ++i) { - for (p = levels[i]; p; p = p->link) { - p->out_use |= JT(p)->in_use | JF(p)->in_use; - p->in_use |= p->out_use &~ p->kill; - } - } -} - -/* - * These data structures are used in a Cocke and Shwarz style - * value numbering scheme. Since the flowgraph is acyclic, - * exit values can be propagated from a node's predecessors - * provided it is uniquely defined. - */ -struct valnode { - int code; - int v0, v1; - int val; - struct valnode *next; -}; - -#define MODULUS 213 -static struct valnode *hashtbl[MODULUS]; -static int curval; -static int maxval; - -/* Integer constants mapped with the load immediate opcode. */ -#define K(i) F(BPF_LD|BPF_IMM|BPF_W, i, 0L) - -struct vmapinfo { - int is_const; - bpf_int32 const_val; -}; - -struct vmapinfo *vmap; -struct valnode *vnode_base; -struct valnode *next_vnode; - -static void -init_val() -{ - curval = 0; - next_vnode = vnode_base; - memset((char *)vmap, 0, maxval * sizeof(*vmap)); - memset((char *)hashtbl, 0, sizeof hashtbl); -} - -/* Because we really don't have an IR, this stuff is a little messy. */ -static int -F(code, v0, v1) - int code; - int v0, v1; -{ - u_int hash; - int val; - struct valnode *p; - - hash = (u_int)code ^ (v0 << 4) ^ (v1 << 8); - hash %= MODULUS; - - for (p = hashtbl[hash]; p; p = p->next) - if (p->code == code && p->v0 == v0 && p->v1 == v1) - return p->val; - - val = ++curval; - if (BPF_MODE(code) == BPF_IMM && - (BPF_CLASS(code) == BPF_LD || BPF_CLASS(code) == BPF_LDX)) { - vmap[val].const_val = v0; - vmap[val].is_const = 1; - } - p = next_vnode++; - p->val = val; - p->code = code; - p->v0 = v0; - p->v1 = v1; - p->next = hashtbl[hash]; - hashtbl[hash] = p; - - return val; -} - -static __inline void -vstore(s, valp, newval, alter) - struct stmt *s; - int *valp; - int newval; - int alter; -{ - if (alter && *valp == newval) - s->code = NOP; - else - *valp = newval; -} - -static void -fold_op(s, v0, v1) - struct stmt *s; - int v0, v1; -{ - bpf_int32 a, b; - - a = vmap[v0].const_val; - b = vmap[v1].const_val; - - switch (BPF_OP(s->code)) { - case BPF_ADD: - a += b; - break; - - case BPF_SUB: - a -= b; - break; - - case BPF_MUL: - a *= b; - break; - - case BPF_DIV: - if (b == 0) - bpf_error("division by zero"); - a /= b; - break; - - case BPF_AND: - a &= b; - break; - - case BPF_OR: - a |= b; - break; - - case BPF_LSH: - a <<= b; - break; - - case BPF_RSH: - a >>= b; - break; - - case BPF_NEG: - a = -a; - break; - - default: - abort(); - } - s->k = a; - s->code = BPF_LD|BPF_IMM; - done = 0; -} - -static __inline struct slist * -this_op(s) - struct slist *s; -{ - while (s != 0 && s->s.code == NOP) - s = s->next; - return s; -} - -static void -opt_not(b) - struct block *b; -{ - struct block *tmp = JT(b); - - JT(b) = JF(b); - JF(b) = tmp; -} - -static void -opt_peep(b) - struct block *b; -{ - struct slist *s; - struct slist *next, *last; - int val; - - s = b->stmts; - if (s == 0) - return; - - last = s; - while (1) { - s = this_op(s); - if (s == 0) - break; - next = this_op(s->next); - if (next == 0) - break; - last = next; - - /* - * st M[k] --> st M[k] - * ldx M[k] tax - */ - if (s->s.code == BPF_ST && - next->s.code == (BPF_LDX|BPF_MEM) && - s->s.k == next->s.k) { - done = 0; - next->s.code = BPF_MISC|BPF_TAX; - } - /* - * ld #k --> ldx #k - * tax txa - */ - if (s->s.code == (BPF_LD|BPF_IMM) && - next->s.code == (BPF_MISC|BPF_TAX)) { - s->s.code = BPF_LDX|BPF_IMM; - next->s.code = BPF_MISC|BPF_TXA; - done = 0; - } - /* - * This is an ugly special case, but it happens - * when you say tcp[k] or udp[k] where k is a constant. - */ - if (s->s.code == (BPF_LD|BPF_IMM)) { - struct slist *add, *tax, *ild; - - /* - * Check that X isn't used on exit from this - * block (which the optimizer might cause). - * We know the code generator won't generate - * any local dependencies. - */ - if (ATOMELEM(b->out_use, X_ATOM)) - break; - - if (next->s.code != (BPF_LDX|BPF_MSH|BPF_B)) - add = next; - else - add = this_op(next->next); - if (add == 0 || add->s.code != (BPF_ALU|BPF_ADD|BPF_X)) - break; - - tax = this_op(add->next); - if (tax == 0 || tax->s.code != (BPF_MISC|BPF_TAX)) - break; - - ild = this_op(tax->next); - if (ild == 0 || BPF_CLASS(ild->s.code) != BPF_LD || - BPF_MODE(ild->s.code) != BPF_IND) - break; - /* - * XXX We need to check that X is not - * subsequently used. We know we can eliminate the - * accumulator modifications since it is defined - * by the last stmt of this sequence. - * - * We want to turn this sequence: - * - * (004) ldi #0x2 {s} - * (005) ldxms [14] {next} -- optional - * (006) addx {add} - * (007) tax {tax} - * (008) ild [x+0] {ild} - * - * into this sequence: - * - * (004) nop - * (005) ldxms [14] - * (006) nop - * (007) nop - * (008) ild [x+2] - * - */ - ild->s.k += s->s.k; - s->s.code = NOP; - add->s.code = NOP; - tax->s.code = NOP; - done = 0; - } - s = next; - } - /* - * If we have a subtract to do a comparison, and the X register - * is a known constant, we can merge this value into the - * comparison. - */ - if (last->s.code == (BPF_ALU|BPF_SUB|BPF_X) && - !ATOMELEM(b->out_use, A_ATOM)) { - val = b->val[X_ATOM]; - if (vmap[val].is_const) { - int op; - - b->s.k += vmap[val].const_val; - op = BPF_OP(b->s.code); - if (op == BPF_JGT || op == BPF_JGE) { - struct block *t = JT(b); - JT(b) = JF(b); - JF(b) = t; - b->s.k += 0x80000000; - } - last->s.code = NOP; - done = 0; - } else if (b->s.k == 0) { - /* - * sub x -> nop - * j #0 j x - */ - last->s.code = NOP; - b->s.code = BPF_CLASS(b->s.code) | BPF_OP(b->s.code) | - BPF_X; - done = 0; - } - } - /* - * Likewise, a constant subtract can be simplified. - */ - else if (last->s.code == (BPF_ALU|BPF_SUB|BPF_K) && - !ATOMELEM(b->out_use, A_ATOM)) { - int op; - - b->s.k += last->s.k; - last->s.code = NOP; - op = BPF_OP(b->s.code); - if (op == BPF_JGT || op == BPF_JGE) { - struct block *t = JT(b); - JT(b) = JF(b); - JF(b) = t; - b->s.k += 0x80000000; - } - done = 0; - } - /* - * and #k nop - * jeq #0 -> jset #k - */ - if (last->s.code == (BPF_ALU|BPF_AND|BPF_K) && - !ATOMELEM(b->out_use, A_ATOM) && b->s.k == 0) { - b->s.k = last->s.k; - b->s.code = BPF_JMP|BPF_K|BPF_JSET; - last->s.code = NOP; - done = 0; - opt_not(b); - } - /* - * If the accumulator is a known constant, we can compute the - * comparison result. - */ - val = b->val[A_ATOM]; - if (vmap[val].is_const && BPF_SRC(b->s.code) == BPF_K) { - bpf_int32 v = vmap[val].const_val; - switch (BPF_OP(b->s.code)) { - - case BPF_JEQ: - v = v == b->s.k; - break; - - case BPF_JGT: - v = (unsigned)v > b->s.k; - break; - - case BPF_JGE: - v = (unsigned)v >= b->s.k; - break; - - case BPF_JSET: - v &= b->s.k; - break; - - default: - abort(); - } - if (JF(b) != JT(b)) - done = 0; - if (v) - JF(b) = JT(b); - else - JT(b) = JF(b); - } -} - -/* - * Compute the symbolic value of expression of 's', and update - * anything it defines in the value table 'val'. If 'alter' is true, - * do various optimizations. This code would be cleaner if symbolic - * evaluation and code transformations weren't folded together. - */ -static void -opt_stmt(s, val, alter) - struct stmt *s; - int val[]; - int alter; -{ - int op; - int v; - - switch (s->code) { - - case BPF_LD|BPF_ABS|BPF_W: - case BPF_LD|BPF_ABS|BPF_H: - case BPF_LD|BPF_ABS|BPF_B: - v = F(s->code, s->k, 0L); - vstore(s, &val[A_ATOM], v, alter); - break; - - case BPF_LD|BPF_IND|BPF_W: - case BPF_LD|BPF_IND|BPF_H: - case BPF_LD|BPF_IND|BPF_B: - v = val[X_ATOM]; - if (alter && vmap[v].is_const) { - s->code = BPF_LD|BPF_ABS|BPF_SIZE(s->code); - s->k += vmap[v].const_val; - v = F(s->code, s->k, 0L); - done = 0; - } - else - v = F(s->code, s->k, v); - vstore(s, &val[A_ATOM], v, alter); - break; - - case BPF_LD|BPF_LEN: - v = F(s->code, 0L, 0L); - vstore(s, &val[A_ATOM], v, alter); - break; - - case BPF_LD|BPF_IMM: - v = K(s->k); - vstore(s, &val[A_ATOM], v, alter); - break; - - case BPF_LDX|BPF_IMM: - v = K(s->k); - vstore(s, &val[X_ATOM], v, alter); - break; - - case BPF_LDX|BPF_MSH|BPF_B: - v = F(s->code, s->k, 0L); - vstore(s, &val[X_ATOM], v, alter); - break; - - case BPF_ALU|BPF_NEG: - if (alter && vmap[val[A_ATOM]].is_const) { - s->code = BPF_LD|BPF_IMM; - s->k = -vmap[val[A_ATOM]].const_val; - val[A_ATOM] = K(s->k); - } - else - val[A_ATOM] = F(s->code, val[A_ATOM], 0L); - break; - - case BPF_ALU|BPF_ADD|BPF_K: - case BPF_ALU|BPF_SUB|BPF_K: - case BPF_ALU|BPF_MUL|BPF_K: - case BPF_ALU|BPF_DIV|BPF_K: - case BPF_ALU|BPF_AND|BPF_K: - case BPF_ALU|BPF_OR|BPF_K: - case BPF_ALU|BPF_LSH|BPF_K: - case BPF_ALU|BPF_RSH|BPF_K: - op = BPF_OP(s->code); - if (alter) { - if (s->k == 0) { - if (op == BPF_ADD || op == BPF_SUB || - op == BPF_LSH || op == BPF_RSH || - op == BPF_OR) { - s->code = NOP; - break; - } - if (op == BPF_MUL || op == BPF_AND) { - s->code = BPF_LD|BPF_IMM; - val[A_ATOM] = K(s->k); - break; - } - } - if (vmap[val[A_ATOM]].is_const) { - fold_op(s, val[A_ATOM], K(s->k)); - val[A_ATOM] = K(s->k); - break; - } - } - val[A_ATOM] = F(s->code, val[A_ATOM], K(s->k)); - break; - - case BPF_ALU|BPF_ADD|BPF_X: - case BPF_ALU|BPF_SUB|BPF_X: - case BPF_ALU|BPF_MUL|BPF_X: - case BPF_ALU|BPF_DIV|BPF_X: - case BPF_ALU|BPF_AND|BPF_X: - case BPF_ALU|BPF_OR|BPF_X: - case BPF_ALU|BPF_LSH|BPF_X: - case BPF_ALU|BPF_RSH|BPF_X: - op = BPF_OP(s->code); - if (alter && vmap[val[X_ATOM]].is_const) { - if (vmap[val[A_ATOM]].is_const) { - fold_op(s, val[A_ATOM], val[X_ATOM]); - val[A_ATOM] = K(s->k); - } - else { - s->code = BPF_ALU|BPF_K|op; - s->k = vmap[val[X_ATOM]].const_val; - done = 0; - val[A_ATOM] = - F(s->code, val[A_ATOM], K(s->k)); - } - break; - } - /* - * Check if we're doing something to an accumulator - * that is 0, and simplify. This may not seem like - * much of a simplification but it could open up further - * optimizations. - * XXX We could also check for mul by 1, and -1, etc. - */ - if (alter && vmap[val[A_ATOM]].is_const - && vmap[val[A_ATOM]].const_val == 0) { - if (op == BPF_ADD || op == BPF_OR || - op == BPF_LSH || op == BPF_RSH || op == BPF_SUB) { - s->code = BPF_MISC|BPF_TXA; - vstore(s, &val[A_ATOM], val[X_ATOM], alter); - break; - } - else if (op == BPF_MUL || op == BPF_DIV || - op == BPF_AND) { - s->code = BPF_LD|BPF_IMM; - s->k = 0; - vstore(s, &val[A_ATOM], K(s->k), alter); - break; - } - else if (op == BPF_NEG) { - s->code = NOP; - break; - } - } - val[A_ATOM] = F(s->code, val[A_ATOM], val[X_ATOM]); - break; - - case BPF_MISC|BPF_TXA: - vstore(s, &val[A_ATOM], val[X_ATOM], alter); - break; - - case BPF_LD|BPF_MEM: - v = val[s->k]; - if (alter && vmap[v].is_const) { - s->code = BPF_LD|BPF_IMM; - s->k = vmap[v].const_val; - done = 0; - } - vstore(s, &val[A_ATOM], v, alter); - break; - - case BPF_MISC|BPF_TAX: - vstore(s, &val[X_ATOM], val[A_ATOM], alter); - break; - - case BPF_LDX|BPF_MEM: - v = val[s->k]; - if (alter && vmap[v].is_const) { - s->code = BPF_LDX|BPF_IMM; - s->k = vmap[v].const_val; - done = 0; - } - vstore(s, &val[X_ATOM], v, alter); - break; - - case BPF_ST: - vstore(s, &val[s->k], val[A_ATOM], alter); - break; - - case BPF_STX: - vstore(s, &val[s->k], val[X_ATOM], alter); - break; - } -} - -static void -deadstmt(s, last) - register struct stmt *s; - register struct stmt *last[]; -{ - register int atom; - - atom = atomuse(s); - if (atom >= 0) { - if (atom == AX_ATOM) { - last[X_ATOM] = 0; - last[A_ATOM] = 0; - } - else - last[atom] = 0; - } - atom = atomdef(s); - if (atom >= 0) { - if (last[atom]) { - done = 0; - last[atom]->code = NOP; - } - last[atom] = s; - } -} - -static void -opt_deadstores(b) - register struct block *b; -{ - register struct slist *s; - register int atom; - struct stmt *last[N_ATOMS]; - - memset((char *)last, 0, sizeof last); - - for (s = b->stmts; s != 0; s = s->next) - deadstmt(&s->s, last); - deadstmt(&b->s, last); - - for (atom = 0; atom < N_ATOMS; ++atom) - if (last[atom] && !ATOMELEM(b->out_use, atom)) { - last[atom]->code = NOP; - done = 0; - } -} - -static void -opt_blk(b, do_stmts) - struct block *b; - int do_stmts; -{ - struct slist *s; - struct edge *p; - int i; - bpf_int32 aval; - - /* - * Initialize the atom values. - * If we have no predecessors, everything is undefined. - * Otherwise, we inherent our values from our predecessors. - * If any register has an ambiguous value (i.e. control paths are - * merging) give it the undefined value of 0. - */ - p = b->in_edges; - if (p == 0) - memset((char *)b->val, 0, sizeof(b->val)); - else { - memcpy((char *)b->val, (char *)p->pred->val, sizeof(b->val)); - while ((p = p->next) != NULL) { - for (i = 0; i < N_ATOMS; ++i) - if (b->val[i] != p->pred->val[i]) - b->val[i] = 0; - } - } - aval = b->val[A_ATOM]; - for (s = b->stmts; s; s = s->next) - opt_stmt(&s->s, b->val, do_stmts); - - /* - * This is a special case: if we don't use anything from this - * block, and we load the accumulator with value that is - * already there, or if this block is a return, - * eliminate all the statements. - */ - if (do_stmts && - ((b->out_use == 0 && aval != 0 &&b->val[A_ATOM] == aval) || - BPF_CLASS(b->s.code) == BPF_RET)) { - if (b->stmts != 0) { - b->stmts = 0; - done = 0; - } - } else { - opt_peep(b); - opt_deadstores(b); - } - /* - * Set up values for branch optimizer. - */ - if (BPF_SRC(b->s.code) == BPF_K) - b->oval = K(b->s.k); - else - b->oval = b->val[X_ATOM]; - b->et.code = b->s.code; - b->ef.code = -b->s.code; -} - -/* - * Return true if any register that is used on exit from 'succ', has - * an exit value that is different from the corresponding exit value - * from 'b'. - */ -static int -use_conflict(b, succ) - struct block *b, *succ; -{ - int atom; - atomset use = succ->out_use; - - if (use == 0) - return 0; - - for (atom = 0; atom < N_ATOMS; ++atom) - if (ATOMELEM(use, atom)) - if (b->val[atom] != succ->val[atom]) - return 1; - return 0; -} - -static struct block * -fold_edge(child, ep) - struct block *child; - struct edge *ep; -{ - int sense; - int aval0, aval1, oval0, oval1; - int code = ep->code; - - if (code < 0) { - code = -code; - sense = 0; - } else - sense = 1; - - if (child->s.code != code) - return 0; - - aval0 = child->val[A_ATOM]; - oval0 = child->oval; - aval1 = ep->pred->val[A_ATOM]; - oval1 = ep->pred->oval; - - if (aval0 != aval1) - return 0; - - if (oval0 == oval1) - /* - * The operands are identical, so the - * result is true if a true branch was - * taken to get here, otherwise false. - */ - return sense ? JT(child) : JF(child); - - if (sense && code == (BPF_JMP|BPF_JEQ|BPF_K)) - /* - * At this point, we only know the comparison if we - * came down the true branch, and it was an equality - * comparison with a constant. We rely on the fact that - * distinct constants have distinct value numbers. - */ - return JF(child); - - return 0; -} - -static void -opt_j(ep) - struct edge *ep; -{ - register int i, k; - register struct block *target; - - if (JT(ep->succ) == 0) - return; - - if (JT(ep->succ) == JF(ep->succ)) { - /* - * Common branch targets can be eliminated, provided - * there is no data dependency. - */ - if (!use_conflict(ep->pred, ep->succ->et.succ)) { - done = 0; - ep->succ = JT(ep->succ); - } - } - /* - * For each edge dominator that matches the successor of this - * edge, promote the edge successor to the its grandchild. - * - * XXX We violate the set abstraction here in favor a reasonably - * efficient loop. - */ - top: - for (i = 0; i < edgewords; ++i) { - register bpf_u_int32 x = ep->edom[i]; - - while (x != 0) { - k = ffs(x) - 1; - x &=~ (1 << k); - k += i * BITS_PER_WORD; - - target = fold_edge(ep->succ, edges[k]); - /* - * Check that there is no data dependency between - * nodes that will be violated if we move the edge. - */ - if (target != 0 && !use_conflict(ep->pred, target)) { - done = 0; - ep->succ = target; - if (JT(target) != 0) - /* - * Start over unless we hit a leaf. - */ - goto top; - return; - } - } - } -} - - -static void -or_pullup(b) - struct block *b; -{ - int val, at_top; - struct block *pull; - struct block **diffp, **samep; - struct edge *ep; - - ep = b->in_edges; - if (ep == 0) - return; - - /* - * Make sure each predecessor loads the same value. - * XXX why? - */ - val = ep->pred->val[A_ATOM]; - for (ep = ep->next; ep != 0; ep = ep->next) - if (val != ep->pred->val[A_ATOM]) - return; - - if (JT(b->in_edges->pred) == b) - diffp = &JT(b->in_edges->pred); - else - diffp = &JF(b->in_edges->pred); - - at_top = 1; - while (1) { - if (*diffp == 0) - return; - - if (JT(*diffp) != JT(b)) - return; - - if (!SET_MEMBER((*diffp)->dom, b->id)) - return; - - if ((*diffp)->val[A_ATOM] != val) - break; - - diffp = &JF(*diffp); - at_top = 0; - } - samep = &JF(*diffp); - while (1) { - if (*samep == 0) - return; - - if (JT(*samep) != JT(b)) - return; - - if (!SET_MEMBER((*samep)->dom, b->id)) - return; - - if ((*samep)->val[A_ATOM] == val) - break; - - /* XXX Need to check that there are no data dependencies - between dp0 and dp1. Currently, the code generator - will not produce such dependencies. */ - samep = &JF(*samep); - } -#ifdef notdef - /* XXX This doesn't cover everything. */ - for (i = 0; i < N_ATOMS; ++i) - if ((*samep)->val[i] != pred->val[i]) - return; -#endif - /* Pull up the node. */ - pull = *samep; - *samep = JF(pull); - JF(pull) = *diffp; - - /* - * At the top of the chain, each predecessor needs to point at the - * pulled up node. Inside the chain, there is only one predecessor - * to worry about. - */ - if (at_top) { - for (ep = b->in_edges; ep != 0; ep = ep->next) { - if (JT(ep->pred) == b) - JT(ep->pred) = pull; - else - JF(ep->pred) = pull; - } - } - else - *diffp = pull; - - done = 0; -} - -static void -and_pullup(b) - struct block *b; -{ - int val, at_top; - struct block *pull; - struct block **diffp, **samep; - struct edge *ep; - - ep = b->in_edges; - if (ep == 0) - return; - - /* - * Make sure each predecessor loads the same value. - */ - val = ep->pred->val[A_ATOM]; - for (ep = ep->next; ep != 0; ep = ep->next) - if (val != ep->pred->val[A_ATOM]) - return; - - if (JT(b->in_edges->pred) == b) - diffp = &JT(b->in_edges->pred); - else - diffp = &JF(b->in_edges->pred); - - at_top = 1; - while (1) { - if (*diffp == 0) - return; - - if (JF(*diffp) != JF(b)) - return; - - if (!SET_MEMBER((*diffp)->dom, b->id)) - return; - - if ((*diffp)->val[A_ATOM] != val) - break; - - diffp = &JT(*diffp); - at_top = 0; - } - samep = &JT(*diffp); - while (1) { - if (*samep == 0) - return; - - if (JF(*samep) != JF(b)) - return; - - if (!SET_MEMBER((*samep)->dom, b->id)) - return; - - if ((*samep)->val[A_ATOM] == val) - break; - - /* XXX Need to check that there are no data dependencies - between diffp and samep. Currently, the code generator - will not produce such dependencies. */ - samep = &JT(*samep); - } -#ifdef notdef - /* XXX This doesn't cover everything. */ - for (i = 0; i < N_ATOMS; ++i) - if ((*samep)->val[i] != pred->val[i]) - return; -#endif - /* Pull up the node. */ - pull = *samep; - *samep = JT(pull); - JT(pull) = *diffp; - - /* - * At the top of the chain, each predecessor needs to point at the - * pulled up node. Inside the chain, there is only one predecessor - * to worry about. - */ - if (at_top) { - for (ep = b->in_edges; ep != 0; ep = ep->next) { - if (JT(ep->pred) == b) - JT(ep->pred) = pull; - else - JF(ep->pred) = pull; - } - } - else - *diffp = pull; - - done = 0; -} - -static void -opt_blks(root, do_stmts) - struct block *root; - int do_stmts; -{ - int i, maxlevel; - struct block *p; - - init_val(); - maxlevel = root->level; - for (i = maxlevel; i >= 0; --i) - for (p = levels[i]; p; p = p->link) - opt_blk(p, do_stmts); - - if (do_stmts) - /* - * No point trying to move branches; it can't possibly - * make a difference at this point. - */ - return; - - for (i = 1; i <= maxlevel; ++i) { - for (p = levels[i]; p; p = p->link) { - opt_j(&p->et); - opt_j(&p->ef); - } - } - for (i = 1; i <= maxlevel; ++i) { - for (p = levels[i]; p; p = p->link) { - or_pullup(p); - and_pullup(p); - } - } -} - -static __inline void -link_inedge(parent, child) - struct edge *parent; - struct block *child; -{ - parent->next = child->in_edges; - child->in_edges = parent; -} - -static void -find_inedges(root) - struct block *root; -{ - int i; - struct block *b; - - for (i = 0; i < n_blocks; ++i) - blocks[i]->in_edges = 0; - - /* - * Traverse the graph, adding each edge to the predecessor - * list of its successors. Skip the leaves (i.e. level 0). - */ - for (i = root->level; i > 0; --i) { - for (b = levels[i]; b != 0; b = b->link) { - link_inedge(&b->et, JT(b)); - link_inedge(&b->ef, JF(b)); - } - } -} - -static void -opt_root(b) - struct block **b; -{ - struct slist *tmp, *s; - - s = (*b)->stmts; - (*b)->stmts = 0; - while (BPF_CLASS((*b)->s.code) == BPF_JMP && JT(*b) == JF(*b)) - *b = JT(*b); - - tmp = (*b)->stmts; - if (tmp != 0) - sappend(s, tmp); - (*b)->stmts = s; - - /* - * If the root node is a return, then there is no - * point executing any statements (since the bpf machine - * has no side effects). - */ - if (BPF_CLASS((*b)->s.code) == BPF_RET) - (*b)->stmts = 0; -} - -static void -opt_loop(root, do_stmts) - struct block *root; - int do_stmts; -{ - -#ifdef BDEBUG - if (dflag > 1) - opt_dump(root); -#endif - do { - done = 1; - find_levels(root); - find_dom(root); - find_closure(root); - find_inedges(root); - find_ud(root); - find_edom(root); - opt_blks(root, do_stmts); -#ifdef BDEBUG - if (dflag > 1) - opt_dump(root); -#endif - } while (!done); -} - -/* - * Optimize the filter code in its dag representation. - */ -void -bpf_optimize(rootp) - struct block **rootp; -{ - struct block *root; - - root = *rootp; - - opt_init(root); - opt_loop(root, 0); - opt_loop(root, 1); - intern_blocks(root); - opt_root(rootp); - opt_cleanup(); -} - -static void -make_marks(p) - struct block *p; -{ - if (!isMarked(p)) { - Mark(p); - if (BPF_CLASS(p->s.code) != BPF_RET) { - make_marks(JT(p)); - make_marks(JF(p)); - } - } -} - -/* - * Mark code array such that isMarked(i) is true - * only for nodes that are alive. - */ -static void -mark_code(p) - struct block *p; -{ - cur_mark += 1; - make_marks(p); -} - -/* - * True iff the two stmt lists load the same value from the packet into - * the accumulator. - */ -static int -eq_slist(x, y) - struct slist *x, *y; -{ - while (1) { - while (x && x->s.code == NOP) - x = x->next; - while (y && y->s.code == NOP) - y = y->next; - if (x == 0) - return y == 0; - if (y == 0) - return x == 0; - if (x->s.code != y->s.code || x->s.k != y->s.k) - return 0; - x = x->next; - y = y->next; - } -} - -static __inline int -eq_blk(b0, b1) - struct block *b0, *b1; -{ - if (b0->s.code == b1->s.code && - b0->s.k == b1->s.k && - b0->et.succ == b1->et.succ && - b0->ef.succ == b1->ef.succ) - return eq_slist(b0->stmts, b1->stmts); - return 0; -} - -static void -intern_blocks(root) - struct block *root; -{ - struct block *p; - int i, j; - int done; - top: - done = 1; - for (i = 0; i < n_blocks; ++i) - blocks[i]->link = 0; - - mark_code(root); - - for (i = n_blocks - 1; --i >= 0; ) { - if (!isMarked(blocks[i])) - continue; - for (j = i + 1; j < n_blocks; ++j) { - if (!isMarked(blocks[j])) - continue; - if (eq_blk(blocks[i], blocks[j])) { - blocks[i]->link = blocks[j]->link ? - blocks[j]->link : blocks[j]; - break; - } - } - } - for (i = 0; i < n_blocks; ++i) { - p = blocks[i]; - if (JT(p) == 0) - continue; - if (JT(p)->link) { - done = 0; - JT(p) = JT(p)->link; - } - if (JF(p)->link) { - done = 0; - JF(p) = JF(p)->link; - } - } - if (!done) - goto top; -} - -static void -opt_cleanup() -{ - free((void *)vnode_base); - free((void *)vmap); - free((void *)edges); - free((void *)space); - free((void *)levels); - free((void *)blocks); -} - -/* - * Return the number of stmts in 's'. - */ -static int -slength(s) - struct slist *s; -{ - int n = 0; - - for (; s; s = s->next) - if (s->s.code != NOP) - ++n; - return n; -} - -/* - * Return the number of nodes reachable by 'p'. - * All nodes should be initially unmarked. - */ -static int -count_blocks(p) - struct block *p; -{ - if (p == 0 || isMarked(p)) - return 0; - Mark(p); - return count_blocks(JT(p)) + count_blocks(JF(p)) + 1; -} - -/* - * Do a depth first search on the flow graph, numbering the - * the basic blocks, and entering them into the 'blocks' array.` - */ -static void -number_blks_r(p) - struct block *p; -{ - int n; - - if (p == 0 || isMarked(p)) - return; - - Mark(p); - n = n_blocks++; - p->id = n; - blocks[n] = p; - - number_blks_r(JT(p)); - number_blks_r(JF(p)); -} - -/* - * Return the number of stmts in the flowgraph reachable by 'p'. - * The nodes should be unmarked before calling. - */ -static int -count_stmts(p) - struct block *p; -{ - int n; - - if (p == 0 || isMarked(p)) - return 0; - Mark(p); - n = count_stmts(JT(p)) + count_stmts(JF(p)); - return slength(p->stmts) + n + 1; -} - -/* - * Allocate memory. All allocation is done before optimization - * is begun. A linear bound on the size of all data structures is computed - * from the total number of blocks and/or statements. - */ -static void -opt_init(root) - struct block *root; -{ - bpf_u_int32 *p; - int i, n, max_stmts; - - /* - * First, count the blocks, so we can malloc an array to map - * block number to block. Then, put the blocks into the array. - */ - unMarkAll(); - n = count_blocks(root); - blocks = (struct block **)malloc(n * sizeof(*blocks)); - unMarkAll(); - n_blocks = 0; - number_blks_r(root); - - n_edges = 2 * n_blocks; - edges = (struct edge **)malloc(n_edges * sizeof(*edges)); - - /* - * The number of levels is bounded by the number of nodes. - */ - levels = (struct block **)malloc(n_blocks * sizeof(*levels)); - - edgewords = n_edges / (8 * sizeof(bpf_u_int32)) + 1; - nodewords = n_blocks / (8 * sizeof(bpf_u_int32)) + 1; - - /* XXX */ - space = (bpf_u_int32 *)malloc(2 * n_blocks * nodewords * sizeof(*space) - + n_edges * edgewords * sizeof(*space)); - p = space; - all_dom_sets = p; - for (i = 0; i < n; ++i) { - blocks[i]->dom = p; - p += nodewords; - } - all_closure_sets = p; - for (i = 0; i < n; ++i) { - blocks[i]->closure = p; - p += nodewords; - } - all_edge_sets = p; - for (i = 0; i < n; ++i) { - register struct block *b = blocks[i]; - - b->et.edom = p; - p += edgewords; - b->ef.edom = p; - p += edgewords; - b->et.id = i; - edges[i] = &b->et; - b->ef.id = n_blocks + i; - edges[n_blocks + i] = &b->ef; - b->et.pred = b; - b->ef.pred = b; - } - max_stmts = 0; - for (i = 0; i < n; ++i) - max_stmts += slength(blocks[i]->stmts) + 1; - /* - * We allocate at most 3 value numbers per statement, - * so this is an upper bound on the number of valnodes - * we'll need. - */ - maxval = 3 * max_stmts; - vmap = (struct vmapinfo *)malloc(maxval * sizeof(*vmap)); - vnode_base = (struct valnode *)malloc(maxval * sizeof(*vmap)); -} - -/* - * Some pointers used to convert the basic block form of the code, - * into the array form that BPF requires. 'fstart' will point to - * the malloc'd array while 'ftail' is used during the recursive traversal. - */ -static struct bpf_insn *fstart; -static struct bpf_insn *ftail; - -#ifdef BDEBUG -int bids[1000]; -#endif - -/* - * Returns true if successful. Returns false if a branch has - * an offset that is too large. If so, we have marked that - * branch so that on a subsequent iteration, it will be treated - * properly. - */ -static int -convert_code_r(p) - struct block *p; -{ - struct bpf_insn *dst; - struct slist *src; - int slen; - u_int off; - int extrajmps; /* number of extra jumps inserted */ - - if (p == 0 || isMarked(p)) - return (1); - Mark(p); - - if (convert_code_r(JF(p)) == 0) - return (0); - if (convert_code_r(JT(p)) == 0) - return (0); - - slen = slength(p->stmts); - dst = ftail -= (slen + 1 + p->longjt + p->longjf); - /* inflate length by any extra jumps */ - - p->offset = dst - fstart; - - for (src = p->stmts; src; src = src->next) { - if (src->s.code == NOP) - continue; - dst->code = (u_short)src->s.code; - dst->k = src->s.k; - ++dst; - } -#ifdef BDEBUG - bids[dst - fstart] = p->id + 1; -#endif - dst->code = (u_short)p->s.code; - dst->k = p->s.k; - if (JT(p)) { - extrajmps = 0; - off = JT(p)->offset - (p->offset + slen) - 1; - if (off >= 256) { - /* offset too large for branch, must add a jump */ - if (p->longjt == 0) { - /* mark this instruction and retry */ - p->longjt++; - return(0); - } - /* branch if T to following jump */ - dst->jt = extrajmps; - extrajmps++; - dst[extrajmps].code = BPF_JMP|BPF_JA; - dst[extrajmps].k = off - extrajmps; - } - else - dst->jt = off; - off = JF(p)->offset - (p->offset + slen) - 1; - if (off >= 256) { - /* offset too large for branch, must add a jump */ - if (p->longjf == 0) { - /* mark this instruction and retry */ - p->longjf++; - return(0); - } - /* branch if F to following jump */ - /* if two jumps are inserted, F goes to second one */ - dst->jf = extrajmps; - extrajmps++; - dst[extrajmps].code = BPF_JMP|BPF_JA; - dst[extrajmps].k = off - extrajmps; - } - else - dst->jf = off; - } - return (1); -} - - -/* - * Convert flowgraph intermediate representation to the - * BPF array representation. Set *lenp to the number of instructions. - */ -struct bpf_insn * -icode_to_fcode(root, lenp) - struct block *root; - int *lenp; -{ - int n; - struct bpf_insn *fp; - - /* - * Loop doing convert_codr_r() until no branches remain - * with too-large offsets. - */ - while (1) { - unMarkAll(); - n = *lenp = count_stmts(root); - - fp = (struct bpf_insn *)malloc(sizeof(*fp) * n); - memset((char *)fp, 0, sizeof(*fp) * n); - fstart = fp; - ftail = fp + n; - - unMarkAll(); - if (convert_code_r(root)) - break; - free(fp); - } - - return fp; -} - -#ifdef BDEBUG -static void -opt_dump(root) - struct block *root; -{ - struct bpf_program f; - - memset(bids, 0, sizeof bids); - f.bf_insns = icode_to_fcode(root, &f.bf_len); - bpf_dump(&f, 1); - putchar('\n'); - free((char *)f.bf_insns); -} -#endif diff --git a/pcap/pcap-bpf.c b/pcap/pcap-bpf.c deleted file mode 100644 index c327b55..0000000 --- a/pcap/pcap-bpf.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: pcap-bpf.c,v 1.7 1996/09/16 02:33:08 tholo Exp $ */ - -/* - * Copyright (c) 1993, 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. - */ -#ifndef lint -static char rcsid[] = - "@(#)Header: pcap-bpf.c,v 1.25 96/06/24 02:50:11 leres Exp (LBL)"; -#endif - -#include /* optionally get BSD define */ -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -int -pcap_stats(pcap_t *p, struct pcap_stat *ps) -{ - struct bpf_stat s; - - if (ioctl(p->fd, BIOCGSTATS, (caddr_t)&s) < 0) { - sprintf(p->errbuf, "BIOCGSTATS: %s", pcap_strerror(errno)); - return (-1); - } - - ps->ps_recv = s.bs_recv; - ps->ps_drop = s.bs_drop; - return (0); -} - -int -pcap_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) -{ - int cc; - int n = 0; - register u_char *bp, *ep; - - again: - cc = p->cc; - if (p->cc == 0) { - cc = read(p->fd, (char *)p->buffer, p->bufsize); - if (cc < 0) { - /* Don't choke when we get ptraced */ - switch (errno) { - - case EINTR: - goto again; - - case EWOULDBLOCK: - return (0); -#if defined(sun) && !defined(BSD) - /* - * Due to a SunOS bug, after 2^31 bytes, the kernel - * file offset overflows and read fails with EINVAL. - * The lseek() to 0 will fix things. - */ - case EINVAL: - if (lseek(p->fd, 0L, SEEK_CUR) + - p->bufsize < 0) { - (void)lseek(p->fd, 0L, SEEK_SET); - goto again; - } - /* fall through */ -#endif - } - sprintf(p->errbuf, "read: %s", pcap_strerror(errno)); - return (-1); - } - bp = p->buffer; - } else - bp = p->bp; - - /* - * Loop through each packet. - */ -#define bhp ((struct bpf_hdr *)bp) - ep = bp + cc; - while (bp < ep) { - register int caplen, hdrlen; - caplen = bhp->bh_caplen; - hdrlen = bhp->bh_hdrlen; - /* - * XXX A bpf_hdr matches a pcap_pkthdr. - */ - (*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen); - bp += BPF_WORDALIGN(caplen + hdrlen); - if (++n >= cnt && cnt > 0) { - p->bp = bp; - p->cc = ep - bp; - return (n); - } - } -#undef bhp - p->cc = 0; - return (n); -} - -int -pcap_inject(pcap_t *p, const void *buf, size_t len) -{ - return (write(p->fd, buf, len)); -} - -static __inline int -bpf_open(pcap_t *p, char *errbuf) -{ - int fd; - int n = 0; - char device[sizeof "/dev/bpf000"]; - - /* - * Go through all the minors and find one that isn't in use. - */ - do { - (void)sprintf(device, "/dev/bpf%d", n++); - fd = open(device, O_RDONLY); - } while (fd < 0 && errno == EBUSY); - - /* - * XXX better message for all minors used - */ - if (fd < 0) - sprintf(errbuf, "%s: %s", device, pcap_strerror(errno)); - - return (fd); -} - -pcap_t * -pcap_open_live(char *device, int snaplen, int promisc, int to_ms, char *ebuf) -{ - int fd; - struct ifreq ifr; - struct bpf_version bv; - u_int v; - pcap_t *p; - - p = (pcap_t *)malloc(sizeof(*p)); - if (p == NULL) { - sprintf(ebuf, "malloc: %s", pcap_strerror(errno)); - return (NULL); - } - bzero(p, sizeof(*p)); - fd = bpf_open(p, ebuf); - if (fd < 0) - goto bad; - - p->fd = fd; - p->snapshot = snaplen; - - if (ioctl(fd, BIOCVERSION, (caddr_t)&bv) < 0) { - sprintf(ebuf, "BIOCVERSION: %s", pcap_strerror(errno)); - goto bad; - } - if (bv.bv_major != BPF_MAJOR_VERSION || - bv.bv_minor < BPF_MINOR_VERSION) { - sprintf(ebuf, "kernel bpf filter out of date"); - goto bad; - } - (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); - if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) { - sprintf(ebuf, "%s: %s", device, pcap_strerror(errno)); - goto bad; - } - /* Get the data link layer type. */ - if (ioctl(fd, BIOCGDLT, (caddr_t)&v) < 0) { - sprintf(ebuf, "BIOCGDLT: %s", pcap_strerror(errno)); - goto bad; - } - p->linktype = v; - - /* set timeout */ - if (to_ms != 0) { - struct timeval to; - to.tv_sec = to_ms / 1000; - to.tv_usec = (to_ms * 1000) % 1000000; - if (ioctl(p->fd, BIOCSRTIMEOUT, (caddr_t)&to) < 0) { - sprintf(ebuf, "BIOCSRTIMEOUT: %s", - pcap_strerror(errno)); - goto bad; - } - } - if (promisc) - /* set promiscuous mode, okay if it fails */ - (void)ioctl(p->fd, BIOCPROMISC, NULL); - - if (ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) { - sprintf(ebuf, "BIOCGBLEN: %s", pcap_strerror(errno)); - goto bad; - } - p->bufsize = v; - p->buffer = (u_char *)malloc(p->bufsize); - if (p->buffer == NULL) { - sprintf(ebuf, "malloc: %s", pcap_strerror(errno)); - goto bad; - } - - return (p); - bad: - (void)close(fd); - free(p); - return (NULL); -} - -int -pcap_setfilter(pcap_t *p, struct bpf_program *fp) -{ - if (p->sf.rfile != NULL) - p->fcode = *fp; - else if (ioctl(p->fd, BIOCSETF, (caddr_t)fp) < 0) { - sprintf(p->errbuf, "BIOCSETF: %s", pcap_strerror(errno)); - return (-1); - } - return (0); -} diff --git a/pcap/pcap-int.h b/pcap/pcap-int.h deleted file mode 100644 index 9513df1..0000000 --- a/pcap/pcap-int.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: pcap-int.h,v 1.6 1996/08/03 12:38:44 niklas Exp $ */ - -/* - * Copyright (c) 1994, 1995 - * 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#) Header: pcap-int.h,v 1.14 95/10/21 22:04:49 leres Exp (LBL) - */ - -#ifndef pcap_int_h -#define pcap_int_h - -#include - -/* - * Savefile - */ -struct pcap_sf { - FILE *rfile; - int swapped; - int version_major; - int version_minor; - u_char *base; -}; - -struct pcap_md { - struct pcap_stat stat; - /*XXX*/ - int use_bpf; - u_long TotPkts; /* can't oflow for 79 hrs on ether */ - u_long TotAccepted; /* count accepted by filter */ - u_long TotDrops; /* count of dropped packets */ - long TotMissed; /* missed by i/f during this run */ - long OrigMissed; /* missed by i/f before this run */ -}; - -struct pcap { - int fd; - int snapshot; - int linktype; - int tzoff; /* timezone offset */ - - struct pcap_sf sf; - struct pcap_md md; - - /* - * Read buffer. - */ - int bufsize; - u_char *buffer; - u_char *bp; - int cc; - - /* - * Place holder for pcap_next(). - */ - u_char *pkt; - - - /* - * Placeholder for filter code if bpf not in kernel. - */ - struct bpf_program fcode; - - char errbuf[PCAP_ERRBUF_SIZE]; -}; - -int yylex(void); - -/* XXX should these be in pcap.h? */ -int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *); -int pcap_read(pcap_t *, int cnt, pcap_handler, u_char *); - -/* Ultrix pads to make everything line up on a nice boundary */ -#if defined(ultrix) || defined(__alpha) -#define PCAP_FDDIPAD 3 -#endif -#endif diff --git a/pcap/pcap-namedb.h b/pcap/pcap-namedb.h deleted file mode 100644 index d8bf162..0000000 --- a/pcap/pcap-namedb.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: pcap-namedb.h,v 1.4 1996/07/12 13:19:11 mickey Exp $ */ - -/* - * Copyright (c) 1994, 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#) Header: pcap-namedb.h,v 1.4 96/06/23 02:21:08 leres Exp (LBL) - */ - -#ifndef lib_pcap_ethers_h -#define lib_pcap_ethers_h - -/* - * As returned by the pcap_next_etherent() - * XXX this stuff doesn't belong in this interface, but this - * library already must do name to address translation, so - * on systems that don't have support for /etc/ethers, we - * export these hooks since they'll - */ -struct pcap_etherent { - u_char addr[6]; - char name[122]; -}; -#ifndef PCAP_ETHERS_FILE -#define PCAP_ETHERS_FILE "/etc/ethers" -#endif -struct pcap_etherent *pcap_next_etherent(FILE *); -u_char *pcap_ether_hostton(const char*); -u_char *pcap_ether_aton(const char *); - -bpf_u_int32 **pcap_nametoaddr(const char *); -bpf_u_int32 pcap_nametonetaddr(const char *); - -int pcap_nametoport(const char *, int *, int *); -int pcap_nametoproto(const char *); -int pcap_nametoeproto(const char *); -/* - * If a protocol is unknown, PROTO_UNDEF is returned. - * Also, pcap_nametoport() returns the protocol along with the port number. - * If there are ambiguous entried in /etc/services (i.e. domain - * can be either tcp or udp) PROTO_UNDEF is returned. - */ -#define PROTO_UNDEF -1 - -/* XXX move these to pcap-int.h? */ -bpf_u_int32 __pcap_atodn(const char *); -bpf_u_int32 __pcap_atoin(const char *); -u_short __pcap_nametodnaddr(const char *); - -#endif diff --git a/pcap/pcap.c b/pcap/pcap.c deleted file mode 100644 index c34b0b2..0000000 --- a/pcap/pcap.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: pcap.c,v 1.4 1996/07/12 13:19:12 mickey Exp $ */ - -/* - * Copyright (c) 1993, 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char rcsid[] = - "@(#) Header: pcap.c,v 1.25 96/06/05 21:45:26 leres Exp (LBL)"; -#endif - -#include - -#include -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -int -pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user) -{ - register int cc; - - if (p->sf.rfile != NULL) - return (pcap_offline_read(p, cnt, callback, user)); - /* XXX keep reading until we get something (or an error occurs) */ - do { - cc = pcap_read(p, cnt, callback, user); - } while (cc == 0); - return (cc); -} - -int -pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user) -{ - for (;;) { - int n = pcap_dispatch(p, cnt, callback, user); - if (n <= 0) - return (n); - if (cnt > 0) { - cnt -= n; - if (cnt <= 0) - return (0); - } - } -} - -struct singleton { - struct pcap_pkthdr *hdr; - const u_char *pkt; -}; - - -static void -pcap_oneshot(u_char *userData, const struct pcap_pkthdr *h, const u_char *pkt) -{ - struct singleton *sp = (struct singleton *)userData; - *sp->hdr = *h; - sp->pkt = pkt; -} - -const u_char * -pcap_next(pcap_t *p, struct pcap_pkthdr *h) -{ - struct singleton s; - - s.hdr = h; - if (pcap_dispatch(p, 1, pcap_oneshot, (u_char*)&s) <= 0) - return (0); - return (s.pkt); -} - -int -pcap_datalink(pcap_t *p) -{ - return (p->linktype); -} - -int -pcap_snapshot(pcap_t *p) -{ - return (p->snapshot); -} - -int -pcap_is_swapped(pcap_t *p) -{ - return (p->sf.swapped); -} - -int -pcap_major_version(pcap_t *p) -{ - return (p->sf.version_major); -} - -int -pcap_minor_version(pcap_t *p) -{ - return (p->sf.version_minor); -} - -FILE * -pcap_file(pcap_t *p) -{ - return (p->sf.rfile); -} - -int -pcap_fileno(pcap_t *p) -{ - return (p->fd); -} - -void -pcap_perror(pcap_t *p, char *prefix) -{ - fprintf(stderr, "%s: %s\n", prefix, p->errbuf); -} - -char * -pcap_geterr(pcap_t *p) -{ - return (p->errbuf); -} - -/* - * Not all systems have strerror(). - */ -char * -pcap_strerror(int errnum) -{ -#ifdef HAVE_STRERROR - return (strerror(errnum)); -#else - extern int sys_nerr; - extern const char *const sys_errlist[]; - static char ebuf[20]; - - if ((unsigned int)errnum < sys_nerr) - return ((char *)sys_errlist[errnum]); - (void)sprintf(ebuf, "Unknown error: %d", errnum); - return(ebuf); -#endif -} - -void -pcap_close(pcap_t *p) -{ - /*XXX*/ - if (p->fd >= 0) - close(p->fd); - if (p->sf.rfile != NULL) { - (void)fclose(p->sf.rfile); - if (p->sf.base != NULL) - free(p->sf.base); - } else if (p->buffer != NULL) - free(p->buffer); - - free(p); -} diff --git a/pcap/pcap.h b/pcap/pcap.h deleted file mode 100644 index 46db423..0000000 --- a/pcap/pcap.h +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: pcap.h,v 1.6 1996/07/12 13:19:12 mickey Exp $ */ - -/* - * Copyright (c) 1993, 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the Computer Systems - * Engineering Group at Lawrence Berkeley Laboratory. - * 4. Neither the name of the University nor of the Laboratory may be used - * to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#) Header: pcap.h,v 1.19 96/06/16 22:36:28 leres Exp (LBL) - */ - -#ifndef lib_pcap_h -#define lib_pcap_h - -#include -#include - -#include - -#include - -#define PCAP_VERSION_MAJOR 2 -#define PCAP_VERSION_MINOR 4 - -#define PCAP_ERRBUF_SIZE 256 - -/* - * Compatibility for systems that have a bpf.h that - * predates the bpf typedefs for 64-bit support. - */ -#if BPF_RELEASE - 0 < 199406 -typedef int bpf_int32; -typedef u_int bpf_u_int32; -#endif - -typedef struct pcap pcap_t; -typedef struct pcap_dumper pcap_dumper_t; - -/* - * The first record in the file contains saved values for some - * of the flags used in the printout phases of tcpdump. - * Many fields here are 32 bit ints so compilers won't insert unwanted - * padding; these files need to be interchangeable across architectures. - */ -struct pcap_file_header { - bpf_u_int32 magic; - u_short version_major; - u_short version_minor; - bpf_int32 thiszone; /* gmt to local correction */ - bpf_u_int32 sigfigs; /* accuracy of timestamps */ - bpf_u_int32 snaplen; /* max length saved portion of each pkt */ - bpf_u_int32 linktype; /* data link type (DLT_*) */ -}; - -/* - * Each packet in the dump file is prepended with this generic header. - * This gets around the problem of different headers for different - * packet interfaces. - */ -struct pcap_pkthdr { - struct timeval ts; /* time stamp */ - bpf_u_int32 caplen; /* length of portion present */ - bpf_u_int32 len; /* length this packet (off wire) */ -}; - -/* - * As returned by the pcap_stats() - */ -struct pcap_stat { - u_int ps_recv; /* number of packets received */ - u_int ps_drop; /* number of packets dropped */ - u_int ps_ifdrop; /* drops by interface XXX not yet supported */ -}; - -typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *, - const u_char *); - -char *pcap_lookupdev(char *); -int pcap_lookupnet(char *, bpf_u_int32 *, bpf_u_int32 *, char *); -pcap_t *pcap_open_live(char *, int, int, int, char *); -pcap_t *pcap_open_offline(char *, char *); -void pcap_close(pcap_t *); -int pcap_loop(pcap_t *, int, pcap_handler, u_char *); -int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *); -const u_char* - pcap_next(pcap_t *, struct pcap_pkthdr *); -int pcap_stats(pcap_t *, struct pcap_stat *); -int pcap_setfilter(pcap_t *, struct bpf_program *); -void pcap_perror(pcap_t *, char *); -char *pcap_strerror(int); -char *pcap_geterr(pcap_t *); -int pcap_compile(pcap_t *, struct bpf_program *, char *, int, - bpf_u_int32); -/* XXX */ -int pcap_freecode(pcap_t *, struct bpf_program *); -int pcap_datalink(pcap_t *); -int pcap_snapshot(pcap_t *); -int pcap_is_swapped(pcap_t *); -int pcap_major_version(pcap_t *); -int pcap_minor_version(pcap_t *); - -/* XXX */ -FILE *pcap_file(pcap_t *); -int pcap_fileno(pcap_t *); - -pcap_dumper_t *pcap_dump_open(pcap_t *, char *); -void pcap_dump_close(pcap_dumper_t *); -void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *); - -/* XXX this guy lives in the bpf tree */ -u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int); -char *bpf_image(struct bpf_insn *, int); - -/* XXX */ -extern int pcap_fddipad; - -#endif diff --git a/pcap/savefile.c b/pcap/savefile.c deleted file mode 100644 index ba1e9c0..0000000 --- a/pcap/savefile.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: savefile.c,v 1.4 1996/07/12 13:19:13 mickey Exp $ */ - -/* - * Copyright (c) 1993, 1994, 1995 - * 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. - */ -#ifndef lint -static char rcsid[] = - "@(#)Header: savefile.c,v 1.28 95/10/07 03:09:06 leres Exp (LBL)"; -#endif - -/* - * savefile.c - supports offline use of tcpdump - * Extraction/creation by Jeffrey Mogul, DECWRL - * Modified by Steve McCanne, LBL. - * - * Used to save the received packet headers, after filtering, to - * a file, and then read them later. - * The first record in the file contains saved values for the machine - * dependent values so we can print the dump file on any architecture. - */ - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" - -#define TCPDUMP_MAGIC 0xa1b2c3d4 - -/* - * We use the "receiver-makes-right" approach to byte order, - * because time is at a premium when we are writing the file. - * In other words, the pcap_file_header and pcap_pkthdr, - * records are written in host byte order. - * Note that the packets are always written in network byte order. - * - * ntoh[ls] aren't sufficient because we might need to swap on a big-endian - * machine (if the file was written in little-end order). - */ -#define SWAPLONG(y) \ -((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff)) -#define SWAPSHORT(y) \ - ( (((y)&0xff)<<8) | (((y)&0xff00)>>8) ) - -#define SFERR_TRUNC 1 -#define SFERR_BADVERSION 2 -#define SFERR_BADF 3 -#define SFERR_EOF 4 /* not really an error, just a status */ - -static int -sf_write_header(FILE *fp, int linktype, int thiszone, int snaplen) -{ - struct pcap_file_header hdr; - - hdr.magic = TCPDUMP_MAGIC; - hdr.version_major = PCAP_VERSION_MAJOR; - hdr.version_minor = PCAP_VERSION_MINOR; - - hdr.thiszone = thiszone; - hdr.snaplen = snaplen; - hdr.sigfigs = 0; - hdr.linktype = linktype; - - if (fwrite((char *)&hdr, sizeof(hdr), 1, fp) != 1) - return (-1); - - return (0); -} - -static void -swap_hdr(struct pcap_file_header *hp) -{ - hp->version_major = SWAPSHORT(hp->version_major); - hp->version_minor = SWAPSHORT(hp->version_minor); - hp->thiszone = SWAPLONG(hp->thiszone); - hp->sigfigs = SWAPLONG(hp->sigfigs); - hp->snaplen = SWAPLONG(hp->snaplen); - hp->linktype = SWAPLONG(hp->linktype); -} - -pcap_t * -pcap_open_offline(char *fname, char *errbuf) -{ - register pcap_t *p; - register FILE *fp; - struct pcap_file_header hdr; - int linklen; - - p = (pcap_t *)malloc(sizeof(*p)); - if (p == NULL) { - strcpy(errbuf, "out of swap"); - return (NULL); - } - - memset((char *)p, 0, sizeof(*p)); - /* - * Set this field so we don't close stdin in pcap_close! - */ - p->fd = -1; - - if (fname[0] == '-' && fname[1] == '\0') - fp = stdin; - else { - fp = fopen(fname, "r"); - if (fp == NULL) { - sprintf(errbuf, "%s: %s", fname, pcap_strerror(errno)); - goto bad; - } - } - if (fread((char *)&hdr, sizeof(hdr), 1, fp) != 1) { - sprintf(errbuf, "fread: %s", pcap_strerror(errno)); - goto bad; - } - if (hdr.magic != TCPDUMP_MAGIC) { - if (SWAPLONG(hdr.magic) != TCPDUMP_MAGIC) { - sprintf(errbuf, "bad dump file format"); - goto bad; - } - p->sf.swapped = 1; - swap_hdr(&hdr); - } - if (hdr.version_major < PCAP_VERSION_MAJOR) { - sprintf(errbuf, "archaic file format"); - goto bad; - } - p->tzoff = hdr.thiszone; - p->snapshot = hdr.snaplen; - p->linktype = hdr.linktype; - p->sf.rfile = fp; - p->bufsize = hdr.snaplen; - - /* Align link header as required for proper data alignment */ - /* XXX should handle all types */ - switch (p->linktype) { - - case DLT_EN10MB: - linklen = 14; - break; - - case DLT_FDDI: - linklen = 13 + 8; /* fddi_header + llc */ - break; - - case DLT_NULL: - default: - linklen = 0; - break; - } - - p->sf.base = (u_char *)malloc(p->bufsize + BPF_ALIGNMENT); - p->buffer = p->sf.base + BPF_ALIGNMENT - (linklen % BPF_ALIGNMENT); - p->sf.version_major = hdr.version_major; - p->sf.version_minor = hdr.version_minor; - - return (p); - bad: - free(p); - return (NULL); -} - -/* - * Read sf_readfile and return the next packet. Return the header in hdr - * and the contents in buf. Return 0 on success, SFERR_EOF if there were - * no more packets, and SFERR_TRUNC if a partial packet was encountered. - */ -static int -sf_next_packet(pcap_t *p, struct pcap_pkthdr *hdr, u_char *buf, int buflen) -{ - FILE *fp = p->sf.rfile; - - /* read the stamp */ - if (fread((char *)hdr, sizeof(struct pcap_pkthdr), 1, fp) != 1) { - /* probably an EOF, though could be a truncated packet */ - return (1); - } - - if (p->sf.swapped) { - /* these were written in opposite byte order */ - hdr->caplen = SWAPLONG(hdr->caplen); - hdr->len = SWAPLONG(hdr->len); - hdr->ts.tv_sec = SWAPLONG(hdr->ts.tv_sec); - hdr->ts.tv_usec = SWAPLONG(hdr->ts.tv_usec); - } - /* - * We interchanged the caplen and len fields at version 2.3, - * in order to match the bpf header layout. But unfortunately - * some files were written with version 2.3 in their headers - * but without the interchanged fields. - */ - if (p->sf.version_minor < 3 || - (p->sf.version_minor == 3 && hdr->caplen > hdr->len)) { - int t = hdr->caplen; - hdr->caplen = hdr->len; - hdr->len = t; - } - - if (hdr->caplen > buflen) { - /* - * This can happen due to Solaris 2.3 systems tripping - * over the BUFMOD problem and not setting the snapshot - * correctly in the savefile header. If the caplen isn't - * grossly wrong, try to salvage. - */ - static u_char *tp = NULL; - static int tsize = 0; - - if (tsize < hdr->caplen) { - tsize = ((hdr->caplen + 1023) / 1024) * 1024; - if (tp != NULL) - free((u_char *)tp); - tp = (u_char *)malloc(tsize); - if (tp == NULL) { - sprintf(p->errbuf, "BUFMOD hack malloc"); - return (-1); - } - } - if (fread((char *)tp, hdr->caplen, 1, fp) != 1) { - sprintf(p->errbuf, "truncated dump file"); - return (-1); - } - memcpy((char *)buf, (char *)tp, buflen); - - } else { - /* read the packet itself */ - - if (fread((char *)buf, hdr->caplen, 1, fp) != 1) { - sprintf(p->errbuf, "truncated dump file"); - return (-1); - } - } - return (0); -} - -/* - * Print out packets stored in the file initialized by sf_read_init(). - * If cnt > 0, return after 'cnt' packets, otherwise continue until eof. - */ -int -pcap_offline_read(pcap_t *p, int cnt, pcap_handler callback, u_char *user) -{ - struct bpf_insn *fcode = p->fcode.bf_insns; - int status = 0; - int n = 0; - - while (status == 0) { - struct pcap_pkthdr h; - - status = sf_next_packet(p, &h, p->buffer, p->bufsize); - if (status) { - if (status == 1) - return (0); - return (status); - } - - if (fcode == NULL || - bpf_filter(fcode, p->buffer, h.len, h.caplen)) { - (*callback)(user, &h, p->buffer); - if (++n >= cnt && cnt > 0) - break; - } - } - /*XXX this breaks semantics tcpslice expects */ - return (n); -} - -/* - * Output a packet to the initialized dump file. - */ -void -pcap_dump(u_char *user, const struct pcap_pkthdr *h, const u_char *sp) -{ - register FILE *f; - - f = (FILE *)user; - /* XXX we should check the return status */ - (void)fwrite((char *)h, sizeof(*h), 1, f); - (void)fwrite((char *)sp, h->caplen, 1, f); -} - -/* - * Initialize so that sf_write() will output to the file named 'fname'. - */ -pcap_dumper_t * -pcap_dump_open(pcap_t *p, char *fname) -{ - FILE *f; - if (fname[0] == '-' && fname[1] == '\0') - f = stdout; - else { - f = fopen(fname, "w"); - if (f == NULL) { - sprintf(p->errbuf, "%s: %s", - fname, pcap_strerror(errno)); - return (NULL); - } - } - (void)sf_write_header(f, p->linktype, p->tzoff, p->snapshot); - return ((pcap_dumper_t *)f); -} - -void -pcap_dump_close(pcap_dumper_t *p) -{ - -#ifdef notyet - if (ferror((FILE *)p)) - return-an-error; - /* XXX should check return from fclose() too */ -#endif - (void)fclose((FILE *)p); -} diff --git a/pcap/scanner.l b/pcap/scanner.l deleted file mode 100644 index 2cbb693..0000000 --- a/pcap/scanner.l +++ /dev/null @@ -1,198 +0,0 @@ -%{ -/* $OpenBSD: scanner.l,v 1.5 1996/07/12 13:19:13 mickey Exp $ */ - -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/pcap/scanner.l,v 1.1.1.1 1999/05/02 03:57:55 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include -#include - -#include -#include - -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -#include "pcap-int.h" -#include "gencode.h" -#include "y.tab.h" - -static int stoi(char *); -static inline int xdtoi(int); - -#ifdef FLEX_SCANNER -#undef YY_INPUT -#define YY_INPUT(buf, result, max)\ - {\ - char *src = in_buffer;\ - int i;\ -\ - if (*src == 0)\ - result = YY_NULL;\ - else {\ - for (i = 0; *src && i < max; ++i)\ - buf[i] = *src++;\ - in_buffer += i;\ - result = i;\ - }\ - } -#else -#undef getc -#define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++) -#endif - -extern YYSTYPE yylval; - -static char *in_buffer; - -%} - -N ([0-9]+|(0X|0x)[0-9A-Fa-f]+) -B ([0-9A-Fa-f][0-9A-Fa-f]?) - -%a 3000 - -%% -dst return DST; -src return SRC; - -link|ether|ppp|slip return LINK; -fddi return LINK; -arp return ARP; -rarp return RARP; -ip return IP; -tcp return TCP; -udp return UDP; -icmp return ICMP; -igmp return IGMP; - -decnet return DECNET; -lat return LAT; -moprc return MOPRC; -mopdl return MOPDL; - -host return HOST; -net return NET; -port return PORT; -proto return PROTO; - -gateway return GATEWAY; - -less return LESS; -greater return GREATER; -byte return BYTE; -broadcast return TK_BROADCAST; -multicast return TK_MULTICAST; - -and|"&&" return AND; -or|"||" return OR; -not return '!'; - -len|length return LEN; -inbound return INBOUND; -outbound return OUTBOUND; - -[ \n\t] ; -[+\-*/:\[\]!<>()&|=] return yytext[0]; -">=" return GEQ; -"<=" return LEQ; -"!=" return NEQ; -"==" return '='; -"<<" return LSH; -">>" return RSH; -{N} { yylval.i = stoi((char *)yytext); return NUM; } -({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) { - yylval.s = sdup((char *)yytext); return HID; -} -{B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext); - return EID; } -{B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); } -[A-Za-z][-_.A-Za-z0-9]* { yylval.s = sdup((char *)yytext); return ID; } -"\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; } -[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ { bpf_error("illegal token: %s\n", yytext); } -. { bpf_error("illegal char '%c'", *yytext); } -%% -void -lex_init(buf) - char *buf; -{ - in_buffer = buf; -} - -/* - * Also define a yywrap. Note that if we're using flex, it will - * define a macro to map this identifier to pcap_wrap. - */ -int -yywrap() -{ - return 1; -} - -/* Hex digit to integer. */ -static inline int -xdtoi(c) - register int c; -{ - if (isdigit(c)) - return c - '0'; - else if (islower(c)) - return c - 'a' + 10; - else - return c - 'A' + 10; -} - -/* - * Convert string to integer. Just like atoi(), but checks for - * preceding 0x or 0 and uses hex or octal instead of decimal. - */ -static int -stoi(s) - char *s; -{ - int base = 10; - int n = 0; - - if (*s == '0') { - if (s[1] == 'x' || s[1] == 'X') { - s += 2; - base = 16; - } - else { - base = 8; - s += 1; - } - } - while (*s) - n = n * base + xdtoi(*s++); - - return n; -} - diff --git a/portmap.tproj/Makefile b/portmap.tproj/Makefile deleted file mode 100644 index 5a91e65..0000000 --- a/portmap.tproj/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = portmap - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Tool - -CFILES = portmap.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble portmap.8 - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = tool.make -NEXTSTEP_INSTALLDIR = /usr/sbin -WINDOWS_INSTALLDIR = /usr/sbin -PDO_UNIX_INSTALLDIR = /usr/sbin -LIBS = -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - - - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/portmap.tproj/Makefile.postamble b/portmap.tproj/Makefile.postamble deleted file mode 100644 index f5c79e2..0000000 --- a/portmap.tproj/Makefile.postamble +++ /dev/null @@ -1,110 +0,0 @@ -############################################################################### -# NeXT Makefile.postamble Template -# Copyright 1993, NeXT Computer, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project, sub-project, bundle, or -# palette. Each node in the project's tree of sub-projects and bundles -# should have it's own Makefile.preamble and Makefile.postamble. Additional -# rules (e.g., after_install) that are defined by the developer should be -# defined in this file. -# -############################################################################### -# -# Here are the variables exported by the common "app" makefiles that can be -# used in any customizations you make to the template below: -# -# PRODUCT_ROOT - Name of top-level app-wrapper (e.g., Webster.app) -# OFILE_DIR - Directory into which .o object files are generated. -# (Note that this name is calculated based on the target -# architectures specified in Project Builder). -# DERIVED_SRC_DIR - Directory used for all other derived files -# ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations -# -# NAME - name of application, bundle, subproject, palette, etc. -# LANGUAGE - langage in which the project is written (default "English") -# ENGLISH - boolean flag set iff $(LANGUAGE) = "English" -# JAPANESE - boolean flag set iff $(LANGUAGE) = "Japanese" -# LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES - non-localized resources of project -# PROJECTVERSION - version of ProjectBuilder that output Makefile -# APPICON - application icon file -# DOCICONS - dock icon files -# ICONSECTIONS - Specifies icon sections when linking executable -# -# CLASSES - Class implementation files in project. -# HFILES - Header files in project. -# MFILES - Other Objective-C source files in project. -# CFILES - Other C source files in project. -# PSWFILES - .psw files in the project -# PSWMFILES - .pswm files in the project -# SUBPROJECTS - Subprojects of this project -# BUNDLES - Bundle subprojects of this project -# OTHERSRCS - Other miscellaneous sources of this project -# OTHERLINKED - Source files not matching a standard source extention -# -# LIBS - Libraries to link with when making app target -# DEBUG_LIBS - Libraries to link with when making debug target -# PROF_LIBS - Libraries to link with when making profile target -# OTHERLINKEDOFILES - Other relocatable files to (always) link in. -# -# APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles -# MAKEFILEDIR - Directory in which to find $(MAKEFILE) -# MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) -# INSTALLDIR - Directory app will be installed into by 'install' target - - -# Change defaults assumed by the standard app makefiles here. Edit the -# following default values as appropriate. (Note that if no Makefile.postamble -# exists, these values will have defaults set in common.make). - -# Add Makefile.preamble, Makefile.postamble, and Makefile.dependencies here if -# you would like changes to them to invalidate previous builds. The project -# depends on $(MAKEFILES) so that changes to Makefiles will trigger a re-build. -#MAKEFILES = Makefile - -# Optimization flag passed to compiler: -#OPTIMIZATION_CFLAG = -O - -# Flags always passed to compiler: -#COMMON_CFLAGS = $(PROJECT_SPECIFIC_CFLAGS) -g -Wall - -# Flags passed to compiler in normal 'app' compiles: -#NORMAL_CFLAGS = $(COMMON_CFLAGS) $(OPTIMIZATION_CFLAG) - -# Flags passed to compiler in 'debug' compiles: -#DEBUG_CFLAGS = $(COMMON_CFLAGS) -DDEBUG - -# Flags passed to compiler in 'profile' compiles -#PROFILE_CFLAGS = $(COMMON_CFLAGS) -pg $(OPTIMIZATION_CFLAG) -DPROFILE - -# Flags passed to yacc -#YFLAGS = -d - -# Ownership and permissions of files installed by 'install' target -#INSTALL_AS_USER = root # User to chown app to -#INSTALL_AS_GROUP = wheel # Group to chgrp app to -#INSTALL_PERMISSIONS = # If set, 'install' chmod's executable to this - -# Options to strip for bundles, apps with bundles, and apps without bundles, -# respectively. -#RELOCATABLE_STRIP_OPTS = -x -u -#DYLD_APP_STRIP_OPTS = -A -n -#APP_STRIP_OPTS = -#TOOL_STRIP_OPTS = -#LIBRARY_STRIP_OPTS = -x -S # Note: -S strips debugging symbols -# (Note: APP_STRIP_OPTS and TOOL_STRIP_OPTS default to empty, but -# developers doing their own dynamic loading should set this to -# $(DYLD_APP_STRIP_OPTS)). -STRIPFLAGS = - - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. Typical -# user-defined rules are before_install and after_install (please don't -# redefine things like install or app, as they are owned by the top-level -# Makefile API), which are rules that get invoked before and after the install -# target runs. Such rules should be specified with the '::' syntax rather than -# a single colon. diff --git a/portmap.tproj/Makefile.preamble b/portmap.tproj/Makefile.preamble deleted file mode 100644 index 2c9003c..0000000 --- a/portmap.tproj/Makefile.preamble +++ /dev/null @@ -1,113 +0,0 @@ -############################################################################### -# NeXT Makefile.preamble Template -# Copyright 1993, NeXT Computer, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project, sub-project, bundle, or -# palette. Each node in the project's tree of sub-projects and bundles -# should have it's own Makefile.preamble and Makefile.postamble. -# -############################################################################### -## Configure the flags passed to $(CC) here. These flags will also be -## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and -## -L flags here. To change the default flags that get passed to ${CC} -## (e.g. change -O to -O2), see Makefile.postamble. - -# Flags passed to compiler (in addition to -g, -O, etc) -OTHER_CFLAGS = -# Flags passed to ld (in addition to -ObjC, etc.) -OTHER_LDFLAGS = - -BUNDLELDFLAGS = # use iff project is a bundle -PALETTELDFLAGS = # use iff project is a palette - -## Specify which headers in this project should be published to the outside -## world in a flat header directory given in PUBLIC_HEADER_DIR (which will be -## prepended by DSTROOT, below. Any subset of these public headers can be -## precompiled automatically after installation, with extra user-defined flags. -PUBLIC_HEADER_DIR = -PUBLIC_HEADERS = -PUBLIC_PRECOMPILED_HEADERS = -PUBLIC_PRECOMPILED_HEADERS_CFLAGS = - -## Configure what is linked in at each level here. Libraries are only used in -## the final 'app' linking step. Final 'app' linking is only done via the -## 'app', 'debug', and 'profile' targets when they are invoked for -## the top-level app. - -# Additional relocatables to be linked in at this level -OTHER_OFILES = -# Additional libs to link apps against ('app' target) -#OTHER_LIBS = -# Additional libs to link apps against ('debug' target) -OTHER_DEBUG_LIBS = -# Additional libs to link apps against ('profile' target) -OTHER_PROF_LIBS = - -# More 'app' libraries when $(JAPANESE) = "YES" -OTHER_JAPANESE_LIBS = -# More 'debug' libraries when $(JAPANESE) = "YES" -OTHER_JAPANESE_DEBUG_LIBS = -# More 'profile' libs when $(JAPANESE) = "YES" -OTHER_JAPANESE_PROF_LIBS = - -# If this is a bundle, and you *know* the enclosing application will not -# be linking with a library which you require in your bundle code, then -# mention it here so that it gets linked into the bundle. Note that this -# is wasteful but sometimes necessary. -BUNDLE_LIBS = - -## Configure how things get built here. Additional dependencies, sourcefiles, -## derived files, and build order should be specified here. - -# Other dependencies of this project -OTHER_PRODUCT_DEPENDS = -# Built *before* building subprojects/bundles -OTHER_INITIAL_TARGETS = -# Other source files maintained by .pre/postamble -OTHER_SOURCEFILES = -# Additional files to be removed by `make clean' -OTHER_GARBAGE = -# Precompiled headers to be built before any compilation occurs (e.g., draw.p) -PRECOMPS = - -# Targets to be built before installation -OTHER_INSTALL_DEPENDS = - -# A virtual root directory (other than /) to be prepended to the $(INSTALLDIR) -# passed from ProjectBuilder. -DSTROOT = - -# Set the following to "YES" if you want the old behavior of recursively -# cleaning all nested subprojects during 'make clean'. -CLEAN_ALL_SUBPROJECTS = - -## Add more obscure source files here to cause them to be automatically -## processed by the appropriate tool. Note that these files should also be -## added to "Supporting Files" in ProjectBuilder. The desired .o files that -## result from these files should also be added to OTHER_OFILES above so they -## will be linked in. - -# .msg files that should have msgwrap run on them -MSGFILES = -# .defs files that should have mig run on them -DEFSFILES = -# .mig files (no .defs files) that should have mig run on them -MIGFILES = - -## Add additional Help directories here (add them to the project as "Other -## Resources" in Project Builder) so that they will be compressed into .store -## files and copied into the app wrapper. If the help directories themselves -## need to also be in the app wrapper, then a cp command will need to be added -## in an after_install target. -OTHER_HELP_DIRS = - -# Don't add more rules here unless you want the first one to be the default -# target for make! Put all your targets in Makefile.postamble. - -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -OTHER_GENERATED_OFILES = $(VERS_OFILE) --include ../Makefile.include diff --git a/portmap.tproj/PB.project b/portmap.tproj/PB.project deleted file mode 100644 index b9275bb..0000000 --- a/portmap.tproj/PB.project +++ /dev/null @@ -1,41 +0,0 @@ -{ - DOCICONFILES = (); - FILESTABLE = { - C_FILES = (); - H_FILES = (); - OTHER_LIBS = (); - OTHER_LINKED = (portmap.c); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble, portmap.8); - PRECOMPILED_HEADERS = (); - PROJECT_HEADERS = (); - PUBLIC_HEADERS = (); - SUBPROJECTS = (); - }; - GENERATEMAIN = YES; - LANGUAGE = English; - LOCALIZABLE_FILES = {}; - NEXTSTEP_BUILDDIR = ""; - NEXTSTEP_BUILDTOOL = /bin/make; - NEXTSTEP_COMPILEROPTIONS = ""; - NEXTSTEP_INSTALLDIR = /usr/sbin; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_LINKEROPTIONS = ""; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDDIR = ""; - PDO_UNIX_BUILDTOOL = /bin/make; - PDO_UNIX_COMPILEROPTIONS = ""; - PDO_UNIX_INSTALLDIR = /usr/sbin; - PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; - PDO_UNIX_LINKEROPTIONS = ""; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = portmap; - PROJECTTYPE = Tool; - PROJECTVERSION = 2.8; - WINDOWS_BUILDDIR = ""; - WINDOWS_BUILDTOOL = /bin/make; - WINDOWS_COMPILEROPTIONS = ""; - WINDOWS_INSTALLDIR = /usr/sbin; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_LINKEROPTIONS = ""; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/portmap.tproj/portmap.8 b/portmap.tproj/portmap.8 deleted file mode 100644 index a651f5f..0000000 --- a/portmap.tproj/portmap.8 +++ /dev/null @@ -1,110 +0,0 @@ -.\" Copyright (c) 1987 Sun Microsystems -.\" Copyright (c) 1990, 1991, 1993 -.\" 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 the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)portmap.8 8.1 (Berkeley) 6/6/93 -.\" -.Dd June 6, 1993 -.Dt PORTMAP 8 -.Os BSD 4.3 -.Sh NAME -.Nm portmap -.Nd -.Tn DARPA -port to -.Tn RPC -program number mapper -.Sh SYNOPSIS -.Nm portmap -.Op Fl d -.Sh DESCRIPTION -.Nm Portmap -is a server that converts -.Tn RPC -program numbers into -.Tn DARPA -protocol port numbers. -It must be running in order to make -.Tn RPC -calls. -.Pp -When an -.Tn RPC -server is started, it will tell -.Nm portmap -what port number it is listening to, and what -.Tn RPC -program numbers it is prepared to serve. -When a client wishes to make an -.Tn RPC -call to a given program number, -it will first contact -.Nm portmap -on the server machine to determine -the port number where -.Tn RPC -packets should be sent. -.Pp -.Nm Portmap -must be started before any -.Tn RPC -servers are invoked. -.Pp -Normally -.Nm portmap -forks and dissociates itself from the terminal -like any other daemon. -.Nm Portmap -then logs errors using -.Xr syslog 3 . -.Pp -Option available: -.Bl -tag -width Ds -.It Fl d -(debug) prevents -.Nm portmap -from running as a daemon, -and causes errors and debugging information -to be printed to the standard error output. -.El -.Sh SEE ALSO -.Xr inetd.conf 5 , -.Xr rpcinfo 8 , -.Xr inetd 8 -.Sh BUGS -If -.Nm portmap -crashes, all servers must be restarted. -.Sh HISTORY -The -.Nm -command appeared in -.Bx 4.3 diff --git a/portmap.tproj/portmap.c b/portmap.tproj/portmap.c deleted file mode 100644 index 8a6c53c..0000000 --- a/portmap.tproj/portmap.c +++ /dev/null @@ -1,661 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/*- - * Copyright (c) 1990, 1993 - * 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)portmap.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - -/* -@(#)portmap.c 2.3 88/08/11 4.0 RPCSRC -static char sccsid[] = "@(#)portmap.c 1.32 87/08/06 Copyr 1984 Sun Micro"; -*/ - -/* - * portmap.c, Implements the program,version to port number mapping for - * rpc. - */ - -/* - * Sun RPC is a product of Sun Microsystems, Inc. and is provided for - * unrestricted use provided that this legend is included on all tape - * media and as a part of the software program in whole or part. Users - * may copy or modify Sun RPC without charge, but are not authorized - * to license or distribute it to anyone else except as part of a product or - * program developed by the user. - * - * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR - * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. - * - * Sun RPC is provided with no support and without any obligation on the - * part of Sun Microsystems, Inc. to assist in its use, correction, - * modification or enhancement. - * - * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE - * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC - * OR ANY PART THEREOF. - * - * In no event will Sun Microsystems, Inc. be liable for any lost revenue - * or profits or other special, indirect and consequential damages, even if - * Sun has been advised of the possibility of such damages. - * - * Sun Microsystems, Inc. - * 2550 Garcia Avenue - * Mountain View, California 94043 - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NETINFO_TAG_NETWORK "network" -#define NETINFO_NETWORK_DIR_PATH "/var/db/netinfo/network.nidb" -#define NETINFO_STAT_LATENCY 30 - -static int have_tag_network = 0; -static struct timeval last_network_stat = {0, 0}; - -void reg_service(); -void reap(); -static void callit(); -struct pmaplist *pmaplist; -int debugging = 0; -extern int errno; -extern int svc_maxfd; - -extern int get_myaddress(); - -static void -portmap_svc_run() -{ - fd_set readfds; - int status; - - for (;;) - { - readfds = svc_fdset; - switch ((status = select(svc_maxfd+1, &readfds, NULL, NULL, NULL))) - { - case -1: - if (errno == EINTR) continue; - - if ((errno == EFAULT) || (errno == EINVAL)) - { - syslog(LOG_ERR, "aborting - select error %d (%s)", - errno, strerror(errno)); - return; - } - - syslog(LOG_NOTICE, "ignoring select error %d (%s)", - errno, strerror(errno)); - continue; - - case 0: - continue; - - default: - svc_getreqset(&readfds); - } - } -} - -int -main(argc, argv) - int argc; - char **argv; -{ - SVCXPRT *xprt; - int sock, c; - struct sockaddr_in addr; - int len = sizeof(struct sockaddr_in); - register struct pmaplist *pml; - - while ((c = getopt(argc, argv, "d")) != EOF) { - switch (c) { - - case 'd': - debugging = 1; - break; - - default: - (void) fprintf(stderr, "usage: %s [-d]\n", argv[0]); - exit(1); - } - } - - if (!debugging && daemon(0, 0)) { - (void) fprintf(stderr, "portmap: fork: %s", strerror(errno)); - exit(1); - } - - openlog("portmap", debugging ? LOG_PID | LOG_PERROR : LOG_PID, - LOG_DAEMON); - - if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - syslog(LOG_ERR, "cannot create udp socket: %m"); - exit(1); - } - - addr.sin_addr.s_addr = 0; - addr.sin_family = AF_INET; - addr.sin_port = htons(PMAPPORT); - if (bind(sock, (struct sockaddr *)&addr, len) != 0) { - syslog(LOG_ERR, "cannot bind udp: %m"); - exit(1); - } - - if ((xprt = svcudp_create(sock)) == (SVCXPRT *)NULL) { - syslog(LOG_ERR, "couldn't do udp_create"); - exit(1); - } - /* make an entry for ourself */ - pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist)); - pml->pml_next = 0; - pml->pml_map.pm_prog = PMAPPROG; - pml->pml_map.pm_vers = PMAPVERS; - pml->pml_map.pm_prot = IPPROTO_UDP; - pml->pml_map.pm_port = PMAPPORT; - pmaplist = pml; - - if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - syslog(LOG_ERR, "cannot create tcp socket: %m"); - exit(1); - } - if (bind(sock, (struct sockaddr *)&addr, len) != 0) { - syslog(LOG_ERR, "cannot bind udp: %m"); - exit(1); - } - if ((xprt = svctcp_create(sock, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE)) - == (SVCXPRT *)NULL) { - syslog(LOG_ERR, "couldn't do tcp_create"); - exit(1); - } - /* make an entry for ourself */ - pml = (struct pmaplist *)malloc((u_int)sizeof(struct pmaplist)); - pml->pml_map.pm_prog = PMAPPROG; - pml->pml_map.pm_vers = PMAPVERS; - pml->pml_map.pm_prot = IPPROTO_TCP; - pml->pml_map.pm_port = PMAPPORT; - pml->pml_next = pmaplist; - pmaplist = pml; - - (void)svc_register(xprt, PMAPPROG, PMAPVERS, reg_service, FALSE); - - /* initialize "network.nidb" timer */ - gettimeofday(&last_network_stat, NULL); - - (void)signal(SIGCHLD, reap); - portmap_svc_run(); - syslog(LOG_ERR, "run_svc returned unexpectedly"); - abort(); -} - -#ifndef lint -/* need to override perror calls in rpc library */ -__private_extern__ -void -perror(what) - const char *what; -{ - - syslog(LOG_ERR, "%s: %m", what); -} -#endif - -static struct pmaplist * -find_service(prog, vers, prot) - u_long prog, vers, prot; -{ - register struct pmaplist *hit = NULL; - register struct pmaplist *pml; - - for (pml = pmaplist; pml != NULL; pml = pml->pml_next) { - if ((pml->pml_map.pm_prog != prog) || - (pml->pml_map.pm_prot != prot)) - continue; - hit = pml; - if (pml->pml_map.pm_vers == vers) - break; - } - return (hit); -} - -/* - * 1 OK, 0 not - */ -void -reg_service(rqstp, xprt) - struct svc_req *rqstp; - SVCXPRT *xprt; -{ - struct pmap reg; - struct pmaplist *pml, *prevpml, *fnd; - int ans, port; - caddr_t t; - - if (debugging) - (void) fprintf(stderr, "server: about do a switch\n"); - switch (rqstp->rq_proc) { - - case PMAPPROC_NULL: - /* - * Null proc call - */ - if (!svc_sendreply(xprt, xdr_void, (caddr_t)0) && debugging) { - abort(); - } - break; - - case PMAPPROC_SET: - /* - * Set a program,version to port mapping - */ - if (!svc_getargs(xprt, xdr_pmap, ®)) - svcerr_decode(xprt); - else { - /* - * check to see if already used - * find_service returns a hit even if - * the versions don't match, so check for it - */ - fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot); - if (fnd && fnd->pml_map.pm_vers == reg.pm_vers) { - if (fnd->pml_map.pm_port == reg.pm_port) { - ans = 1; - goto done; - } - else { - ans = 0; - goto done; - } - } else { - /* - * add to END of list - */ - pml = (struct pmaplist *) - malloc((u_int)sizeof(struct pmaplist)); - pml->pml_map = reg; - pml->pml_next = 0; - if (pmaplist == 0) { - pmaplist = pml; - } else { - for (fnd= pmaplist; fnd->pml_next != 0; - fnd = fnd->pml_next); - fnd->pml_next = pml; - } - ans = 1; - } - done: - if ((!svc_sendreply(xprt, xdr_long, (caddr_t)&ans)) && - debugging) { - (void) fprintf(stderr, "svc_sendreply\n"); - abort(); - } - } - break; - - case PMAPPROC_UNSET: - /* - * Remove a program,version to port mapping. - */ - if (!svc_getargs(xprt, xdr_pmap, ®)) - svcerr_decode(xprt); - else { - ans = 0; - for (prevpml = NULL, pml = pmaplist; pml != NULL; ) { - if ((pml->pml_map.pm_prog != reg.pm_prog) || - (pml->pml_map.pm_vers != reg.pm_vers)) { - /* both pml & prevpml move forwards */ - prevpml = pml; - pml = pml->pml_next; - continue; - } - /* found it; pml moves forward, prevpml stays */ - ans = 1; - t = (caddr_t)pml; - pml = pml->pml_next; - if (prevpml == NULL) - pmaplist = pml; - else - prevpml->pml_next = pml; - free(t); - } - if ((!svc_sendreply(xprt, xdr_long, (caddr_t)&ans)) && - debugging) { - (void) fprintf(stderr, "svc_sendreply\n"); - abort(); - } - } - break; - - case PMAPPROC_GETPORT: - /* - * Lookup the mapping for a program,version and return its port - */ - if (!svc_getargs(xprt, xdr_pmap, ®)) - svcerr_decode(xprt); - else { - fnd = find_service(reg.pm_prog, reg.pm_vers, reg.pm_prot); - if (fnd) - port = fnd->pml_map.pm_port; - else - port = 0; - if ((!svc_sendreply(xprt, xdr_long, (caddr_t)&port)) && - debugging) { - (void) fprintf(stderr, "svc_sendreply\n"); - abort(); - } - } - break; - - case PMAPPROC_DUMP: - /* - * Return the current set of mapped program,version - */ - if (!svc_getargs(xprt, xdr_void, NULL)) - svcerr_decode(xprt); - else { - if ((!svc_sendreply(xprt, xdr_pmaplist, - (caddr_t)&pmaplist)) && debugging) { - (void) fprintf(stderr, "svc_sendreply\n"); - abort(); - } - } - break; - - case PMAPPROC_CALLIT: - /* - * Calls a procedure on the local machine. If the requested - * procedure is not registered this procedure does not return - * error information!! - * This procedure is only supported on rpc/udp and calls via - * rpc/udp. It passes null authentication parameters. - */ - callit(rqstp, xprt); - break; - - default: - svcerr_noproc(xprt); - break; - } -} - - -/* - * Stuff for the rmtcall service - */ -#define ARGSIZE 9000 - -struct encap_parms { - u_long arglen; - char *args; -}; - -static bool_t -xdr_encap_parms(xdrs, epp) - XDR *xdrs; - struct encap_parms *epp; -{ - return (xdr_bytes(xdrs, &(epp->args), (int *)&(epp->arglen), ARGSIZE)); -} - -struct rmtcallargs { - u_long rmt_prog; - u_long rmt_vers; - u_long rmt_port; - u_long rmt_proc; - struct encap_parms rmt_args; -}; - -static bool_t -xdr_rmtcall_args(xdrs, cap) - register XDR *xdrs; - register struct rmtcallargs *cap; -{ - - /* does not get a port number */ - if (xdr_u_long(xdrs, &(cap->rmt_prog)) && - xdr_u_long(xdrs, &(cap->rmt_vers)) && - xdr_u_long(xdrs, &(cap->rmt_proc))) { - return (xdr_encap_parms(xdrs, &(cap->rmt_args))); - } - return (FALSE); -} - -static bool_t -xdr_rmtcall_result(xdrs, cap) - register XDR *xdrs; - register struct rmtcallargs *cap; -{ - if (xdr_u_long(xdrs, &(cap->rmt_port))) - return (xdr_encap_parms(xdrs, &(cap->rmt_args))); - return (FALSE); -} - -/* - * only worries about the struct encap_parms part of struct rmtcallargs. - * The arglen must already be set!! - */ -static bool_t -xdr_opaque_parms(xdrs, cap) - XDR *xdrs; - struct rmtcallargs *cap; -{ - - return (xdr_opaque(xdrs, cap->rmt_args.args, cap->rmt_args.arglen)); -} - -/* - * This routine finds and sets the length of incoming opaque paraters - * and then calls xdr_opaque_parms. - */ -static bool_t -xdr_len_opaque_parms(xdrs, cap) - register XDR *xdrs; - struct rmtcallargs *cap; -{ - register u_int beginpos, lowpos, highpos, currpos, pos; - - beginpos = lowpos = pos = xdr_getpos(xdrs); - highpos = lowpos + ARGSIZE; - while ((int)(highpos - lowpos) >= 0) { - currpos = (lowpos + highpos) / 2; - if (xdr_setpos(xdrs, currpos)) { - pos = currpos; - lowpos = currpos + 1; - } else { - highpos = currpos - 1; - } - } - xdr_setpos(xdrs, beginpos); - cap->rmt_args.arglen = pos - beginpos; - return (xdr_opaque_parms(xdrs, cap)); -} - -/* - * Call a remote procedure service - * This procedure is very quiet when things go wrong. - * The proc is written to support broadcast rpc. In the broadcast case, - * a machine should shut-up instead of complain, less the requestor be - * overrun with complaints at the expense of not hearing a valid reply ... - * - * This now forks so that the program & process that it calls can call - * back to the portmapper. - */ -static void -callit(rqstp, xprt) - struct svc_req *rqstp; - SVCXPRT *xprt; -{ - struct rmtcallargs a; - struct pmaplist *pml; - u_short port; - struct sockaddr_in me; - int pid, so = -1; - CLIENT *client; - struct authunix_parms *au = (struct authunix_parms *)rqstp->rq_clntcred; - struct timeval timeout; - char buf[ARGSIZE]; - char tag[MAXPATHLEN]; - int off, taglen; - unsigned int delta; - struct stat sb; - struct timeval now; - - timeout.tv_sec = 5; - timeout.tv_usec = 0; - a.rmt_args.args = buf; - if (!svc_getargs(xprt, xdr_rmtcall_args, &a)) - return; - - /* - * Drop NIBIND_BIND calls for the parent tag "network" if the database - * doesn't exist. This prevents excessive fork() calls. - */ - if ((have_tag_network == 0) && (a.rmt_prog == NIBIND_PROG) && (a.rmt_proc == NIBIND_BIND)) - { - /* Skip sender address and child tag */ - memmove(&taglen, a.rmt_args.args + 4, 4); - taglen = ntohl(taglen); - off = 8 + (((taglen + 3) / 4) * 4); - - /* Get parent tag */ - memmove(&taglen, a.rmt_args.args + off, 4); - taglen = ntohl(taglen); - if (taglen >= MAXPATHLEN) return; - - off += 4; - memmove(tag, a.rmt_args.args + off, taglen); - tag[taglen] = '\0'; - - /* - * If there was no network.nidb a few seconds ago, drop the requset. - */ - if (!strcmp(tag, NETINFO_TAG_NETWORK)) - { - gettimeofday(&now, NULL); - delta = now.tv_sec - last_network_stat.tv_sec; - if (delta < NETINFO_STAT_LATENCY) return; - - if (stat(NETINFO_NETWORK_DIR_PATH, &sb) < 0) - { - last_network_stat = now; - return; - } - - have_tag_network = 1; - } - } - - if ((pml = find_service(a.rmt_prog, a.rmt_vers, - (u_long)IPPROTO_UDP)) == NULL) - return; - /* - * fork a child to do the work. Parent immediately returns. - * Child exits upon completion. - */ - if ((pid = fork()) != 0) { - if (pid < 0) - syslog(LOG_ERR, "CALLIT (prog %lu): fork: %m", - a.rmt_prog); - return; - } - port = pml->pml_map.pm_port; - get_myaddress(&me); - me.sin_port = htons(port); - client = clntudp_create(&me, a.rmt_prog, a.rmt_vers, timeout, &so); - if (client != (CLIENT *)NULL) { - if (rqstp->rq_cred.oa_flavor == AUTH_UNIX) { - client->cl_auth = authunix_create(au->aup_machname, - au->aup_uid, au->aup_gid, au->aup_len, au->aup_gids); - } - a.rmt_port = (u_long)port; - if (clnt_call(client, a.rmt_proc, xdr_opaque_parms, &a, - xdr_len_opaque_parms, &a, timeout) == RPC_SUCCESS) { - svc_sendreply(xprt, xdr_rmtcall_result, (caddr_t)&a); - } - AUTH_DESTROY(client->cl_auth); - clnt_destroy(client); - } - (void)close(so); - exit(0); -} - -void -reap() -{ - while (wait3((int *)NULL, WNOHANG, (struct rusage *)NULL) > 0); -} diff --git a/rwhod.tproj/rwhod.c b/rwhod.tproj/rwhod.c index 6094340..cbff644 100644 --- a/rwhod.tproj/rwhod.c +++ b/rwhod.tproj/rwhod.c @@ -75,6 +75,7 @@ static char sccsid[] = "@(#)rwhod.c 8.1 (Berkeley) 6/6/93"; #include #include #include +#include #include #include @@ -207,17 +208,23 @@ main(argc, argv) continue; } if (from.sin_port != sp->s_port) { - syslog(LOG_WARNING, "%d: bad from port", - ntohs(from.sin_port)); + syslog(LOG_WARNING, "%d: bad source port from %s", + ntohs(from.sin_port), inet_ntoa(from.sin_addr)); continue; } + if (cc < WHDRSIZE) { + syslog(LOG_WARNING, "short packet from %s", + inet_ntoa(from.sin_addr)); + continue; + } + if (wd.wd_vers != WHODVERSION) continue; if (wd.wd_type != WHODTYPE_STATUS) continue; if (!verify(wd.wd_hostname)) { - syslog(LOG_WARNING, "malformed host name from %x", - from.sin_addr); + syslog(LOG_WARNING, "malformed host name from %s", + inet_ntoa(from.sin_addr)); continue; } (void) sprintf(path, "whod.%s", wd.wd_hostname); diff --git a/tcpdump.tproj/Makefile b/tcpdump.tproj/Makefile deleted file mode 100644 index fb9c458..0000000 --- a/tcpdump.tproj/Makefile +++ /dev/null @@ -1,63 +0,0 @@ -# -# Generated by the NeXT Project Builder. -# -# NOTE: Do NOT change this file -- Project Builder maintains it. -# -# Put all of your customizations in files called Makefile.preamble -# and Makefile.postamble (both optional), and Makefile will include them. -# - -NAME = tcpdump - -PROJECTVERSION = 2.8 -PROJECT_TYPE = Tool - -HFILES = machdep.h addrtoname.h ntp.h nfsfh.h igrp.h interface.h\ - os-sunos4.h decnet.h ipx.h mib.h os-ultrix4.h netbios.h\ - bootp.h ospf.h llc.h nfs.h os-solaris2.h nfsv2.h fddi.h\ - gnuc.h ethertype.h extract.h appletalk.h - -CFILES = addrtoname.c bpf_dump.c machdep.c parsenfsfh.c print-arp.c\ - print-atalk.c print-atm.c print-bootp.c print-decnet.c\ - print-domain.c print-dvmrp.c print-egp.c print-ether.c\ - print-fddi.c print-gre.c print-icmp.c print-igrp.c print-ip.c\ - print-ipx.c print-isoclns.c print-krb.c print-llc.c\ - print-netbios.c print-nfs.c print-ntp.c print-null.c\ - print-ospf.c print-pim.c print-ppp.c print-rip.c print-skip.c\ - print-sl.c print-snmp.c print-sunrpc.c print-tcp.c\ - print-tftp.c print-udp.c print-wb.c strcasecmp.c tcpdump.c\ - util.c version.c vfprintf.c - -OTHERSRCS = Makefile.preamble Makefile Makefile.postamble - - -MAKEFILEDIR = $(MAKEFILEPATH)/pb_makefiles -CODE_GEN_STYLE = DYNAMIC -MAKEFILE = tool.make -NEXTSTEP_INSTALLDIR = /usr/sbin -LIBS = -lpcap -DEBUG_LIBS = $(LIBS) -PROF_LIBS = $(LIBS) - - -NEXTSTEP_PB_CFLAGS = -traditional-cpp - - -NEXTSTEP_BUILD_OUTPUT_DIR = /$(USER)/BUILD - -NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc -WINDOWS_OBJCPLUS_COMPILER = $(DEVDIR)/gcc -PDO_UNIX_OBJCPLUS_COMPILER = $(NEXTDEV_BIN)/gcc -NEXTSTEP_JAVA_COMPILER = /usr/bin/javac -WINDOWS_JAVA_COMPILER = $(JDKBINDIR)/javac.exe -PDO_UNIX_JAVA_COMPILER = $(NEXTDEV_BIN)/javac - -include $(MAKEFILEDIR)/platform.make - --include Makefile.preamble - -include $(MAKEFILEDIR)/$(MAKEFILE) - --include Makefile.postamble - --include Makefile.dependencies diff --git a/tcpdump.tproj/Makefile.postamble b/tcpdump.tproj/Makefile.postamble deleted file mode 100644 index 7823726..0000000 --- a/tcpdump.tproj/Makefile.postamble +++ /dev/null @@ -1,123 +0,0 @@ -############################################################################### -# NeXT Makefile.postamble -# Copyright 1996, NeXT Software, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project, sub-project, bundle, or -# palette. Each node in the project's tree of sub-projects and bundles -# should have it's own Makefile.preamble and Makefile.postamble. Additional -# rules (e.g., after_install) that are defined by the developer should be -# defined in this file. -# -############################################################################### -# -# Here are the variables exported by the common "app" makefiles that can be -# used in any customizations you make to the template below: -# -# PRODUCT_ROOT - Name of the directory to which resources are copied. -# OFILE_DIR - Directory into which .o object files are generated. -# (Note that this name is calculated based on the target -# architectures specified in Project Builder). -# DERIVED_SRC_DIR - Directory used for all other derived files -# ALL_CFLAGS - All the flags passed to the cc(1) driver for compilations -# -# NAME - name of application, bundle, subproject, palette, etc. -# LANGUAGE - langage in which the project is written (default "English") -# LOCAL_RESOURCES - localized resources (e.g. nib's, images) of project -# GLOBAL_RESOURCES - non-localized resources of project -# PROJECTVERSION - version of ProjectBuilder project (NS3.X = 1.1, NS4.0 = 2.0) -# ICONSECTIONS - Specifies icon sections when linking executable -# -# CLASSES - Class implementation files in project. -# HFILES - Header files in project. -# MFILES - Other Objective-C source files in project. -# CFILES - Other C source files in project. -# PSWFILES - .psw files in the project -# PSWMFILES - .pswm files in the project -# SUBPROJECTS - Subprojects of this project -# BUNDLES - Bundle subprojects of this project -# OTHERSRCS - Other miscellaneous sources of this project -# OTHERLINKED - Source files not matching a standard source extention -# -# LIBS - Libraries to link with when making app target -# DEBUG_LIBS - Libraries to link with when making debug target -# PROF_LIBS - Libraries to link with when making profile target -# OTHERLINKEDOFILES - Other relocatable files to (always) link in. -# -# APP_MAKEFILE_DIR - Directory in which to find generic set of Makefiles -# MAKEFILEDIR - Directory in which to find $(MAKEFILE) -# MAKEFILE - Top level mechanism Makefile (e.g., app.make, bundle.make) -# INSTALLDIR - Directory app will be installed into by 'install' target -# -############################################################################### - - -# Change defaults assumed by the standard makefiles here. Edit the -# following default values as appropriate. (Note that if no Makefile.postamble -# exists, these values will have defaults set in common.make). - -# Versioning of frameworks, libraries, bundles, and palettes: -#CURRENTLY_ACTIVE_VERSION = YES - # Set to "NO" to produce a compatibility binary -#DEPLOY_WITH_VERSION_NAME = A - # This should be incremented as your API changes. -#COMPATIBILITY_PROJECT_VERSION = 1 - # This should be incremented as your API grows. -#CURRENT_PROJECT_VERSION = 1 - # Defaults to using the "vers_string" hack. - -# Some compiler flags can be easily overridden here, but onlytake effect at -# the top-level: -#OPTIMIZATION_CFLAG = -O -#DEBUG_SYMBOLS_CFLAG = -g -#WARNING_CFLAGS = -Wmost -#DEBUG_BUILD_CFLAGS = -DDEBUG -#PROFILE_BUILD_CFLAGS = -pg -DPROFILE - -# This definition will suppress stripping of debug symbols when an executable -# is installed. By default it is YES. -# STRIP_ON_INSTALL = NO - -# Flags passed to yacc -#YFLAGS = -d - -# Library and Framework projects only: -# 1. If you want something other than the default .dylib name, override it here -#DYLIB_INSTALL_NAME = lib$(NAME).dylib - -# 2. If you want to change the -install_name flag from the absolute path to the development area, change it here. One good choice is the installation directory. Another one might be none at all. -#DYLIB_INSTALL_DIR = $(INSTALLDIR) - -# Ownership and permissions of files installed by 'install' target -#INSTALL_AS_USER = root - # User/group ownership -#INSTALL_AS_GROUP = wheel - # (probably want to set both of these) -#INSTALL_PERMISSIONS = - # If set, 'install' chmod's executable to this - -# Options to strip for various project types. Note: -S strips debugging symbols -# (executables can be stripped down further with -x or, if they load no bundles, with no -# options at all). -#APP_STRIP_OPTS = -S -#TOOL_STRIP_OPTS = -S -#LIBRARY_STRIP_OPTS = -S - # for .a archives -#DYNAMIC_STRIP_OPTS = -S - # for bundles and shared libraries -STRIPFLAGS = - -######################################################################### -# Put rules to extend the behavior of the standard Makefiles here. "Official" -# user-defined rules are: -# * before_install -# * after_install -# * after_installhdrs -# You should avoid redefining things like "install" or "app", as they are -# owned by the top-level Makefile API and no context has been set up for where -# derived files should go. -# -# Note: on MS Windows, executables, have an extension, so rules and dependencies -# for generated tools should use $(EXECUTABLE_EXT) on the end. diff --git a/tcpdump.tproj/Makefile.preamble b/tcpdump.tproj/Makefile.preamble deleted file mode 100644 index faec713..0000000 --- a/tcpdump.tproj/Makefile.preamble +++ /dev/null @@ -1,130 +0,0 @@ -############################################################################### -# NeXT Makefile.preamble -# Copyright 1996, NeXT Software, Inc. -# -# This Makefile is used for configuring the standard app makefiles associated -# with ProjectBuilder. -# -# Use this template to set attributes for a project. Each node in a project -# tree of sub-projects, tools, etc. should have its own Makefile.preamble and -# Makefile.postamble. -# -############################################################################### -## Configure the flags passed to $(CC) here. These flags will also be -## inherited by all nested sub-projects and bundles. Put your -I, -D, -U, and -## -L flags in ProjectBuilder's Build Options inspector if at all possible. -## To change the default flags that get passed to ${CC} -## (e.g. change -O to -O2), see Makefile.postamble. - -# Flags passed to compiler (in addition to -g, -O, etc) -OTHER_CFLAGS =-DRETSIGTYPE=void -# Flags passed to ld (in addition to -ObjC, etc.) -OTHER_LDFLAGS = -# Flags passed to libtool when building libraries -OTHER_LIBTOOL_FLAGS = -# For ordering named sections on NEXTSTEP (see ld(1)) -SECTORDER_FLAGS = - -# If you do not want any headers exported before compilations begin, -# uncomment the following line. This can be a big time saver. -#SKIP_EXPORTING_HEADERS = YES - -# Stuff related to exporting headers from this project that isn't already -# handled by PB. -OTHER_PUBLIC_HEADERS = -OTHER_PROJECT_HEADERS = -OTHER_PRIVATE_HEADERS = - -# Set these two macros if you want a precomp to be built as part of -# installation. The cc -precomp will be run in the public header directory -# on the specified public header files with the specified additional flags. -PUBLIC_PRECOMPILED_HEADERS = -PUBLIC_PRECOMPILED_HEADERS_CFLAGS = - -# Set this for library projects if you want to publish header files. If your -# app or tool project exports headers Don't -# include $(DSTROOT); this is added for you automatically. -PUBLIC_HEADER_DIR = -PRIVATE_HEADER_DIR = - -# If, in a subproject, you want to append to the parent's PUBLIC_HEADER_DIR# -# (say, to add a subdirectory like "/sys"), you can use: -PUBLIC_HEADER_DIR_SUFFIX = -PRIVATE_HEADER_DIR_SUFFIX = - -# Set this for dynamic library projects on platforms where code which references -# a dynamic library must link against an import library (i.e., Windows NT) -# Don't include $(DSTROOT); this is added for you automatically. -IMPORT_LIBRARY_DIR = - -# Additional (non-localized) resources for this project, which can be generated -OTHER_RESOURCES = - -# Uncomment this to produce a static archive-style (.a) library -#LIBRARY_STYLE = STATIC - -# Set this to YES if you don't want a final libtool call for a library/framework. -BUILD_OFILES_LIST_ONLY = - -# Additional relocatables to be linked into this project -OTHER_OFILES = -# Additional libraries to link against -OTHER_LIBS = -# To include a version string, project source must exist in a directory named -# $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) - -## Configure how things get built here. Additional dependencies, source files, -## derived files, and build order should be specified here. - -# Other dependencies of this project -OTHER_PRODUCT_DEPENDS = -# Built *before* building subprojects/bundles -OTHER_INITIAL_TARGETS = -# Other source files maintained by .pre/postamble -OTHER_SOURCEFILES = -# Additional files to be removed by `make clean' -OTHER_GARBAGE = - -# Targets to build before installation -OTHER_INSTALL_DEPENDS = - -# More obscure flags you might want to set for pswrap, yacc, lex, etc. -PSWFLAGS = -YFLAGS = -LFLAGS = - -## Delete this line if you want fast and loose cleans that will not remove -## things like precomps and user-defined OTHER_GARBAGE in subprojects. -CLEAN_ALL_SUBPROJECTS = YES - -## Add more obscure source files here to cause them to be automatically -## processed by the appropriate tool. Note that these files should also be -## added to "Supporting Files" in ProjectBuilder. The desired .o files that -## result from these files should also be added to OTHER_OFILES above so they -## will be linked in. - -# .msg files that should have msgwrap run on them -MSGFILES = -# .defs files that should have mig run on them -DEFSFILES = -# .mig files (no .defs files) that should have mig run on them -MIGFILES = -# .x files that should have rpcgen run on them -RPCFILES = - -## Add additional Help directories here (add them to the project as "Other -## Resources" in Project Builder) so that they will be compressed into .store -## files and copied into the app wrapper. If the help directories themselves -## need to also be in the app wrapper, then a cp command will need to be added -## in an after_install target. -OTHER_HELP_DIRS = - -# After you have saved your project using the 4.0 PB, you will automatically -# start using the makefiles in $(SYSTEM_DEVELOPER_DIR)/Makefiles/project. If you should -# need to revert back to the old 3.3 Makefile behavior, override MAKEFILEDIR to -# be $(SYSTEM_DEVELOPER_DIR)/Makefiles/app. - -# Don't add more rules here unless you want the first one to be the default -# target for make! Put all your targets in Makefile.postamble. - diff --git a/tcpdump.tproj/PB.project b/tcpdump.tproj/PB.project deleted file mode 100644 index 143e686..0000000 --- a/tcpdump.tproj/PB.project +++ /dev/null @@ -1,98 +0,0 @@ -{ - DYNAMIC_CODE_GEN = YES; - FILESTABLE = { - CLASSES = (); - FRAMEWORKS = (); - H_FILES = ( - machdep.h, - addrtoname.h, - ntp.h, - nfsfh.h, - igrp.h, - interface.h, - "os-sunos4.h", - decnet.h, - ipx.h, - mib.h, - "os-ultrix4.h", - netbios.h, - bootp.h, - ospf.h, - llc.h, - nfs.h, - "os-solaris2.h", - nfsv2.h, - fddi.h, - gnuc.h, - ethertype.h, - extract.h, - appletalk.h - ); - OTHER_LIBS = (pcap); - OTHER_LINKED = ( - addrtoname.c, - bpf_dump.c, - machdep.c, - parsenfsfh.c, - "print-arp.c", - "print-atalk.c", - "print-atm.c", - "print-bootp.c", - "print-decnet.c", - "print-domain.c", - "print-dvmrp.c", - "print-egp.c", - "print-ether.c", - "print-fddi.c", - "print-gre.c", - "print-icmp.c", - "print-igrp.c", - "print-ip.c", - "print-ipx.c", - "print-isoclns.c", - "print-krb.c", - "print-llc.c", - "print-netbios.c", - "print-nfs.c", - "print-ntp.c", - "print-null.c", - "print-ospf.c", - "print-pim.c", - "print-ppp.c", - "print-rip.c", - "print-skip.c", - "print-sl.c", - "print-snmp.c", - "print-sunrpc.c", - "print-tcp.c", - "print-tftp.c", - "print-udp.c", - "print-wb.c", - strcasecmp.c, - tcpdump.c, - util.c, - version.c, - vfprintf.c - ); - OTHER_SOURCES = (Makefile.preamble, Makefile, Makefile.postamble); - SUBPROJECTS = (); - }; - LANGUAGE = English; - LOCALIZABLE_FILES = {}; - MAKEFILEDIR = "$(MAKEFILEPATH)/pb_makefiles"; - NEXTSTEP_BUILDDIR = "/$(USER)/BUILD"; - NEXTSTEP_BUILDTOOL = /bin/gnumake; - NEXTSTEP_COMPILEROPTIONS = "-traditional-cpp"; - NEXTSTEP_INSTALLDIR = /usr/sbin; - NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; - PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; - PDO_UNIX_JAVA_COMPILER = "$(NEXTDEV_BIN)/javac"; - PDO_UNIX_OBJCPLUS_COMPILER = "$(NEXTDEV_BIN)/gcc"; - PROJECTNAME = tcpdump; - PROJECTTYPE = Tool; - PROJECTVERSION = 2.8; - WINDOWS_BUILDTOOL = $NEXT_ROOT/Developer/Executables/make; - WINDOWS_JAVA_COMPILER = "$(JDKBINDIR)/javac.exe"; - WINDOWS_OBJCPLUS_COMPILER = "$(DEVDIR)/gcc"; -} diff --git a/tcpdump.tproj/addrtoname.c b/tcpdump.tproj/addrtoname.c deleted file mode 100644 index f940348..0000000 --- a/tcpdump.tproj/addrtoname.c +++ /dev/null @@ -1,779 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1992, 1993, 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. - * - * Internet, ethernet, port, and protocol string to address - * and address to string conversion routines - */ -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/addrtoname.c,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "llc.h" - -/* Forwards */ -static RETSIGTYPE nohostname(int); - -/* - * hash tables for whatever-to-name translations - */ - -#define HASHNAMESIZE 4096 - -struct hnamemem { - u_int32_t addr; - char *name; - struct hnamemem *nxt; -}; - -struct hnamemem hnametable[HASHNAMESIZE]; -struct hnamemem tporttable[HASHNAMESIZE]; -struct hnamemem uporttable[HASHNAMESIZE]; -struct hnamemem eprototable[HASHNAMESIZE]; -struct hnamemem dnaddrtable[HASHNAMESIZE]; -struct hnamemem llcsaptable[HASHNAMESIZE]; - -struct enamemem { - u_short e_addr0; - u_short e_addr1; - u_short e_addr2; - char *e_name; - u_char *e_nsap; /* used only for nsaptable[] */ - struct enamemem *e_nxt; -}; - -struct enamemem enametable[HASHNAMESIZE]; -struct enamemem nsaptable[HASHNAMESIZE]; - -struct protoidmem { - u_int32_t p_oui; - u_short p_proto; - char *p_name; - struct protoidmem *p_nxt; -}; - -struct protoidmem protoidtable[HASHNAMESIZE]; - -/* - * A faster replacement for inet_ntoa(). - */ -char * -intoa(u_int32_t addr) -{ - register char *cp; - register u_int byte; - register int n; - static char buf[sizeof(".xxx.xxx.xxx.xxx")]; - - NTOHL(addr); - cp = &buf[sizeof buf]; - *--cp = '\0'; - - n = 4; - do { - byte = addr & 0xff; - *--cp = byte % 10 + '0'; - byte /= 10; - if (byte > 0) { - *--cp = byte % 10 + '0'; - byte /= 10; - if (byte > 0) - *--cp = byte + '0'; - } - *--cp = '.'; - addr >>= 8; - } while (--n > 0); - - return cp + 1; -} - -static u_int32_t f_netmask; -static u_int32_t f_localnet; -static u_int32_t netmask; - -/* - * "getname" is written in this atrocious way to make sure we don't - * wait forever while trying to get hostnames from yp. - */ -#include - -jmp_buf getname_env; - -static RETSIGTYPE -nohostname(int signo) -{ - longjmp(getname_env, 1); -} - -/* - * Return a name for the IP address pointed to by ap. This address - * is assumed to be in network byte order. - */ -char * -getname(const u_char *ap) -{ - register struct hostent *hp; - u_int32_t addr; - static struct hnamemem *p; /* static for longjmp() */ - -#ifndef LBL_ALIGN - addr = *(const u_int32_t *)ap; -#else - /* - * Extract 32 bits in network order, dealing with alignment. - */ - switch ((long)ap & 3) { - - case 0: - addr = *(u_int32_t *)ap; - break; - - case 2: -#ifdef WORDS_BIGENDIAN - addr = ((u_int32_t)*(u_short *)ap << 16) | - (u_int32_t)*(u_short *)(ap + 2); -#else - addr = ((u_int32_t)*(u_short *)(ap + 2) << 16) | - (u_int32_t)*(u_short *)ap; -#endif - break; - - default: -#ifdef WORDS_BIGENDIAN - addr = ((u_int32_t)ap[0] << 24) | - ((u_int32_t)ap[1] << 16) | - ((u_int32_t)ap[2] << 8) | - (u_int32_t)ap[3]; -#else - addr = ((u_int32_t)ap[3] << 24) | - ((u_int32_t)ap[2] << 16) | - ((u_int32_t)ap[1] << 8) | - (u_int32_t)ap[0]; -#endif - break; - } -#endif - p = &hnametable[addr & (HASHNAMESIZE-1)]; - for (; p->nxt; p = p->nxt) { - if (p->addr == addr) - return (p->name); - } - p->addr = addr; - p->nxt = newhnamemem(); - - /* - * Only print names when: - * (1) -n was not given. - * (2) Address is foreign and -f was given. If -f was not - * present, f_netmask and f_local are 0 and the second - * test will succeed. - * (3) The host portion is not 0 (i.e., a network address). - * (4) The host portion is not broadcast. - */ - if (!nflag && (addr & f_netmask) == f_localnet - && (addr &~ netmask) != 0 && (addr | netmask) != 0xffffffff) { - if (!setjmp(getname_env)) { - (void)signal(SIGALRM, nohostname); - (void)alarm(20); - hp = gethostbyaddr((char *)&addr, 4, AF_INET); - (void)alarm(0); - if (hp) { - char *dotp; - - p->name = savestr(hp->h_name); - if (Nflag) { - /* Remove domain qualifications */ - dotp = strchr(p->name, '.'); - if (dotp) - *dotp = '\0'; - } - return (p->name); - } - } - } - p->name = savestr(intoa(addr)); - return (p->name); -} - -static char hex[] = "0123456789abcdef"; - - -/* Find the hash node that corresponds the ether address 'ep' */ - -static inline struct enamemem * -lookup_emem(const u_char *ep) -{ - register u_int i, j, k; - struct enamemem *tp; - - k = (ep[0] << 8) | ep[1]; - j = (ep[2] << 8) | ep[3]; - i = (ep[4] << 8) | ep[5]; - - tp = &enametable[(i ^ j) & (HASHNAMESIZE-1)]; - while (tp->e_nxt) - if (tp->e_addr0 == i && - tp->e_addr1 == j && - tp->e_addr2 == k) - return tp; - else - tp = tp->e_nxt; - tp->e_addr0 = i; - tp->e_addr1 = j; - tp->e_addr2 = k; - tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); - if (tp->e_nxt == NULL) - error("lookup_emem: calloc"); - - return tp; -} - -/* Find the hash node that corresponds the NSAP 'nsap' */ - -static inline struct enamemem * -lookup_nsap(register const u_char *nsap) -{ - register u_int i, j, k; - int nlen = *nsap; - struct enamemem *tp; - const u_char *ensap = nsap + nlen - 6; - - if (nlen > 6) { - k = (ensap[0] << 8) | ensap[1]; - j = (ensap[2] << 8) | ensap[3]; - i = (ensap[4] << 8) | ensap[5]; - } - else - i = j = k = 0; - - tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)]; - while (tp->e_nxt) - if (tp->e_addr0 == i && - tp->e_addr1 == j && - tp->e_addr2 == k && - tp->e_nsap[0] == nlen && - memcmp((char *)&(nsap[1]), - (char *)&(tp->e_nsap[1]), nlen) == 0) - return tp; - else - tp = tp->e_nxt; - tp->e_addr0 = i; - tp->e_addr1 = j; - tp->e_addr2 = k; - tp->e_nsap = (u_char *)malloc(nlen + 1); - if (tp->e_nsap == NULL) - error("lookup_nsap: malloc"); - memcpy(tp->e_nsap, nsap, nlen + 1); - tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp)); - if (tp->e_nxt == NULL) - error("lookup_nsap: calloc"); - - return tp; -} - -/* Find the hash node that corresponds the protoid 'pi'. */ - -static inline struct protoidmem * -lookup_protoid(const u_char *pi) -{ - register u_int i, j; - struct protoidmem *tp; - - /* 5 octets won't be aligned */ - i = (((pi[0] << 8) + pi[1]) << 8) + pi[2]; - j = (pi[3] << 8) + pi[4]; - /* XXX should be endian-insensitive, but do big-endian testing XXX */ - - tp = &protoidtable[(i ^ j) & (HASHNAMESIZE-1)]; - while (tp->p_nxt) - if (tp->p_oui == i && tp->p_proto == j) - return tp; - else - tp = tp->p_nxt; - tp->p_oui = i; - tp->p_proto = j; - tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp)); - if (tp->p_nxt == NULL) - error("lookup_protoid: calloc"); - - return tp; -} - -char * -etheraddr_string(register const u_char *ep) -{ - register u_int i, j; - register char *cp; - register struct enamemem *tp; - char buf[sizeof("00:00:00:00:00:00")]; - - tp = lookup_emem(ep); - if (tp->e_name) - return (tp->e_name); -#ifdef HAVE_ETHER_NTOHOST - if (!nflag) { - char buf[128]; - if (ether_ntohost(buf, (struct ether_addr *)ep) == 0) { - tp->e_name = savestr(buf); - return (tp->e_name); - } - } -#endif - cp = buf; - if ((j = *ep >> 4) != 0) - *cp++ = hex[j]; - *cp++ = hex[*ep++ & 0xf]; - for (i = 5; (int)--i >= 0;) { - *cp++ = ':'; - if ((j = *ep >> 4) != 0) - *cp++ = hex[j]; - *cp++ = hex[*ep++ & 0xf]; - } - *cp = '\0'; - tp->e_name = savestr(buf); - return (tp->e_name); -} - -char * -etherproto_string(u_short port) -{ - register char *cp; - register struct hnamemem *tp; - register u_int32_t i = port; - char buf[sizeof("0000")]; - - for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) - if (tp->addr == i) - return (tp->name); - - tp->addr = i; - tp->nxt = newhnamemem(); - - cp = buf; - NTOHS(port); - *cp++ = hex[port >> 12 & 0xf]; - *cp++ = hex[port >> 8 & 0xf]; - *cp++ = hex[port >> 4 & 0xf]; - *cp++ = hex[port & 0xf]; - *cp++ = '\0'; - tp->name = savestr(buf); - return (tp->name); -} - -char * -protoid_string(register const u_char *pi) -{ - register u_int i, j; - register char *cp; - register struct protoidmem *tp; - char buf[sizeof("00:00:00:00:00")]; - - tp = lookup_protoid(pi); - if (tp->p_name) - return tp->p_name; - - cp = buf; - if ((j = *pi >> 4) != 0) - *cp++ = hex[j]; - *cp++ = hex[*pi++ & 0xf]; - for (i = 4; (int)--i >= 0;) { - *cp++ = ':'; - if ((j = *pi >> 4) != 0) - *cp++ = hex[j]; - *cp++ = hex[*pi++ & 0xf]; - } - *cp = '\0'; - tp->p_name = savestr(buf); - return (tp->p_name); -} - -char * -llcsap_string(u_char sap) -{ - register char *cp; - register struct hnamemem *tp; - register u_int32_t i = sap; - char buf[sizeof("sap 00")]; - - for (tp = &llcsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) - if (tp->addr == i) - return (tp->name); - - tp->addr = i; - tp->nxt = newhnamemem(); - - cp = buf; - (void)strcpy(cp, "sap "); - cp += strlen(cp); - *cp++ = hex[sap >> 4 & 0xf]; - *cp++ = hex[sap & 0xf]; - *cp++ = '\0'; - tp->name = savestr(buf); - return (tp->name); -} - -char * -isonsap_string(const u_char *nsap) -{ - register u_int i, nlen = nsap[0]; - register char *cp; - register struct enamemem *tp; - - tp = lookup_nsap(nsap); - if (tp->e_name) - return tp->e_name; - - tp->e_name = cp = (char *)malloc(nlen * 2 + 2); - if (cp == NULL) - error("isonsap_string: malloc"); - - nsap++; - *cp++ = '/'; - for (i = nlen; (int)--i >= 0;) { - *cp++ = hex[*nsap >> 4]; - *cp++ = hex[*nsap++ & 0xf]; - } - *cp = '\0'; - return (tp->e_name); -} - -char * -tcpport_string(u_short port) -{ - register struct hnamemem *tp; - register u_int32_t i = port; - char buf[sizeof("00000")]; - - for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) - if (tp->addr == i) - return (tp->name); - - tp->addr = i; - tp->nxt = newhnamemem(); - - (void)sprintf(buf, "%u", i); - tp->name = savestr(buf); - return (tp->name); -} - -char * -udpport_string(register u_short port) -{ - register struct hnamemem *tp; - register u_int32_t i = port; - char buf[sizeof("00000")]; - - for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) - if (tp->addr == i) - return (tp->name); - - tp->addr = i; - tp->nxt = newhnamemem(); - - (void)sprintf(buf, "%u", i); - tp->name = savestr(buf); - return (tp->name); -} - -static void -init_servarray(void) -{ - struct servent *sv; - register struct hnamemem *table; - register int i; - char buf[sizeof("0000000000")]; - - while ((sv = getservent()) != NULL) { - int port = ntohs(sv->s_port); - i = port & (HASHNAMESIZE-1); - if (strcmp(sv->s_proto, "tcp") == 0) - table = &tporttable[i]; - else if (strcmp(sv->s_proto, "udp") == 0) - table = &uporttable[i]; - else - continue; - - while (table->name) - table = table->nxt; - if (nflag) { - (void)sprintf(buf, "%d", port); - table->name = savestr(buf); - } else - table->name = savestr(sv->s_name); - table->addr = port; - table->nxt = newhnamemem(); - } - endservent(); -} - -/*XXX from libbpfc.a */ -extern struct eproto { - char *s; - u_short p; -} eproto_db[]; - -static void -init_eprotoarray(void) -{ - register int i; - register struct hnamemem *table; - - for (i = 0; eproto_db[i].s; i++) { - int j = ntohs(eproto_db[i].p) & (HASHNAMESIZE-1); - table = &eprototable[j]; - while (table->name) - table = table->nxt; - table->name = eproto_db[i].s; - table->addr = ntohs(eproto_db[i].p); - table->nxt = newhnamemem(); - } -} - -/* - * SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet - * types. - */ -static void -init_protoidarray(void) -{ - register int i; - register struct protoidmem *tp; - u_char protoid[5]; - - protoid[0] = 0; - protoid[1] = 0; - protoid[2] = 0; - for (i = 0; eproto_db[i].s; i++) { - u_short etype = htons(eproto_db[i].p); - - memcpy((char *)&protoid[3], (char *)&etype, 2); - tp = lookup_protoid(protoid); - tp->p_name = savestr(eproto_db[i].s); - } -} - -static struct etherlist { - u_char addr[6]; - char *name; -} etherlist[] = { - {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" }, - {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL } -}; - -/* - * Initialize the ethers hash table. We take two different approaches - * depending on whether or not the system provides the ethers name - * service. If it does, we just wire in a few names at startup, - * and etheraddr_string() fills in the table on demand. If it doesn't, - * then we suck in the entire /etc/ethers file at startup. The idea - * is that parsing the local file will be fast, but spinning through - * all the ethers entries via NIS & next_etherent might be very slow. - * - * XXX pcap_next_etherent doesn't belong in the pcap interface, but - * since the pcap module already does name-to-address translation, - * it's already does most of the work for the ethernet address-to-name - * translation, so we just pcap_next_etherent as a convenience. - */ -static void -init_etherarray(void) -{ - register struct etherlist *el; - register struct enamemem *tp; -#ifdef HAVE_ETHER_NTOHOST - char name[256]; -#else - register struct pcap_etherent *ep; - register FILE *fp; - - /* Suck in entire ethers file */ - fp = fopen(PCAP_ETHERS_FILE, "r"); - if (fp != NULL) { - while ((ep = pcap_next_etherent(fp)) != NULL) { - tp = lookup_emem(ep->addr); - tp->e_name = savestr(ep->name); - } - (void)fclose(fp); - } -#endif - - /* Hardwire some ethernet names */ - for (el = etherlist; el->name != NULL; ++el) { - tp = lookup_emem(el->addr); - /* Don't override existing name */ - if (tp->e_name != NULL) - continue; - -#ifdef HAVE_ETHER_NTOHOST - /* Use yp/nis version of name if available */ - if (ether_ntohost(name, (struct ether_addr *)el->addr) == 0) { - tp->e_name = savestr(name); - continue; - } -#endif - tp->e_name = el->name; - } -} - -static struct tok llcsap_db[] = { - { LLCSAP_NULL, "null" }, - { LLCSAP_8021B_I, "802.1b-gsap" }, - { LLCSAP_8021B_G, "802.1b-isap" }, - { LLCSAP_IP, "ip-sap" }, - { LLCSAP_PROWAYNM, "proway-nm" }, - { LLCSAP_8021D, "802.1d" }, - { LLCSAP_RS511, "eia-rs511" }, - { LLCSAP_ISO8208, "x.25/llc2" }, - { LLCSAP_PROWAY, "proway" }, - { LLCSAP_ISONS, "iso-clns" }, - { LLCSAP_GLOBAL, "global" }, - { 0, NULL } -}; - -static void -init_llcsaparray(void) -{ - register int i; - register struct hnamemem *table; - - for (i = 0; llcsap_db[i].s != NULL; i++) { - table = &llcsaptable[llcsap_db[i].v]; - while (table->name) - table = table->nxt; - table->name = llcsap_db[i].s; - table->addr = llcsap_db[i].v; - table->nxt = newhnamemem(); - } -} - -/* - * Initialize the address to name translation machinery. We map all - * non-local IP addresses to numeric addresses if fflag is true (i.e., - * to prevent blocking on the nameserver). localnet is the IP address - * of the local network. mask is its subnet mask. - */ -void -init_addrtoname(int fflag, u_int32_t localnet, u_int32_t mask) -{ - netmask = mask; - if (fflag) { - f_localnet = localnet; - f_netmask = mask; - } - if (nflag) - /* - * Simplest way to suppress names. - */ - return; - - init_etherarray(); - init_servarray(); - init_eprotoarray(); - init_llcsaparray(); - init_protoidarray(); -} - -char * -dnaddr_string(u_short dnaddr) -{ - register struct hnamemem *tp; - - for (tp = &dnaddrtable[dnaddr & (HASHNAMESIZE-1)]; tp->nxt != 0; - tp = tp->nxt) - if (tp->addr == dnaddr) - return (tp->name); - - tp->addr = dnaddr; - tp->nxt = newhnamemem(); - if (nflag) - tp->name = dnnum_string(dnaddr); - else - tp->name = dnname_string(dnaddr); - - return(tp->name); -} - -/* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */ -struct hnamemem * -newhnamemem(void) -{ - register struct hnamemem *p; - static struct hnamemem *ptr = NULL; - static u_int num = 0; - - if (num <= 0) { - num = 64; - ptr = (struct hnamemem *)calloc(num, sizeof (*ptr)); - if (ptr == NULL) - error("newhnamemem: calloc"); - } - --num; - p = ptr++; - return (p); -} diff --git a/tcpdump.tproj/addrtoname.h b/tcpdump.tproj/addrtoname.h deleted file mode 100644 index c40b03f..0000000 --- a/tcpdump.tproj/addrtoname.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1992, 1993, 1994, 1995 - * 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: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/addrtoname.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) - */ - -/* Name to address translation routines. */ - -extern char *etheraddr_string(const u_char *); -extern char *etherproto_string(u_short); -extern char *tcpport_string(u_short); -extern char *udpport_string(u_short); -extern char *getname(const u_char *); -extern char *intoa(u_int32_t); - -extern void init_addrtoname(int, u_int32_t, u_int32_t); -extern struct hnamemem *newhnamemem(void); - -#define ipaddr_string(p) getname((const u_char *)(p)) diff --git a/tcpdump.tproj/appletalk.h b/tcpdump.tproj/appletalk.h deleted file mode 100644 index 49690e7..0000000 --- a/tcpdump.tproj/appletalk.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1993, 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. - * - * AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX). - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/appletalk.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) - */ - -struct LAP { - u_char dst; - u_char src; - u_char type; -}; -#define lapShortDDP 1 /* short DDP type */ -#define lapDDP 2 /* DDP type */ -#define lapKLAP 'K' /* Kinetics KLAP type */ - -/* Datagram Delivery Protocol */ - -struct atDDP { - u_short length; - u_short checksum; - u_short dstNet; - u_short srcNet; - u_char dstNode; - u_char srcNode; - u_char dstSkt; - u_char srcSkt; - u_char type; -}; - -struct atShortDDP { - u_short length; - u_char dstSkt; - u_char srcSkt; - u_char type; -}; - -#define ddpMaxWKS 0x7F -#define ddpMaxData 586 -#define ddpLengthMask 0x3FF -#define ddpHopShift 10 -#define ddpSize 13 /* size of DDP header (avoid struct padding) */ -#define ddpSSize 5 -#define ddpWKS 128 /* boundary of DDP well known sockets */ -#define ddpRTMP 1 /* RTMP type */ -#define ddpRTMPrequest 5 /* RTMP request type */ -#define ddpNBP 2 /* NBP type */ -#define ddpATP 3 /* ATP type */ -#define ddpECHO 4 /* ECHO type */ -#define ddpIP 22 /* IP type */ -#define ddpARP 23 /* ARP type */ -#define ddpKLAP 0x4b /* Kinetics KLAP type */ - - -/* AppleTalk Transaction Protocol */ - -struct atATP { - u_char control; - u_char bitmap; - u_short transID; - int32_t userData; -}; - -#define atpReqCode 0x40 -#define atpRspCode 0x80 -#define atpRelCode 0xC0 -#define atpXO 0x20 -#define atpEOM 0x10 -#define atpSTS 0x08 -#define atpFlagMask 0x3F -#define atpControlMask 0xF8 -#define atpMaxNum 8 -#define atpMaxData 578 - - -/* AppleTalk Echo Protocol */ - -struct atEcho { - u_char echoFunction; - u_char *echoData; -}; - -#define echoSkt 4 /* the echoer socket */ -#define echoSize 1 /* size of echo header */ -#define echoRequest 1 /* echo request */ -#define echoReply 2 /* echo request */ - - -/* Name Binding Protocol */ - -struct atNBP { - u_char control; - u_char id; -}; - -struct atNBPtuple { - u_short net; - u_char node; - u_char skt; - u_char enumerator; -}; - -#define nbpBrRq 0x10 -#define nbpLkUp 0x20 -#define nbpLkUpReply 0x30 - -#define nbpNIS 2 -#define nbpTupleMax 15 - -#define nbpHeaderSize 2 -#define nbpTupleSize 5 - -#define nbpSkt 2 /* NIS */ - - -/* Routing Table Maint. Protocol */ - -#define rtmpSkt 1 /* number of RTMP socket */ -#define rtmpSize 4 /* minimum size */ -#define rtmpTupleSize 3 - - -/* Zone Information Protocol */ - -struct zipHeader { - u_char command; - u_char netcount; -}; - -#define zipHeaderSize 2 -#define zipQuery 1 -#define zipReply 2 -#define zipTakedown 3 -#define zipBringup 4 -#define ddpZIP 6 -#define zipSkt 6 -#define GetMyZone 7 -#define GetZoneList 8 - -/* - * UDP port range used for ddp-in-udp encapsulation is 16512-16639 - * for client sockets (128-255) and 200-327 for server sockets - * (0-127). We also try to recognize the pre-April 88 server - * socket range of 768-895. - */ -#define atalk_port(p) \ - (((unsigned)((p) - 16512) < 128) || \ - ((unsigned)((p) - 200) < 128) || \ - ((unsigned)((p) - 768) < 128)) diff --git a/tcpdump.tproj/bootp.h b/tcpdump.tproj/bootp.h deleted file mode 100644 index 74dc2c2..0000000 --- a/tcpdump.tproj/bootp.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/bootp.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) */ -/* - * Bootstrap Protocol (BOOTP). RFC951 and RFC1048. - * - * This file specifies the "implementation-independent" BOOTP protocol - * information which is common to both client and server. - * - * Copyright 1988 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. - */ - - -struct bootp { - unsigned char bp_op; /* packet opcode type */ - unsigned char bp_htype; /* hardware addr type */ - unsigned char bp_hlen; /* hardware addr length */ - unsigned char bp_hops; /* gateway hops */ - u_int32_t bp_xid; /* transaction ID */ - unsigned short bp_secs; /* seconds since boot began */ - unsigned short bp_unused; - struct in_addr bp_ciaddr; /* client IP address */ - struct in_addr bp_yiaddr; /* 'your' IP address */ - struct in_addr bp_siaddr; /* server IP address */ - struct in_addr bp_giaddr; /* gateway IP address */ - unsigned char bp_chaddr[16]; /* client hardware address */ - unsigned char bp_sname[64]; /* server host name */ - unsigned char bp_file[128]; /* boot file name */ - unsigned char bp_vend[64]; /* vendor-specific area */ -}; - -/* - * UDP port numbers, server and client. - */ -#define IPPORT_BOOTPS 67 -#define IPPORT_BOOTPC 68 - -#define BOOTREPLY 2 -#define BOOTREQUEST 1 - - -/* - * Vendor magic cookie (v_magic) for CMU - */ -#define VM_CMU "CMU" - -/* - * Vendor magic cookie (v_magic) for RFC1048 - */ -#define VM_RFC1048 { 99, 130, 83, 99 } - - - -/* - * RFC1048 tag values used to specify what information is being supplied in - * the vendor field of the packet. - */ - -#define TAG_PAD ((unsigned char) 0) -#define TAG_SUBNET_MASK ((unsigned char) 1) -#define TAG_TIME_OFFSET ((unsigned char) 2) -#define TAG_GATEWAY ((unsigned char) 3) -#define TAG_TIME_SERVER ((unsigned char) 4) -#define TAG_NAME_SERVER ((unsigned char) 5) -#define TAG_DOMAIN_SERVER ((unsigned char) 6) -#define TAG_LOG_SERVER ((unsigned char) 7) -#define TAG_COOKIE_SERVER ((unsigned char) 8) -#define TAG_LPR_SERVER ((unsigned char) 9) -#define TAG_IMPRESS_SERVER ((unsigned char) 10) -#define TAG_RLP_SERVER ((unsigned char) 11) -#define TAG_HOSTNAME ((unsigned char) 12) -#define TAG_BOOTSIZE ((unsigned char) 13) -#define TAG_END ((unsigned char) 255) -/* RFC1497 tags */ -#define TAG_DUMPPATH ((unsigned char) 14) -#define TAG_DOMAINNAME ((unsigned char) 15) -#define TAG_SWAP_SERVER ((unsigned char) 16) -#define TAG_ROOTPATH ((unsigned char) 17) -#define TAG_EXTPATH ((unsigned char) 18) - - - -/* - * "vendor" data permitted for CMU bootp clients. - */ - -struct cmu_vend { - unsigned char v_magic[4]; /* magic number */ - u_int32_t v_flags; /* flags/opcodes, etc. */ - struct in_addr v_smask; /* Subnet mask */ - struct in_addr v_dgate; /* Default gateway */ - struct in_addr v_dns1, v_dns2; /* Domain name servers */ - struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */ - struct in_addr v_ts1, v_ts2; /* Time servers */ - unsigned char v_unused[24]; /* currently unused */ -}; - - -/* v_flags values */ -#define VF_SMASK 1 /* Subnet mask field contains valid data */ diff --git a/tcpdump.tproj/bpf_dump.c b/tcpdump.tproj/bpf_dump.c deleted file mode 100644 index 5c29e59..0000000 --- a/tcpdump.tproj/bpf_dump.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - */ -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/bpf_dump.c,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include -#include - -#include "interface.h" - -extern void bpf_dump(struct bpf_program *, int); - -void -bpf_dump(struct bpf_program *p, int option) -{ - struct bpf_insn *insn; - int i; - int n = p->bf_len; - - insn = p->bf_insns; - if (option > 2) { - printf("%d\n", n); - for (i = 0; i < n; ++insn, ++i) { - printf("%u %u %u %u\n", insn->code, - insn->jt, insn->jf, insn->k); - } - return ; - } - if (option > 1) { - for (i = 0; i < n; ++insn, ++i) - printf("{ 0x%x, %d, %d, 0x%08x },\n", - insn->code, insn->jt, insn->jf, insn->k); - return; - } - for (i = 0; i < n; ++insn, ++i) { -#ifdef BDEBUG - extern int bids[]; - printf(bids[i] > 0 ? "[%02d]" : " -- ", bids[i] - 1); -#endif - puts(bpf_image(insn, i)); - } -} diff --git a/tcpdump.tproj/decnet.h b/tcpdump.tproj/decnet.h deleted file mode 100644 index 37a6127..0000000 --- a/tcpdump.tproj/decnet.h +++ /dev/null @@ -1,476 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1994, 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: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/decnet.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) - */ - -typedef unsigned char byte[1]; /* single byte field */ -typedef unsigned char word[2]; /* 2 byte field */ -typedef unsigned char longword[4]; /* 4 bytes field */ - -/* - * Definitions for DECNET Phase IV protocol headers - */ -union etheraddress { - unsigned char dne_addr[6]; /* full ethernet address */ - struct { - unsigned char dne_hiord[4]; /* DECnet HIORD prefix */ - unsigned char dne_nodeaddr[2]; /* DECnet node address */ - } dne_remote; -}; - -typedef union etheraddress etheraddr; /* Ethernet address */ - -#define HIORD 0x000400aa /* high 32-bits of address (swapped) */ - -#define AREAMASK 0176000 /* mask for area field */ -#define AREASHIFT 10 /* bit-offset for area field */ -#define NODEMASK 01777 /* mask for node address field */ - -#define DN_MAXADDL 20 /* max size of DECnet address */ -struct dn_naddr { - unsigned short a_len; /* length of address */ - unsigned char a_addr[DN_MAXADDL]; /* address as bytes */ -}; - -/* - * Define long and short header formats. - */ -struct shorthdr - { - byte sh_flags; /* route flags */ - word sh_dst; /* destination node address */ - word sh_src; /* source node address */ - byte sh_visits; /* visit count */ - }; - -struct longhdr - { - byte lg_flags; /* route flags */ - byte lg_darea; /* destination area (reserved) */ - byte lg_dsarea; /* destination subarea (reserved) */ - etheraddr lg_dst; /* destination id */ - byte lg_sarea; /* source area (reserved) */ - byte lg_ssarea; /* source subarea (reserved) */ - etheraddr lg_src; /* source id */ - byte lg_nextl2; /* next level 2 router (reserved) */ - byte lg_visits; /* visit count */ - byte lg_service; /* service class (reserved) */ - byte lg_pt; /* protocol type (reserved) */ - }; - -union routehdr - { - struct shorthdr rh_short; /* short route header */ - struct longhdr rh_long; /* long route header */ - }; - -/* - * Define the values of various fields in the protocol messages. - * - * 1. Data packet formats. - */ -#define RMF_MASK 7 /* mask for message type */ -#define RMF_SHORT 2 /* short message format */ -#define RMF_LONG 6 /* long message format */ -#ifndef RMF_RQR -#define RMF_RQR 010 /* request return to sender */ -#define RMF_RTS 020 /* returning to sender */ -#define RMF_IE 040 /* intra-ethernet packet */ -#endif /* RMR_RQR */ -#define RMF_FVER 0100 /* future version flag */ -#define RMF_PAD 0200 /* pad field */ -#define RMF_PADMASK 0177 /* pad field mask */ - -#define VIS_MASK 077 /* visit field mask */ - -/* - * 2. Control packet formats. - */ -#define RMF_CTLMASK 017 /* mask for message type */ -#define RMF_CTLMSG 01 /* control message indicator */ -#define RMF_INIT 01 /* initialization message */ -#define RMF_VER 03 /* verification message */ -#define RMF_TEST 05 /* hello and test message */ -#define RMF_L1ROUT 07 /* level 1 routing message */ -#define RMF_L2ROUT 011 /* level 2 routing message */ -#define RMF_RHELLO 013 /* router hello message */ -#define RMF_EHELLO 015 /* endnode hello message */ - -#define TI_L2ROUT 01 /* level 2 router */ -#define TI_L1ROUT 02 /* level 1 router */ -#define TI_ENDNODE 03 /* endnode */ -#define TI_VERIF 04 /* verification required */ -#define TI_BLOCK 010 /* blocking requested */ - -#define VE_VERS 2 /* version number (2) */ -#define VE_ECO 0 /* ECO number */ -#define VE_UECO 0 /* user ECO number (0) */ - -#define P3_VERS 1 /* phase III version number (1) */ -#define P3_ECO 3 /* ECO number (3) */ -#define P3_UECO 0 /* user ECO number (0) */ - -#define II_L2ROUT 01 /* level 2 router */ -#define II_L1ROUT 02 /* level 1 router */ -#define II_ENDNODE 03 /* endnode */ -#define II_VERIF 04 /* verification required */ -#define II_NOMCAST 040 /* no multicast traffic accepted */ -#define II_BLOCK 0100 /* blocking requested */ -#define II_TYPEMASK 03 /* mask for node type */ - -#define TESTDATA 0252 /* test data bytes */ -#define TESTLEN 1 /* length of transmitted test data */ - -/* - * Define control message formats. - */ -struct initmsgIII /* phase III initialization message */ - { - byte inIII_flags; /* route flags */ - word inIII_src; /* source node address */ - byte inIII_info; /* routing layer information */ - word inIII_blksize; /* maximum data link block size */ - byte inIII_vers; /* version number */ - byte inIII_eco; /* ECO number */ - byte inIII_ueco; /* user ECO number */ - byte inIII_rsvd; /* reserved image field */ - }; - -struct initmsg /* initialization message */ - { - byte in_flags; /* route flags */ - word in_src; /* source node address */ - byte in_info; /* routing layer information */ - word in_blksize; /* maximum data link block size */ - byte in_vers; /* version number */ - byte in_eco; /* ECO number */ - byte in_ueco; /* user ECO number */ - word in_hello; /* hello timer */ - byte in_rsvd; /* reserved image field */ - }; - -struct verifmsg /* verification message */ - { - byte ve_flags; /* route flags */ - word ve_src; /* source node address */ - byte ve_fcnval; /* function value image field */ - }; - -struct testmsg /* hello and test message */ - { - byte te_flags; /* route flags */ - word te_src; /* source node address */ - byte te_data; /* test data image field */ - }; - -struct l1rout /* level 1 routing message */ - { - byte r1_flags; /* route flags */ - word r1_src; /* source node address */ - byte r1_rsvd; /* reserved field */ - }; - -struct l2rout /* level 2 routing message */ - { - byte r2_flags; /* route flags */ - word r2_src; /* source node address */ - byte r2_rsvd; /* reserved field */ - }; - -struct rhellomsg /* router hello message */ - { - byte rh_flags; /* route flags */ - byte rh_vers; /* version number */ - byte rh_eco; /* ECO number */ - byte rh_ueco; /* user ECO number */ - etheraddr rh_src; /* source id */ - byte rh_info; /* routing layer information */ - word rh_blksize; /* maximum data link block size */ - byte rh_priority; /* router's priority */ - byte rh_area; /* reserved */ - word rh_hello; /* hello timer */ - byte rh_mpd; /* reserved */ - }; - -struct ehellomsg /* endnode hello message */ - { - byte eh_flags; /* route flags */ - byte eh_vers; /* version number */ - byte eh_eco; /* ECO number */ - byte eh_ueco; /* user ECO number */ - etheraddr eh_src; /* source id */ - byte eh_info; /* routing layer information */ - word eh_blksize; /* maximum data link block size */ - byte eh_area; /* area (reserved) */ - byte eh_seed[8]; /* verification seed */ - etheraddr eh_router; /* designated router */ - word eh_hello; /* hello timer */ - byte eh_mpd; /* (reserved) */ - byte eh_data; /* test data image field */ - }; - -union controlmsg - { - struct initmsg cm_init; /* initialization message */ - struct verifmsg cm_ver; /* verification message */ - struct testmsg cm_test; /* hello and test message */ - struct l1rout cm_l1rou; /* level 1 routing message */ - struct l2rout cm_l2rout; /* level 2 routing message */ - struct rhellomsg cm_rhello; /* router hello message */ - struct ehellomsg cm_ehello; /* endnode hello message */ - }; - -/* Macros for decoding routing-info fields */ -#define RI_COST(x) ((x)&0777) -#define RI_HOPS(x) (((x)>>10)&037) - -/* - * NSP protocol fields and values. - */ - -#define NSP_TYPEMASK 014 /* mask to isolate type code */ -#define NSP_SUBMASK 0160 /* mask to isolate subtype code */ -#define NSP_SUBSHFT 4 /* shift to move subtype code */ - -#define MFT_DATA 0 /* data message */ -#define MFT_ACK 04 /* acknowledgement message */ -#define MFT_CTL 010 /* control message */ - -#define MFS_ILS 020 /* data or I/LS indicator */ -#define MFS_BOM 040 /* beginning of message (data) */ -#define MFS_MOM 0 /* middle of message (data) */ -#define MFS_EOM 0100 /* end of message (data) */ -#define MFS_INT 040 /* interrupt message */ - -#define MFS_DACK 0 /* data acknowledgement */ -#define MFS_IACK 020 /* I/LS acknowledgement */ -#define MFS_CACK 040 /* connect acknowledgement */ - -#define MFS_NOP 0 /* no operation */ -#define MFS_CI 020 /* connect initiate */ -#define MFS_CC 040 /* connect confirm */ -#define MFS_DI 060 /* disconnect initiate */ -#define MFS_DC 0100 /* disconnect confirm */ -#define MFS_RCI 0140 /* retransmitted connect initiate */ - -#define SGQ_ACK 0100000 /* ack */ -#define SGQ_NAK 0110000 /* negative ack */ -#define SGQ_OACK 0120000 /* other channel ack */ -#define SGQ_ONAK 0130000 /* other channel negative ack */ -#define SGQ_MASK 07777 /* mask to isolate seq # */ -#define SGQ_OTHER 020000 /* other channel qualifier */ -#define SGQ_DELAY 010000 /* ack delay flag */ - -#define SGQ_EOM 0100000 /* pseudo flag for end-of-message */ - -#define LSM_MASK 03 /* mask for modifier field */ -#define LSM_NOCHANGE 0 /* no change */ -#define LSM_DONOTSEND 1 /* do not send data */ -#define LSM_SEND 2 /* send data */ - -#define LSI_MASK 014 /* mask for interpretation field */ -#define LSI_DATA 0 /* data segment or message count */ -#define LSI_INTR 4 /* interrupt request count */ -#define LSI_INTM 0377 /* funny marker for int. message */ - -#define COS_MASK 014 /* mask for flow control field */ -#define COS_NONE 0 /* no flow control */ -#define COS_SEGMENT 04 /* segment flow control */ -#define COS_MESSAGE 010 /* message flow control */ -#define COS_CRYPTSER 020 /* cryptographic services requested */ -#define COS_DEFAULT 1 /* default value for field */ - -#define COI_MASK 3 /* mask for version field */ -#define COI_32 0 /* version 3.2 */ -#define COI_31 1 /* version 3.1 */ -#define COI_40 2 /* version 4.0 */ -#define COI_41 3 /* version 4.1 */ - -#define MNU_MASK 140 /* mask for session control version */ -#define MNU_10 000 /* session V1.0 */ -#define MNU_20 040 /* session V2.0 */ -#define MNU_ACCESS 1 /* access control present */ -#define MNU_USRDATA 2 /* user data field present */ -#define MNU_INVKPROXY 4 /* invoke proxy field present */ -#define MNU_UICPROXY 8 /* use uic-based proxy */ - -#define DC_NORESOURCES 1 /* no resource reason code */ -#define DC_NOLINK 41 /* no link terminate reason code */ -#define DC_COMPLETE 42 /* disconnect complete reason code */ - -#define DI_NOERROR 0 /* user disconnect */ -#define DI_SHUT 3 /* node is shutting down */ -#define DI_NOUSER 4 /* destination end user does not exist */ -#define DI_INVDEST 5 /* invalid end user destination */ -#define DI_REMRESRC 6 /* insufficient remote resources */ -#define DI_TPA 8 /* third party abort */ -#define DI_PROTOCOL 7 /* protocol error discovered */ -#define DI_ABORT 9 /* user abort */ -#define DI_LOCALRESRC 32 /* insufficient local resources */ -#define DI_REMUSERRESRC 33 /* insufficient remote user resources */ -#define DI_BADACCESS 34 /* bad access control information */ -#define DI_BADACCNT 36 /* bad ACCOUNT information */ -#define DI_CONNECTABORT 38 /* connect request cancelled */ -#define DI_TIMEDOUT 38 /* remote node or user crashed */ -#define DI_UNREACHABLE 39 /* local timers expired due to ... */ -#define DI_BADIMAGE 43 /* bad image data in connect */ -#define DI_SERVMISMATCH 54 /* cryptographic service mismatch */ - -#define UC_OBJREJECT 0 /* object rejected connect */ -#define UC_USERDISCONNECT 0 /* user disconnect */ -#define UC_RESOURCES 1 /* insufficient resources (local or remote) */ -#define UC_NOSUCHNODE 2 /* unrecognized node name */ -#define UC_REMOTESHUT 3 /* remote node shutting down */ -#define UC_NOSUCHOBJ 4 /* unrecognized object */ -#define UC_INVOBJFORMAT 5 /* invalid object name format */ -#define UC_OBJTOOBUSY 6 /* object too busy */ -#define UC_NETWORKABORT 8 /* network abort */ -#define UC_USERABORT 9 /* user abort */ -#define UC_INVNODEFORMAT 10 /* invalid node name format */ -#define UC_LOCALSHUT 11 /* local node shutting down */ -#define UC_ACCESSREJECT 34 /* invalid access control information */ -#define UC_NORESPONSE 38 /* no response from object */ -#define UC_UNREACHABLE 39 /* node unreachable */ - -/* - * NSP message formats. - */ -struct nsphdr /* general nsp header */ - { - byte nh_flags; /* message flags */ - word nh_dst; /* destination link address */ - word nh_src; /* source link address */ - }; - -struct seghdr /* data segment header */ - { - byte sh_flags; /* message flags */ - word sh_dst; /* destination link address */ - word sh_src; /* source link address */ - word sh_seq[3]; /* sequence numbers */ - }; - -struct minseghdr /* minimum data segment header */ - { - byte ms_flags; /* message flags */ - word ms_dst; /* destination link address */ - word ms_src; /* source link address */ - word ms_seq; /* sequence number */ - }; - -struct lsmsg /* link service message (after hdr) */ - { - byte ls_lsflags; /* link service flags */ - byte ls_fcval; /* flow control value */ - }; - -struct ackmsg /* acknowledgement message */ - { - byte ak_flags; /* message flags */ - word ak_dst; /* destination link address */ - word ak_src; /* source link address */ - word ak_acknum[2]; /* acknowledgement numbers */ - }; - -struct minackmsg /* minimum acknowledgement message */ - { - byte mk_flags; /* message flags */ - word mk_dst; /* destination link address */ - word mk_src; /* source link address */ - word mk_acknum; /* acknowledgement number */ - }; - -struct ciackmsg /* connect acknowledgement message */ - { - byte ck_flags; /* message flags */ - word ck_dst; /* destination link address */ - }; - -struct cimsg /* connect initiate message */ - { - byte ci_flags; /* message flags */ - word ci_dst; /* destination link address (0) */ - word ci_src; /* source link address */ - byte ci_services; /* requested services */ - byte ci_info; /* information */ - word ci_segsize; /* maximum segment size */ - }; - -struct ccmsg /* connect confirm message */ - { - byte cc_flags; /* message flags */ - word cc_dst; /* destination link address */ - word cc_src; /* source link address */ - byte cc_services; /* requested services */ - byte cc_info; /* information */ - word cc_segsize; /* maximum segment size */ - byte cc_optlen; /* optional data length */ - }; - -struct cnmsg /* generic connect message */ - { - byte cn_flags; /* message flags */ - word cn_dst; /* destination link address */ - word cn_src; /* source link address */ - byte cn_services; /* requested services */ - byte cn_info; /* information */ - word cn_segsize; /* maximum segment size */ - }; - -struct dimsg /* disconnect initiate message */ - { - byte di_flags; /* message flags */ - word di_dst; /* destination link address */ - word di_src; /* source link address */ - word di_reason; /* reason code */ - byte di_optlen; /* optional data length */ - }; - -struct dcmsg /* disconnect confirm message */ - { - byte dc_flags; /* message flags */ - word dc_dst; /* destination link address */ - word dc_src; /* source link address */ - word dc_reason; /* reason code */ - }; diff --git a/tcpdump.tproj/ethertype.h b/tcpdump.tproj/ethertype.h deleted file mode 100644 index 43726ac..0000000 --- a/tcpdump.tproj/ethertype.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1993, 1994, 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: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/ethertype.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) - */ - -/* Types missing from some systems */ - -#ifndef ETHERTYPE_NS -#define ETHERTYPE_NS 0x0600 -#endif -#ifndef ETHERTYPE_SPRITE -#define ETHERTYPE_SPRITE 0x0500 -#endif -#ifndef ETHERTYPE_TRAIL -#define ETHERTYPE_TRAIL 0x1000 -#endif -#ifndef ETHERTYPE_MOPDL -#define ETHERTYPE_MOPDL 0x6001 -#endif -#ifndef ETHERTYPE_MOPRC -#define ETHERTYPE_MOPRC 0x6002 -#endif -#ifndef ETHERTYPE_DN -#define ETHERTYPE_DN 0x6003 -#endif -#ifndef ETHERTYPE_LAT -#define ETHERTYPE_LAT 0x6004 -#endif -#ifndef ETHERTYPE_SCA -#define ETHERTYPE_SCA 0x6007 -#endif -#ifndef ETHERTYPE_REVARP -#define ETHERTYPE_REVARP 0x8035 -#endif -#ifndef ETHERTYPE_LANBRIDGE -#define ETHERTYPE_LANBRIDGE 0x8038 -#endif -#ifndef ETHERTYPE_DECDNS -#define ETHERTYPE_DECDNS 0x803c -#endif -#ifndef ETHERTYPE_DECDTS -#define ETHERTYPE_DECDTS 0x803e -#endif -#ifndef ETHERTYPE_VEXP -#define ETHERTYPE_VEXP 0x805b -#endif -#ifndef ETHERTYPE_VPROD -#define ETHERTYPE_VPROD 0x805c -#endif -#ifndef ETHERTYPE_ATALK -#define ETHERTYPE_ATALK 0x809b -#endif -#ifndef ETHERTYPE_AARP -#define ETHERTYPE_AARP 0x80f3 -#endif -#ifndef ETHERTYPE_LOOPBACK -#define ETHERTYPE_LOOPBACK 0x9000 -#endif diff --git a/tcpdump.tproj/extract.h b/tcpdump.tproj/extract.h deleted file mode 100644 index f3213d4..0000000 --- a/tcpdump.tproj/extract.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/extract.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) - */ - -/* Network to host order macros */ - -#ifdef LBL_ALIGN -#define EXTRACT_16BITS(p) \ - ((u_short)*((u_char *)(p) + 0) << 8 | \ - (u_short)*((u_char *)(p) + 1)) -#define EXTRACT_32BITS(p) \ - ((u_int32_t)*((u_char *)(p) + 0) << 24 | \ - (u_int32_t)*((u_char *)(p) + 1) << 16 | \ - (u_int32_t)*((u_char *)(p) + 2) << 8 | \ - (u_int32_t)*((u_char *)(p) + 3)) -#else -#define EXTRACT_16BITS(p) \ - ((u_short)ntohs(*(u_short *)(p))) -#define EXTRACT_32BITS(p) \ - ((u_int32_t)ntohl(*(u_int32_t *)(p))) -#endif - -#define EXTRACT_24BITS(p) \ - ((u_int32_t)*((u_char *)(p) + 0) << 16 | \ - (u_int32_t)*((u_char *)(p) + 1) << 8 | \ - (u_int32_t)*((u_char *)(p) + 2)) - -/* Little endian protocol host order macros */ - -#define EXTRACT_LE_8BITS(p) (*(p)) -#define EXTRACT_LE_16BITS(p) \ - ((u_short)*((u_char *)(p) + 1) << 8 | \ - (u_short)*((u_char *)(p) + 0)) -#define EXTRACT_LE_32BITS(p) \ - ((u_int32_t)*((u_char *)(p) + 3) << 24 | \ - (u_int32_t)*((u_char *)(p) + 2) << 16 | \ - (u_int32_t)*((u_char *)(p) + 1) << 8 | \ - (u_int32_t)*((u_char *)(p) + 0)) diff --git a/tcpdump.tproj/fddi.h b/tcpdump.tproj/fddi.h deleted file mode 100644 index 21920f4..0000000 --- a/tcpdump.tproj/fddi.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/fddi.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez Exp $ (LBL) - */ - -/* - * Based on Ultrix if_fddi.h - */ - -/* - * This stuff should come from a system header file, but there's no - * obviously portable way to do that and it's not really going - * to change from system to system (except for the padding business). - */ - -struct fddi_header { - u_char fddi_fc; /* frame control */ - u_char fddi_dhost[6]; - u_char fddi_shost[6]; -}; - - -/* Useful values for fddi_fc (frame control) field */ - -/* - * FDDI Frame Control bits - */ -#define FDDIFC_C 0x80 /* Class bit */ -#define FDDIFC_L 0x40 /* Address length bit */ -#define FDDIFC_F 0x30 /* Frame format bits */ -#define FDDIFC_Z 0x0f /* Control bits */ - -/* - * FDDI Frame Control values. (48-bit addressing only). - */ -#define FDDIFC_VOID 0x40 /* Void frame */ -#define FDDIFC_NRT 0x80 /* Nonrestricted token */ -#define FDDIFC_RT 0xc0 /* Restricted token */ -#define FDDIFC_SMT_INFO 0x41 /* SMT Info */ -#define FDDIFC_SMT_NSA 0x4F /* SMT Next station adrs */ -#define FDDIFC_MAC_BEACON 0xc2 /* MAC Beacon frame */ -#define FDDIFC_MAC_CLAIM 0xc3 /* MAC Claim frame */ -#define FDDIFC_LLC_ASYNC 0x50 /* Async. LLC frame */ -#define FDDIFC_LLC_SYNC 0xd0 /* Sync. LLC frame */ -#define FDDIFC_IMP_ASYNC 0x60 /* Implementor Async. */ -#define FDDIFC_IMP_SYNC 0xe0 /* Implementor Synch. */ -#define FDDIFC_SMT 0x40 /* SMT frame */ -#define FDDIFC_MAC 0xc0 /* MAC frame */ - -#define FDDIFC_CLFF 0xF0 /* Class/Length/Format bits */ -#define FDDIFC_ZZZZ 0x0F /* Control bits */ diff --git a/tcpdump.tproj/gnuc.h b/tcpdump.tproj/gnuc.h deleted file mode 100644 index a88d32c..0000000 --- a/tcpdump.tproj/gnuc.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/gnuc.h,v 1.1.1.1 1999/05/02 03:58:31 wsanchez 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/tcpdump.tproj/igrp.h b/tcpdump.tproj/igrp.h deleted file mode 100644 index ec55bdf..0000000 --- a/tcpdump.tproj/igrp.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* 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/tcpdump.tproj/interface.h b/tcpdump.tproj/interface.h deleted file mode 100644 index 089c4dd..0000000 --- a/tcpdump.tproj/interface.h +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/interface.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL) - */ - -#ifndef tcpdump_interface_h -#define tcpdump_interface_h -#ifndef IPPROTO_ND -#define IPPROTO_ND 77 -#endif - - -#include "gnuc.h" -#ifdef HAVE_OS_PROTO_H -#include "os-proto.h" -#endif - -struct tok { - int v; /* value */ - char *s; /* string */ -}; - -extern int dflag; /* print filter code */ -extern int eflag; /* print ethernet header */ -extern int nflag; /* leave addresses as numbers */ -extern int Nflag; /* remove domains from printed host names */ -extern int qflag; /* quick (shorter) output */ -extern int Sflag; /* print raw TCP sequence numbers */ -extern int tflag; /* print packet arrival time */ -extern int vflag; /* verbose */ -extern int xflag; /* print packet in hex */ - -extern int packettype; /* as specified by -T */ -#define PT_VAT 1 /* Visual Audio Tool */ -#define PT_WB 2 /* distributed White Board */ -#define PT_RPC 3 /* Remote Procedure Call */ -#define PT_RTP 4 /* Real-Time Applications protocol */ -#define PT_RTCP 5 /* Real-Time Applications control protocol */ - -#ifndef min -#define min(a,b) ((a)>(b)?(b):(a)) -#endif -#ifndef max -#define max(a,b) ((b)>(a)?(b):(a)) -#endif - -/* - * The default snapshot length. This value allows most printers to print - * useful information while keeping the amount of unwanted data down. - * In particular, it allows for an ethernet header, tcp/ip header, and - * 14 bytes of data (assuming no ip options). - */ -#define DEFAULT_SNAPLEN 68 - -#ifndef BIG_ENDIAN -#define BIG_ENDIAN 4321 -#define LITTLE_ENDIAN 1234 -#endif - -#ifdef ETHER_HEADER_HAS_EA -#define ESRC(ep) ((ep)->ether_shost.ether_addr_octet) -#define EDST(ep) ((ep)->ether_dhost.ether_addr_octet) -#else -#define ESRC(ep) ((ep)->ether_shost) -#define EDST(ep) ((ep)->ether_dhost) -#endif - -#ifdef ETHER_ARP_HAS_X -#define SHA(ap) ((ap)->arp_xsha) -#define THA(ap) ((ap)->arp_xtha) -#define SPA(ap) ((ap)->arp_xspa) -#define TPA(ap) ((ap)->arp_xtpa) -#else -#ifdef ETHER_ARP_HAS_EA -#define SHA(ap) ((ap)->arp_sha.ether_addr_octet) -#define THA(ap) ((ap)->arp_tha.ether_addr_octet) -#else -#define SHA(ap) ((ap)->arp_sha) -#define THA(ap) ((ap)->arp_tha) -#endif -#define SPA(ap) ((ap)->arp_spa) -#define TPA(ap) ((ap)->arp_tpa) -#endif - -#ifndef NTOHL -#define NTOHL(x) (x) = ntohl(x) -#define NTOHS(x) (x) = ntohs(x) -#define HTONL(x) (x) = htonl(x) -#define HTONS(x) (x) = htons(x) -#endif -#endif - -extern char *program_name; /* used to generate self-identifying messages */ - -extern int32_t thiszone; /* seconds offset from gmt to local time */ - -extern int snaplen; -/* global pointers to beginning and end of current packet (during printing) */ -extern const u_char *packetp; -extern const u_char *snapend; - -/* True if "l" bytes of "var" were captured */ -#define TTEST2(var, l) ((u_char *)&(var) <= snapend - (l)) - -/* True if "var" was captured */ -#define TTEST(var) TTEST2(var, sizeof(var)) - -/* Bail if "l" bytes of "var" were not captured */ -#define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc - -/* Bail if "var" was not captured */ -#define TCHECK(var) TCHECK2(var, sizeof(var)) - -#ifdef __STDC__ -struct timeval; -#endif - -extern void ts_print(const struct timeval *); -extern int32_t gmt2local(void); - -extern int fn_print(const u_char *, const u_char *); -extern int fn_printn(const u_char *, u_int, const u_char *); -extern const char *tok2str(const struct tok *, const char *, int); -extern char *dnaddr_string(u_short); -extern char *savestr(const char *); - -extern void wrapup(int); - -#if __STDC__ -extern __dead void error(const char *, ...) - __attribute__((volatile, format (printf, 1, 2))); -extern void warning(const char *, ...) __attribute__ ((format (printf, 1, 2))); -#endif - -extern char *read_infile(char *); -extern char *copy_argv(char **); - -extern char *isonsap_string(const u_char *); -extern char *llcsap_string(u_char); -extern char *protoid_string(const u_char *); -extern char *dnname_string(u_short); -extern char *dnnum_string(u_short); - -/* The printer routines. */ - -#ifdef __STDC__ -struct pcap_pkthdr; -#endif - -extern int ether_encap_print(u_short, const u_char *, u_int, u_int); -extern int llc_print(const u_char *, u_int, u_int, const u_char *, - const u_char *); -extern void aarp_print(const u_char *, u_int); -extern void arp_print(const u_char *, u_int, u_int); -extern void atalk_print(const u_char *, u_int); -extern void atm_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); -extern void bootp_print(const u_char *, u_int, u_short, u_short); -extern void decnet_print(const u_char *, u_int, u_int); -extern void default_print(const u_char *, u_int); -extern void default_print_unaligned(const u_char *, u_int); -extern void dvmrp_print(const u_char *, u_int); -extern void egp_print(const u_char *, u_int, const u_char *); -extern void ether_if_print(u_char *, const struct pcap_pkthdr *, - const u_char *); -extern void fddi_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); -extern void gre_print(const u_char *, u_int); -extern void icmp_print(const u_char *, const u_char *); -extern void igrp_print(const u_char *, u_int, const u_char *); -extern void ip_print(const u_char *, u_int); -extern void ipx_print(const u_char *, u_int); -extern void isoclns_print(const u_char *, u_int, u_int, const u_char *, - const u_char *); -extern void krb_print(const u_char *, u_int); -extern void nfsreply_print(const u_char *, u_int, const u_char *); -extern void nfsreq_print(const u_char *, u_int, const u_char *); -extern void ns_print(const u_char *, u_int); -extern void ntp_print(const u_char *, u_int); -extern void null_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); -extern void ospf_print(const u_char *, u_int, const u_char *); -extern void pim_print(const u_char *, u_int); -extern void ppp_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); -extern void rip_print(const u_char *, u_int); -extern void sl_if_print(u_char *, const struct pcap_pkthdr *, const u_char *); -extern void snmp_print(const u_char *, u_int); -extern void sunrpcrequest_print(const u_char *, u_int, const u_char *); -extern void tcp_print(const u_char *, u_int, const u_char *); -extern void tftp_print(const u_char *, u_int); -extern void udp_print(const u_char *, u_int, const u_char *); -extern void wb_print(const void *, u_int); diff --git a/tcpdump.tproj/ipx.h b/tcpdump.tproj/ipx.h deleted file mode 100644 index e1dda81..0000000 --- a/tcpdump.tproj/ipx.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * IPX protocol formats - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/ipx.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ - */ - -/* well-known sockets */ -#define IPX_SKT_NCP 0x0451 -#define IPX_SKT_SAP 0x0452 -#define IPX_SKT_RIP 0x0453 -#define IPX_SKT_NETBIOS 0x0455 -#define IPX_SKT_DIAGNOSTICS 0x0456 - -/* IPX transport header */ -struct ipxHdr { - u_short cksum; /* Checksum */ - u_short length; /* Length, in bytes, including header */ - u_char tCtl; /* Transport Control (i.e. hop count) */ - u_char pType; /* Packet Type (i.e. level 2 protocol) */ - u_short dstNet[2]; /* destination net */ - u_char dstNode[6]; /* destination node */ - u_short dstSkt; /* destination socket */ - u_short srcNet[2]; /* source net */ - u_char srcNode[6]; /* source node */ - u_short srcSkt; /* source socket */ -} ipx_hdr_t; - -#define ipxSize 30 - diff --git a/tcpdump.tproj/llc.h b/tcpdump.tproj/llc.h deleted file mode 100644 index 4432514..0000000 --- a/tcpdump.tproj/llc.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1993, 1994 - * 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: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/llc.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL) - */ - -/* - * This stuff should come from a system header file, but there's no - * obviously portable way to do that and it's not really going - * to change from system to system. - */ - -/* - * A somewhat abstracted view of the LLC header - */ - -struct llc { - u_char dsap; - u_char ssap; - union { - u_char u_ctl; - u_short is_ctl; - struct { - u_char snap_ui; - u_char snap_pi[5]; - } snap; - struct { - u_char snap_ui; - u_char snap_orgcode[3]; - u_char snap_ethertype[2]; - } snap_ether; - } ctl; -}; - -#define llcui ctl.snap.snap_ui -#define llcpi ctl.snap.snap_pi -#define orgcode ctl.snap_ether.snap_orgcode -#define ethertype ctl.snap_ether.snap_ethertype -#define llcis ctl.is_ctl -#define llcu ctl.u_ctl - -#define LLC_U_FMT 3 -#define LLC_GSAP 1 -#define LLC_S_FMT 1 - -#define LLC_U_POLL 0x10 -#define LLC_IS_POLL 0x0001 -#define LLC_XID_FI 0x81 - -#define LLC_U_CMD(u) ((u) & 0xef) -#define LLC_UI 0x03 -#define LLC_UA 0x63 -#define LLC_DISC 0x43 -#define LLC_DM 0x0f -#define LLC_SABME 0x6f -#define LLC_TEST 0xe3 -#define LLC_XID 0xaf -#define LLC_FRMR 0x87 - -#define LLC_S_CMD(is) (((is) >> 10) & 0x03) -#define LLC_RR 0x0100 -#define LLC_RNR 0x0500 -#define LLC_REJ 0x0900 - -#define LLC_IS_NR(is) (((is) >> 9) & 0x7f) -#define LLC_I_NS(is) (((is) >> 1) & 0x7f) - -#ifndef LLCSAP_NULL -#define LLCSAP_NULL 0x00 -#endif -#ifndef LLCSAP_GLOBAL -#define LLCSAP_GLOBAL 0xff -#endif -#ifndef LLCSAP_8021B -#define LLCSAP_8021B_I 0x02 -#endif -#ifndef LLCSAP_8021B -#define LLCSAP_8021B_G 0x03 -#endif -#ifndef LLCSAP_IP -#define LLCSAP_IP 0x06 -#endif -#ifndef LLCSAP_PROWAYNM -#define LLCSAP_PROWAYNM 0x0e -#endif -#ifndef LLCSAP_8021D -#define LLCSAP_8021D 0x42 -#endif -#ifndef LLCSAP_RS511 -#define LLCSAP_RS511 0x4e -#endif -#ifndef LLCSAP_ISO8208 -#define LLCSAP_ISO8208 0x7e -#endif -#ifndef LLCSAP_PROWAY -#define LLCSAP_PROWAY 0x8e -#endif -#ifndef LLCSAP_SNAP -#define LLCSAP_SNAP 0xaa -#endif -#ifndef LLCSAP_ISONS -#define LLCSAP_ISONS 0xfe -#endif diff --git a/tcpdump.tproj/machdep.c b/tcpdump.tproj/machdep.c deleted file mode 100644 index df136f4..0000000 --- a/tcpdump.tproj/machdep.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/machdep.c,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL)"; -#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/tcpdump.tproj/machdep.h b/tcpdump.tproj/machdep.h deleted file mode 100644 index 7e8d45a..0000000 --- a/tcpdump.tproj/machdep.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/machdep.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL) - */ -#ifndef tcpdump_machdep_h -#define tcpdump_machdep_h - -int abort_on_misalignment(char *); -#endif diff --git a/tcpdump.tproj/mib.h b/tcpdump.tproj/mib.h deleted file mode 100644 index 454d6b2..0000000 --- a/tcpdump.tproj/mib.h +++ /dev/null @@ -1,1279 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * This file was generated by tcpdump/makemib on Wed Sep 26 12:12:31 EDT 1990 - * You probably don't want to edit this by hand! - * - * struct mib somename = { desc, oid-octet, type, child-pointer, next-pointer -}; - */ - -/* parse problem: new name "mib" for mgmt.mib(1) ignored */ -/* parse problem: no parent for 0.nullSpecific(0) */ -struct obj -_proteon_obj = { - "proteon", 1, 0, - NULL, NULL -}, -_ibm_obj = { - "ibm", 2, 0, - NULL, &_proteon_obj -}, -_cmu_obj = { - "cmu", 3, 0, - NULL, &_ibm_obj -}, -_unix_obj = { - "unix", 4, 0, - NULL, &_cmu_obj -}, -_acc_obj = { - "acc", 5, 0, - NULL, &_unix_obj -}, -_twg_obj = { - "twg", 6, 0, - NULL, &_acc_obj -}, -_cayman_obj = { - "cayman", 7, 0, - NULL, &_twg_obj -}, -_nysernet_obj = { - "nysernet", 8, 0, - NULL, &_cayman_obj -}, -_cisco_obj = { - "cisco", 9, 0, - NULL, &_nysernet_obj -}, -_nsc_obj = { - "nsc", 10, 0, - NULL, &_cisco_obj -}, -_hp_obj = { - "hp", 11, 0, - NULL, &_nsc_obj -}, -_epilogue_obj = { - "epilogue", 12, 0, - NULL, &_hp_obj -}, -_utennessee_obj = { - "utennessee", 13, 0, - NULL, &_epilogue_obj -}, -_bbn_obj = { - "bbn", 14, 0, - NULL, &_utennessee_obj -}, -_xylogics_obj = { - "xylogics", 15, 0, - NULL, &_bbn_obj -}, -_unisys_obj = { - "unisys", 16, 0, - NULL, &_xylogics_obj -}, -_canstar_obj = { - "canstar", 17, 0, - NULL, &_unisys_obj -}, -_wellfleet_obj = { - "wellfleet", 18, 0, - NULL, &_canstar_obj -}, -_trw_obj = { - "trw", 19, 0, - NULL, &_wellfleet_obj -}, -_mit_obj = { - "mit", 20, 0, - NULL, &_trw_obj -}, -_eon_obj = { - "eon", 21, 0, - NULL, &_mit_obj -}, -_spartacus_obj = { - "spartacus", 22, 0, - NULL, &_eon_obj -}, -_excelan_obj = { - "excelan", 23, 0, - NULL, &_spartacus_obj -}, -_spider_obj = { - "spider", 24, 0, - NULL, &_excelan_obj -}, -_nsfnet_obj = { - "nsfnet", 25, 0, - NULL, &_spider_obj -}, -_sytek_obj = { - "sytek", 26, 0, - NULL, &_nsfnet_obj -}, -_intergraph_obj = { - "intergraph", 27, 0, - NULL, &_sytek_obj -}, -_interlan_obj = { - "interlan", 28, 0, - NULL, &_intergraph_obj -}, -_vitalink_obj = { - "vitalink", 29, 0, - NULL, &_interlan_obj -}, -_ulana_obj = { - "ulana", 30, 0, - NULL, &_vitalink_obj -}, -_nswc_obj = { - "nswc", 31, 0, - NULL, &_ulana_obj -}, -_santacruzoperation_obj = { - "santacruzoperation", 32, 0, - NULL, &_nswc_obj -}, -_xyplex_obj = { - "xyplex", 33, 0, - NULL, &_santacruzoperation_obj -}, -_cray_obj = { - "cray", 34, 0, - NULL, &_xyplex_obj -}, -_bellnorthernresearch_obj = { - "bellnorthernresearch", 35, 0, - NULL, &_cray_obj -}, -_dec_obj = { - "dec", 36, 0, - NULL, &_bellnorthernresearch_obj -}, -_touch_obj = { - "touch", 37, 0, - NULL, &_dec_obj -}, -_networkresearchcorp_obj = { - "networkresearchcorp", 38, 0, - NULL, &_touch_obj -}, -_baylor_obj = { - "baylor", 39, 0, - NULL, &_networkresearchcorp_obj -}, -_nmfeccllnl_obj = { - "nmfeccllnl", 40, 0, - NULL, &_baylor_obj -}, -_sri_obj = { - "sri", 41, 0, - NULL, &_nmfeccllnl_obj -}, -_sun_obj = { - "sun", 42, 0, - NULL, &_sri_obj -}, -_3com_obj = { - "3com", 43, 0, - NULL, &_sun_obj -}, -_cmc_obj = { - "cmc", 44, 0, - NULL, &_3com_obj -}, -_synoptics_obj = { - "synoptics", 45, 0, - NULL, &_cmc_obj -}, -_cheyenne_obj = { - "cheyenne", 46, 0, - NULL, &_synoptics_obj -}, -_prime_obj = { - "prime", 47, 0, - NULL, &_cheyenne_obj -}, -_mcnc_obj = { - "mcnc", 48, 0, - NULL, &_prime_obj -}, -_chipcom_obj = { - "chipcom", 49, 0, - NULL, &_mcnc_obj -}, -_opticaldatasystems_obj = { - "opticaldatasystems", 50, 0, - NULL, &_chipcom_obj -}, -_gated_obj = { - "gated", 51, 0, - NULL, &_opticaldatasystems_obj -}, -_cabletron_obj = { - "cabletron", 52, 0, - NULL, &_gated_obj -}, -_apollo_obj = { - "apollo", 53, 0, - NULL, &_cabletron_obj -}, -_desktalksystems_obj = { - "desktalksystems", 54, 0, - NULL, &_apollo_obj -}, -_ssds_obj = { - "ssds", 55, 0, - NULL, &_desktalksystems_obj -}, -_castlerock_obj = { - "castlerock", 56, 0, - NULL, &_ssds_obj -}, -_mips_obj = { - "mips", 57, 0, - NULL, &_castlerock_obj -}, -_tgv_obj = { - "tgv", 58, 0, - NULL, &_mips_obj -}, -_silicongraphics_obj = { - "silicongraphics", 59, 0, - NULL, &_tgv_obj -}, -_ubc_obj = { - "ubc", 60, 0, - NULL, &_silicongraphics_obj -}, -_merit_obj = { - "merit", 61, 0, - NULL, &_ubc_obj -}, -_fibercom_obj = { - "fibercom", 62, 0, - NULL, &_merit_obj -}, -_apple_obj = { - "apple", 63, 0, - NULL, &_fibercom_obj -}, -_gandalf_obj = { - "gandalf", 64, 0, - NULL, &_apple_obj -}, -_dartmouth_obj = { - "dartmouth", 65, 0, - NULL, &_gandalf_obj -}, -_davidsystems_obj = { - "davidsystems", 66, 0, - NULL, &_dartmouth_obj -}, -_reuter_obj = { - "reuter", 67, 0, - NULL, &_davidsystems_obj -}, -_cornell_obj = { - "cornell", 68, 0, - NULL, &_reuter_obj -}, -_tmac_obj = { - "tmac", 69, 0, - NULL, &_cornell_obj -}, -_locus_obj = { - "locus", 70, 0, - NULL, &_tmac_obj -}, -_nasa_obj = { - "nasa", 71, 0, - NULL, &_locus_obj -}, -_retix_obj = { - "retix", 72, 0, - NULL, &_nasa_obj -}, -_boeing_obj = { - "boeing", 73, 0, - NULL, &_retix_obj -}, -_att_obj = { - "att", 74, 0, - NULL, &_boeing_obj -}, -_ungermannbass_obj = { - "ungermannbass", 75, 0, - NULL, &_att_obj -}, -_digitalanalysis_obj = { - "digitalanalysis", 76, 0, - NULL, &_ungermannbass_obj -}, -_hplanman_obj = { - "hplanman", 77, 0, - NULL, &_digitalanalysis_obj -}, -_netlabs_obj = { - "netlabs", 78, 0, - NULL, &_hplanman_obj -}, -_icl_obj = { - "icl", 79, 0, - NULL, &_netlabs_obj -}, -_auspex_obj = { - "auspex", 80, 0, - NULL, &_icl_obj -}, -_lannet_obj = { - "lannet", 81, 0, - NULL, &_auspex_obj -}, -_ncd_obj = { - "ncd", 82, 0, - NULL, &_lannet_obj -}, -_raycom_obj = { - "raycom", 83, 0, - NULL, &_ncd_obj -}, -_pirellifocom_obj = { - "pirellifocom", 84, 0, - NULL, &_raycom_obj -}, -_datability_obj = { - "datability", 85, 0, - NULL, &_pirellifocom_obj -}, -_networkappltech_obj = { - "networkappltech", 86, 0, - NULL, &_datability_obj -}, -_link_obj = { - "link", 87, 0, - NULL, &_networkappltech_obj -}, -_nyu_obj = { - "nyu", 88, 0, - NULL, &_link_obj -}, -_rnd_obj = { - "rnd", 89, 0, - NULL, &_nyu_obj -}, -_intercon_obj = { - "intercon", 90, 0, - NULL, &_rnd_obj -}, -_learningtree_obj = { - "learningtree", 91, 0, - NULL, &_intercon_obj -}, -_webstercomputer_obj = { - "webstercomputer", 92, 0, - NULL, &_learningtree_obj -}, -_frontier_obj = { - "frontier", 93, 0, - NULL, &_webstercomputer_obj -}, -_nokia_obj = { - "nokia", 94, 0, - NULL, &_frontier_obj -}, -_allenbradley_obj = { - "allenbradley", 95, 0, - NULL, &_nokia_obj -}, -_cern_obj = { - "cern", 96, 0, - NULL, &_allenbradley_obj -}, -_sigma_obj = { - "sigma", 97, 0, - NULL, &_cern_obj -}, -_emergingtech_obj = { - "emergingtech", 98, 0, - NULL, &_sigma_obj -}, -_snmpresearch_obj = { - "snmpresearch", 99, 0, - NULL, &_emergingtech_obj -}, -_ohiostate_obj = { - "ohiostate", 100, 0, - NULL, &_snmpresearch_obj -}, -_ultra_obj = { - "ultra", 101, 0, - NULL, &_ohiostate_obj -}, -_ccur_obj = { - "ccur", 136, 0, - NULL, &_ultra_obj -}, -_enterprises_obj = { - "enterprises", 1, 0, - &_ccur_obj, NULL -}, -_snmpInPkts_obj = { - "snmpInPkts", 1, 0, - NULL, NULL -}, -_snmpOutPkts_obj = { - "snmpOutPkts", 2, 0, - NULL, &_snmpInPkts_obj -}, -_snmpInBadVersions_obj = { - "snmpInBadVersions", 3, 0, - NULL, &_snmpOutPkts_obj -}, -_snmpInBadCommunityNames_obj = { - "snmpInBadCommunityNames", 4, 0, - NULL, &_snmpInBadVersions_obj -}, -_snmpInBadCommunityUses_obj = { - "snmpInBadCommunityUses", 5, 0, - NULL, &_snmpInBadCommunityNames_obj -}, -_snmpInASNParseErrs_obj = { - "snmpInASNParseErrs", 6, 0, - NULL, &_snmpInBadCommunityUses_obj -}, -_snmpInBadTypes_obj = { - "snmpInBadTypes", 7, 0, - NULL, &_snmpInASNParseErrs_obj -}, -_snmpInTooBigs_obj = { - "snmpInTooBigs", 8, 0, - NULL, &_snmpInBadTypes_obj -}, -_snmpInNoSuchNames_obj = { - "snmpInNoSuchNames", 9, 0, - NULL, &_snmpInTooBigs_obj -}, -_snmpInBadValues_obj = { - "snmpInBadValues", 10, 0, - NULL, &_snmpInNoSuchNames_obj -}, -_snmpInReadOnlys_obj = { - "snmpInReadOnlys", 11, 0, - NULL, &_snmpInBadValues_obj -}, -_snmpInGenErrs_obj = { - "snmpInGenErrs", 12, 0, - NULL, &_snmpInReadOnlys_obj -}, -_snmpInTotalReqVars_obj = { - "snmpInTotalReqVars", 13, 0, - NULL, &_snmpInGenErrs_obj -}, -_snmpInTotalSetVars_obj = { - "snmpInTotalSetVars", 14, 0, - NULL, &_snmpInTotalReqVars_obj -}, -_snmpInGetRequests_obj = { - "snmpInGetRequests", 15, 0, - NULL, &_snmpInTotalSetVars_obj -}, -_snmpInGetNexts_obj = { - "snmpInGetNexts", 16, 0, - NULL, &_snmpInGetRequests_obj -}, -_snmpInSetRequests_obj = { - "snmpInSetRequests", 17, 0, - NULL, &_snmpInGetNexts_obj -}, -_snmpInGetResponses_obj = { - "snmpInGetResponses", 18, 0, - NULL, &_snmpInSetRequests_obj -}, -_snmpInTraps_obj = { - "snmpInTraps", 19, 0, - NULL, &_snmpInGetResponses_obj -}, -_snmpOutTooBigs_obj = { - "snmpOutTooBigs", 20, 0, - NULL, &_snmpInTraps_obj -}, -_snmpOutNoSuchNames_obj = { - "snmpOutNoSuchNames", 21, 0, - NULL, &_snmpOutTooBigs_obj -}, -_snmpOutBadValues_obj = { - "snmpOutBadValues", 22, 0, - NULL, &_snmpOutNoSuchNames_obj -}, -_snmpOutReadOnlys_obj = { - "snmpOutReadOnlys", 23, 0, - NULL, &_snmpOutBadValues_obj -}, -_snmpOutGenErrs_obj = { - "snmpOutGenErrs", 24, 0, - NULL, &_snmpOutReadOnlys_obj -}, -_snmpOutGetRequests_obj = { - "snmpOutGetRequests", 25, 0, - NULL, &_snmpOutGenErrs_obj -}, -_snmpOutGetNexts_obj = { - "snmpOutGetNexts", 26, 0, - NULL, &_snmpOutGetRequests_obj -}, -_snmpOutSetRequests_obj = { - "snmpOutSetRequests", 27, 0, - NULL, &_snmpOutGetNexts_obj -}, -_snmpOutGetResponses_obj = { - "snmpOutGetResponses", 28, 0, - NULL, &_snmpOutSetRequests_obj -}, -_snmpOutTraps_obj = { - "snmpOutTraps", 29, 0, - NULL, &_snmpOutGetResponses_obj -}, -_snmpEnableAuthTraps_obj = { - "snmpEnableAuthTraps", 30, 0, - NULL, &_snmpOutTraps_obj -}, -_egpNeighState_obj = { - "egpNeighState", 1, 0, - NULL, NULL -}, -_egpNeighAddr_obj = { - "egpNeighAddr", 2, 0, - NULL, &_egpNeighState_obj -}, -_egpNeighAs_obj = { - "egpNeighAs", 3, 0, - NULL, &_egpNeighAddr_obj -}, -_egpNeighInMsgs_obj = { - "egpNeighInMsgs", 4, 0, - NULL, &_egpNeighAs_obj -}, -_egpNeighInErrs_obj = { - "egpNeighInErrs", 5, 0, - NULL, &_egpNeighInMsgs_obj -}, -_egpNeighOutMsgs_obj = { - "egpNeighOutMsgs", 6, 0, - NULL, &_egpNeighInErrs_obj -}, -_egpNeighOutErrs_obj = { - "egpNeighOutErrs", 7, 0, - NULL, &_egpNeighOutMsgs_obj -}, -_egpNeighInErrMsgs_obj = { - "egpNeighInErrMsgs", 8, 0, - NULL, &_egpNeighOutErrs_obj -}, -_egpNeighOutErrMsgs_obj = { - "egpNeighOutErrMsgs", 9, 0, - NULL, &_egpNeighInErrMsgs_obj -}, -_egpNeighStateUps_obj = { - "egpNeighStateUps", 10, 0, - NULL, &_egpNeighOutErrMsgs_obj -}, -_egpNeighStateDowns_obj = { - "egpNeighStateDowns", 11, 0, - NULL, &_egpNeighStateUps_obj -}, -_egpNeighIntervalHello_obj = { - "egpNeighIntervalHello", 12, 0, - NULL, &_egpNeighStateDowns_obj -}, -_egpNeighIntervalPoll_obj = { - "egpNeighIntervalPoll", 13, 0, - NULL, &_egpNeighIntervalHello_obj -}, -_egpNeighMode_obj = { - "egpNeighMode", 14, 0, - NULL, &_egpNeighIntervalPoll_obj -}, -_egpNeighEventTrigger_obj = { - "egpNeighEventTrigger", 15, 0, - NULL, &_egpNeighMode_obj -}, -_egpNeighEntry_obj = { - "egpNeighEntry", 1, 0, - &_egpNeighEventTrigger_obj, NULL -}, -_egpInMsgs_obj = { - "egpInMsgs", 1, 0, - NULL, NULL -}, -_egpInErrors_obj = { - "egpInErrors", 2, 0, - NULL, &_egpInMsgs_obj -}, -_egpOutMsgs_obj = { - "egpOutMsgs", 3, 0, - NULL, &_egpInErrors_obj -}, -_egpOutErrors_obj = { - "egpOutErrors", 4, 0, - NULL, &_egpOutMsgs_obj -}, -_egpNeighTable_obj = { - "egpNeighTable", 5, 0, - &_egpNeighEntry_obj, &_egpOutErrors_obj -}, -_egpAs_obj = { - "egpAs", 6, 0, - NULL, &_egpNeighTable_obj -}, -_udpLocalAddress_obj = { - "udpLocalAddress", 1, 0, - NULL, NULL -}, -_udpLocalPort_obj = { - "udpLocalPort", 2, 0, - NULL, &_udpLocalAddress_obj -}, -_udpEntry_obj = { - "udpEntry", 1, 0, - &_udpLocalPort_obj, NULL -}, -_udpInDatagrams_obj = { - "udpInDatagrams", 1, 0, - NULL, NULL -}, -_udpNoPorts_obj = { - "udpNoPorts", 2, 0, - NULL, &_udpInDatagrams_obj -}, -_udpInErrors_obj = { - "udpInErrors", 3, 0, - NULL, &_udpNoPorts_obj -}, -_udpOutDatagrams_obj = { - "udpOutDatagrams", 4, 0, - NULL, &_udpInErrors_obj -}, -_udpTable_obj = { - "udpTable", 5, 0, - &_udpEntry_obj, &_udpOutDatagrams_obj -}, -_tcpConnState_obj = { - "tcpConnState", 1, 0, - NULL, NULL -}, -_tcpConnLocalAddress_obj = { - "tcpConnLocalAddress", 2, 0, - NULL, &_tcpConnState_obj -}, -_tcpConnLocalPort_obj = { - "tcpConnLocalPort", 3, 0, - NULL, &_tcpConnLocalAddress_obj -}, -_tcpConnRemAddress_obj = { - "tcpConnRemAddress", 4, 0, - NULL, &_tcpConnLocalPort_obj -}, -_tcpConnRemPort_obj = { - "tcpConnRemPort", 5, 0, - NULL, &_tcpConnRemAddress_obj -}, -_tcpConnEntry_obj = { - "tcpConnEntry", 1, 0, - &_tcpConnRemPort_obj, NULL -}, -_tcpRtoAlgorithm_obj = { - "tcpRtoAlgorithm", 1, 0, - NULL, NULL -}, -_tcpRtoMin_obj = { - "tcpRtoMin", 2, 0, - NULL, &_tcpRtoAlgorithm_obj -}, -_tcpRtoMax_obj = { - "tcpRtoMax", 3, 0, - NULL, &_tcpRtoMin_obj -}, -_tcpMaxConn_obj = { - "tcpMaxConn", 4, 0, - NULL, &_tcpRtoMax_obj -}, -_tcpActiveOpens_obj = { - "tcpActiveOpens", 5, 0, - NULL, &_tcpMaxConn_obj -}, -_tcpPassiveOpens_obj = { - "tcpPassiveOpens", 6, 0, - NULL, &_tcpActiveOpens_obj -}, -_tcpAttemptFails_obj = { - "tcpAttemptFails", 7, 0, - NULL, &_tcpPassiveOpens_obj -}, -_tcpEstabResets_obj = { - "tcpEstabResets", 8, 0, - NULL, &_tcpAttemptFails_obj -}, -_tcpCurrEstab_obj = { - "tcpCurrEstab", 9, 0, - NULL, &_tcpEstabResets_obj -}, -_tcpInSegs_obj = { - "tcpInSegs", 10, 0, - NULL, &_tcpCurrEstab_obj -}, -_tcpOutSegs_obj = { - "tcpOutSegs", 11, 0, - NULL, &_tcpInSegs_obj -}, -_tcpRetransSegs_obj = { - "tcpRetransSegs", 12, 0, - NULL, &_tcpOutSegs_obj -}, -_tcpConnTable_obj = { - "tcpConnTable", 13, 0, - &_tcpConnEntry_obj, &_tcpRetransSegs_obj -}, -_tcpInErrs_obj = { - "tcpInErrs", 14, 0, - NULL, &_tcpConnTable_obj -}, -_tcpOutRsts_obj = { - "tcpOutRsts", 15, 0, - NULL, &_tcpInErrs_obj -}, -_icmpInMsgs_obj = { - "icmpInMsgs", 1, 0, - NULL, NULL -}, -_icmpInErrors_obj = { - "icmpInErrors", 2, 0, - NULL, &_icmpInMsgs_obj -}, -_icmpInDestUnreachs_obj = { - "icmpInDestUnreachs", 3, 0, - NULL, &_icmpInErrors_obj -}, -_icmpInTimeExcds_obj = { - "icmpInTimeExcds", 4, 0, - NULL, &_icmpInDestUnreachs_obj -}, -_icmpInParmProbs_obj = { - "icmpInParmProbs", 5, 0, - NULL, &_icmpInTimeExcds_obj -}, -_icmpInSrcQuenchs_obj = { - "icmpInSrcQuenchs", 6, 0, - NULL, &_icmpInParmProbs_obj -}, -_icmpInRedirects_obj = { - "icmpInRedirects", 7, 0, - NULL, &_icmpInSrcQuenchs_obj -}, -_icmpInEchos_obj = { - "icmpInEchos", 8, 0, - NULL, &_icmpInRedirects_obj -}, -_icmpInEchoReps_obj = { - "icmpInEchoReps", 9, 0, - NULL, &_icmpInEchos_obj -}, -_icmpInTimestamps_obj = { - "icmpInTimestamps", 10, 0, - NULL, &_icmpInEchoReps_obj -}, -_icmpInTimestampReps_obj = { - "icmpInTimestampReps", 11, 0, - NULL, &_icmpInTimestamps_obj -}, -_icmpInAddrMasks_obj = { - "icmpInAddrMasks", 12, 0, - NULL, &_icmpInTimestampReps_obj -}, -_icmpInAddrMaskReps_obj = { - "icmpInAddrMaskReps", 13, 0, - NULL, &_icmpInAddrMasks_obj -}, -_icmpOutMsgs_obj = { - "icmpOutMsgs", 14, 0, - NULL, &_icmpInAddrMaskReps_obj -}, -_icmpOutErrors_obj = { - "icmpOutErrors", 15, 0, - NULL, &_icmpOutMsgs_obj -}, -_icmpOutDestUnreachs_obj = { - "icmpOutDestUnreachs", 16, 0, - NULL, &_icmpOutErrors_obj -}, -_icmpOutTimeExcds_obj = { - "icmpOutTimeExcds", 17, 0, - NULL, &_icmpOutDestUnreachs_obj -}, -_icmpOutParmProbs_obj = { - "icmpOutParmProbs", 18, 0, - NULL, &_icmpOutTimeExcds_obj -}, -_icmpOutSrcQuenchs_obj = { - "icmpOutSrcQuenchs", 19, 0, - NULL, &_icmpOutParmProbs_obj -}, -_icmpOutRedirects_obj = { - "icmpOutRedirects", 20, 0, - NULL, &_icmpOutSrcQuenchs_obj -}, -_icmpOutEchos_obj = { - "icmpOutEchos", 21, 0, - NULL, &_icmpOutRedirects_obj -}, -_icmpOutEchoReps_obj = { - "icmpOutEchoReps", 22, 0, - NULL, &_icmpOutEchos_obj -}, -_icmpOutTimestamps_obj = { - "icmpOutTimestamps", 23, 0, - NULL, &_icmpOutEchoReps_obj -}, -_icmpOutTimestampReps_obj = { - "icmpOutTimestampReps", 24, 0, - NULL, &_icmpOutTimestamps_obj -}, -_icmpOutAddrMasks_obj = { - "icmpOutAddrMasks", 25, 0, - NULL, &_icmpOutTimestampReps_obj -}, -_icmpOutAddrMaskReps_obj = { - "icmpOutAddrMaskReps", 26, 0, - NULL, &_icmpOutAddrMasks_obj -}, -_ipNetToMediaIfIndex_obj = { - "ipNetToMediaIfIndex", 1, 0, - NULL, NULL -}, -_ipNetToMediaPhysAddress_obj = { - "ipNetToMediaPhysAddress", 2, 0, - NULL, &_ipNetToMediaIfIndex_obj -}, -_ipNetToMediaNetAddress_obj = { - "ipNetToMediaNetAddress", 3, 0, - NULL, &_ipNetToMediaPhysAddress_obj -}, -_ipNetToMediaType_obj = { - "ipNetToMediaType", 4, 0, - NULL, &_ipNetToMediaNetAddress_obj -}, -_ipNetToMediaEntry_obj = { - "ipNetToMediaEntry", 1, 0, - &_ipNetToMediaType_obj, NULL -}, -_ipRouteDest_obj = { - "ipRouteDest", 1, 0, - NULL, NULL -}, -_ipRouteIfIndex_obj = { - "ipRouteIfIndex", 2, 0, - NULL, &_ipRouteDest_obj -}, -_ipRouteMetric1_obj = { - "ipRouteMetric1", 3, 0, - NULL, &_ipRouteIfIndex_obj -}, -_ipRouteMetric2_obj = { - "ipRouteMetric2", 4, 0, - NULL, &_ipRouteMetric1_obj -}, -_ipRouteMetric3_obj = { - "ipRouteMetric3", 5, 0, - NULL, &_ipRouteMetric2_obj -}, -_ipRouteMetric4_obj = { - "ipRouteMetric4", 6, 0, - NULL, &_ipRouteMetric3_obj -}, -_ipRouteNextHop_obj = { - "ipRouteNextHop", 7, 0, - NULL, &_ipRouteMetric4_obj -}, -_ipRouteType_obj = { - "ipRouteType", 8, 0, - NULL, &_ipRouteNextHop_obj -}, -_ipRouteProto_obj = { - "ipRouteProto", 9, 0, - NULL, &_ipRouteType_obj -}, -_ipRouteAge_obj = { - "ipRouteAge", 10, 0, - NULL, &_ipRouteProto_obj -}, -_ipRouteMask_obj = { - "ipRouteMask", 11, 0, - NULL, &_ipRouteAge_obj -}, -_ipRouteEntry_obj = { - "ipRouteEntry", 1, 0, - &_ipRouteMask_obj, NULL -}, -_ipAdEntAddr_obj = { - "ipAdEntAddr", 1, 0, - NULL, NULL -}, -_ipAdEntIfIndex_obj = { - "ipAdEntIfIndex", 2, 0, - NULL, &_ipAdEntAddr_obj -}, -_ipAdEntNetMask_obj = { - "ipAdEntNetMask", 3, 0, - NULL, &_ipAdEntIfIndex_obj -}, -_ipAdEntBcastAddr_obj = { - "ipAdEntBcastAddr", 4, 0, - NULL, &_ipAdEntNetMask_obj -}, -_ipAdEntReasmMaxSize_obj = { - "ipAdEntReasmMaxSize", 5, 0, - NULL, &_ipAdEntBcastAddr_obj -}, -_ipAddrEntry_obj = { - "ipAddrEntry", 1, 0, - &_ipAdEntReasmMaxSize_obj, NULL -}, -_ipForwarding_obj = { - "ipForwarding", 1, 0, - NULL, NULL -}, -_ipDefaultTTL_obj = { - "ipDefaultTTL", 2, 0, - NULL, &_ipForwarding_obj -}, -_ipInReceives_obj = { - "ipInReceives", 3, 0, - NULL, &_ipDefaultTTL_obj -}, -_ipInHdrErrors_obj = { - "ipInHdrErrors", 4, 0, - NULL, &_ipInReceives_obj -}, -_ipInAddrErrors_obj = { - "ipInAddrErrors", 5, 0, - NULL, &_ipInHdrErrors_obj -}, -_ipForwDatagrams_obj = { - "ipForwDatagrams", 6, 0, - NULL, &_ipInAddrErrors_obj -}, -_ipInUnknownProtos_obj = { - "ipInUnknownProtos", 7, 0, - NULL, &_ipForwDatagrams_obj -}, -_ipInDiscards_obj = { - "ipInDiscards", 8, 0, - NULL, &_ipInUnknownProtos_obj -}, -_ipInDelivers_obj = { - "ipInDelivers", 9, 0, - NULL, &_ipInDiscards_obj -}, -_ipOutRequests_obj = { - "ipOutRequests", 10, 0, - NULL, &_ipInDelivers_obj -}, -_ipOutDiscards_obj = { - "ipOutDiscards", 11, 0, - NULL, &_ipOutRequests_obj -}, -_ipOutNoRoutes_obj = { - "ipOutNoRoutes", 12, 0, - NULL, &_ipOutDiscards_obj -}, -_ipReasmTimeout_obj = { - "ipReasmTimeout", 13, 0, - NULL, &_ipOutNoRoutes_obj -}, -_ipReasmReqds_obj = { - "ipReasmReqds", 14, 0, - NULL, &_ipReasmTimeout_obj -}, -_ipReasmOKs_obj = { - "ipReasmOKs", 15, 0, - NULL, &_ipReasmReqds_obj -}, -_ipReasmFails_obj = { - "ipReasmFails", 16, 0, - NULL, &_ipReasmOKs_obj -}, -_ipFragOKs_obj = { - "ipFragOKs", 17, 0, - NULL, &_ipReasmFails_obj -}, -_ipFragFails_obj = { - "ipFragFails", 18, 0, - NULL, &_ipFragOKs_obj -}, -_ipFragCreates_obj = { - "ipFragCreates", 19, 0, - NULL, &_ipFragFails_obj -}, -_ipAddrTable_obj = { - "ipAddrTable", 20, 0, - &_ipAddrEntry_obj, &_ipFragCreates_obj -}, -_ipRoutingTable_obj = { - "ipRoutingTable", 21, 0, - &_ipRouteEntry_obj, &_ipAddrTable_obj -}, -_ipNetToMediaTable_obj = { - "ipNetToMediaTable", 22, 0, - &_ipNetToMediaEntry_obj, &_ipRoutingTable_obj -}, -_atIfIndex_obj = { - "atIfIndex", 1, 0, - NULL, NULL -}, -_atPhysAddress_obj = { - "atPhysAddress", 2, 0, - NULL, &_atIfIndex_obj -}, -_atNetAddress_obj = { - "atNetAddress", 3, 0, - NULL, &_atPhysAddress_obj -}, -_atEntry_obj = { - "atEntry", 1, 0, - &_atNetAddress_obj, NULL -}, -_atTable_obj = { - "atTable", 1, 0, - &_atEntry_obj, NULL -}, -_ifIndex_obj = { - "ifIndex", 1, 0, - NULL, NULL -}, -_ifDescr_obj = { - "ifDescr", 2, 0, - NULL, &_ifIndex_obj -}, -_ifType_obj = { - "ifType", 3, 0, - NULL, &_ifDescr_obj -}, -_ifMtu_obj = { - "ifMtu", 4, 0, - NULL, &_ifType_obj -}, -_ifSpeed_obj = { - "ifSpeed", 5, 0, - NULL, &_ifMtu_obj -}, -_ifPhysAddress_obj = { - "ifPhysAddress", 6, 0, - NULL, &_ifSpeed_obj -}, -_ifAdminStatus_obj = { - "ifAdminStatus", 7, 0, - NULL, &_ifPhysAddress_obj -}, -_ifOperStatus_obj = { - "ifOperStatus", 8, 0, - NULL, &_ifAdminStatus_obj -}, -_ifLastChange_obj = { - "ifLastChange", 9, 0, - NULL, &_ifOperStatus_obj -}, -_ifInOctets_obj = { - "ifInOctets", 10, 0, - NULL, &_ifLastChange_obj -}, -_ifInUcastPkts_obj = { - "ifInUcastPkts", 11, 0, - NULL, &_ifInOctets_obj -}, -_ifInNUcastPkts_obj = { - "ifInNUcastPkts", 12, 0, - NULL, &_ifInUcastPkts_obj -}, -_ifInDiscards_obj = { - "ifInDiscards", 13, 0, - NULL, &_ifInNUcastPkts_obj -}, -_ifInErrors_obj = { - "ifInErrors", 14, 0, - NULL, &_ifInDiscards_obj -}, -_ifInUnknownProtos_obj = { - "ifInUnknownProtos", 15, 0, - NULL, &_ifInErrors_obj -}, -_ifOutOctets_obj = { - "ifOutOctets", 16, 0, - NULL, &_ifInUnknownProtos_obj -}, -_ifOutUcastPkts_obj = { - "ifOutUcastPkts", 17, 0, - NULL, &_ifOutOctets_obj -}, -_ifOutNUcastPkts_obj = { - "ifOutNUcastPkts", 18, 0, - NULL, &_ifOutUcastPkts_obj -}, -_ifOutDiscards_obj = { - "ifOutDiscards", 19, 0, - NULL, &_ifOutNUcastPkts_obj -}, -_ifOutErrors_obj = { - "ifOutErrors", 20, 0, - NULL, &_ifOutDiscards_obj -}, -_ifOutQLen_obj = { - "ifOutQLen", 21, 0, - NULL, &_ifOutErrors_obj -}, -_ifSpecific_obj = { - "ifSpecific", 22, 0, - NULL, &_ifOutQLen_obj -}, -_ifEntry_obj = { - "ifEntry", 1, 0, - &_ifSpecific_obj, NULL -}, -_ifNumber_obj = { - "ifNumber", 1, 0, - NULL, NULL -}, -_ifTable_obj = { - "ifTable", 2, 0, - &_ifEntry_obj, &_ifNumber_obj -}, -_sysDescr_obj = { - "sysDescr", 1, 0, - NULL, NULL -}, -_sysObjectID_obj = { - "sysObjectID", 2, 0, - NULL, &_sysDescr_obj -}, -_sysUpTime_obj = { - "sysUpTime", 3, 0, - NULL, &_sysObjectID_obj -}, -_sysContact_obj = { - "sysContact", 4, 0, - NULL, &_sysUpTime_obj -}, -_sysName_obj = { - "sysName", 5, 0, - NULL, &_sysContact_obj -}, -_sysLocation_obj = { - "sysLocation", 6, 0, - NULL, &_sysName_obj -}, -_sysServices_obj = { - "sysServices", 7, 0, - NULL, &_sysLocation_obj -}, -_system_obj = { - "system", 1, 0, - &_sysServices_obj, NULL -}, -_interfaces_obj = { - "interfaces", 2, 0, - &_ifTable_obj, &_system_obj -}, -_at_obj = { - "at", 3, 0, - &_atTable_obj, &_interfaces_obj -}, -_ip_obj = { - "ip", 4, 0, - &_ipNetToMediaTable_obj, &_at_obj -}, -_icmp_obj = { - "icmp", 5, 0, - &_icmpOutAddrMaskReps_obj, &_ip_obj -}, -_tcp_obj = { - "tcp", 6, 0, - &_tcpOutRsts_obj, &_icmp_obj -}, -_udp_obj = { - "udp", 7, 0, - &_udpTable_obj, &_tcp_obj -}, -_egp_obj = { - "egp", 8, 0, - &_egpAs_obj, &_udp_obj -}, -_transmission_obj = { - "transmission", 10, 0, - NULL, &_egp_obj -}, -_snmp_obj = { - "snmp", 11, 0, - &_snmpEnableAuthTraps_obj, &_transmission_obj -}, -_mib_obj = { - "mib", 1, 0, - &_snmp_obj, NULL -}, -_directory_obj = { - "directory", 1, 0, - NULL, NULL -}, -_mgmt_obj = { - "mgmt", 2, 0, - &_mib_obj, &_directory_obj -}, -_experimental_obj = { - "experimental", 3, 0, - NULL, &_mgmt_obj -}, -_private_obj = { - "private", 4, 0, - &_enterprises_obj, &_experimental_obj -}, -_internet_obj = { - "internet", 1, 0, - &_private_obj, NULL -}, -_dod_obj = { - "dod", 6, 0, - &_internet_obj, NULL -}, -_org_obj = { - "org", 3, 0, - &_dod_obj, NULL -}, -_iso_obj = { - "iso", 1, 0, - &_org_obj, NULL -}, -*mibroot = &_iso_obj; diff --git a/tcpdump.tproj/netbios.h b/tcpdump.tproj/netbios.h deleted file mode 100644 index 629e5a5..0000000 --- a/tcpdump.tproj/netbios.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * NETBIOS protocol formats - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/netbios.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez 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/tcpdump.tproj/nfs.h b/tcpdump.tproj/nfs.h deleted file mode 100644 index a45e1ce..0000000 --- a/tcpdump.tproj/nfs.h +++ /dev/null @@ -1,470 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: nfs.h,v 1.2 1996/07/13 11:01:12 mickey Exp $ */ -/* $NetBSD: nfs.h,v 1.1 1996/05/23 22:49:53 fvdl Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Rick Macklem at The University of Guelph. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)nfsproto.h 8.2 (Berkeley) 3/30/95 - */ - -/* - * nfs definitions as per the Version 2 and 3 specs - */ - -/* - * Constants as defined in the Sun NFS Version 2 and 3 specs. - * "NFS: Network File System Protocol Specification" RFC1094 - * and in the "NFS: Network File System Version 3 Protocol - * Specification" - */ - -#define NFS_PORT 2049 -#define NFS_PROG 100003 -#define NFS_VER2 2 -#define NFS_VER3 3 -#define NFS_V2MAXDATA 8192 -#define NFS_MAXDGRAMDATA 16384 -#define NFS_MAXDATA 32768 -#define NFS_MAXPATHLEN 1024 -#define NFS_MAXNAMLEN 255 -#define NFS_MAXPKTHDR 404 -#define NFS_MAXPACKET (NFS_MAXPKTHDR + NFS_MAXDATA) -#define NFS_MINPACKET 20 -#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ - -/* Stat numbers for rpc returns (version 2 and 3) */ -#define NFS_OK 0 -#define NFSERR_PERM 1 -#define NFSERR_NOENT 2 -#define NFSERR_IO 5 -#define NFSERR_NXIO 6 -#define NFSERR_ACCES 13 -#define NFSERR_EXIST 17 -#define NFSERR_XDEV 18 /* Version 3 only */ -#define NFSERR_NODEV 19 -#define NFSERR_NOTDIR 20 -#define NFSERR_ISDIR 21 -#define NFSERR_INVAL 22 /* Version 3 only */ -#define NFSERR_FBIG 27 -#define NFSERR_NOSPC 28 -#define NFSERR_ROFS 30 -#define NFSERR_MLINK 31 /* Version 3 only */ -#define NFSERR_NAMETOL 63 -#define NFSERR_NOTEMPTY 66 -#define NFSERR_DQUOT 69 -#define NFSERR_STALE 70 -#define NFSERR_REMOTE 71 /* Version 3 only */ -#define NFSERR_WFLUSH 99 /* Version 2 only */ -#define NFSERR_BADHANDLE 10001 /* The rest Version 3 only */ -#define NFSERR_NOT_SYNC 10002 -#define NFSERR_BAD_COOKIE 10003 -#define NFSERR_NOTSUPP 10004 -#define NFSERR_TOOSMALL 10005 -#define NFSERR_SERVERFAULT 10006 -#define NFSERR_BADTYPE 10007 -#define NFSERR_JUKEBOX 10008 -#define NFSERR_TRYLATER NFSERR_JUKEBOX -#define NFSERR_STALEWRITEVERF 30001 /* Fake return for nfs_commit() */ - -#define NFSERR_RETVOID 0x20000000 /* Return void, not error */ -#define NFSERR_AUTHERR 0x40000000 /* Mark an authentication error */ -#define NFSERR_RETERR 0x80000000 /* Mark an error return for V3 */ - -/* Sizes in bytes of various nfs rpc components */ -#define NFSX_UNSIGNED 4 - -/* specific to NFS Version 2 */ -#define NFSX_V2FH 32 -#define NFSX_V2FATTR 68 -#define NFSX_V2SATTR 32 -#define NFSX_V2COOKIE 4 -#define NFSX_V2STATFS 20 - -/* specific to NFS Version 3 */ -#if 0 -#define NFSX_V3FH (sizeof (fhandle_t)) /* size this server uses */ -#endif -#define NFSX_V3FHMAX 64 /* max. allowed by protocol */ -#define NFSX_V3FATTR 84 -#define NFSX_V3SATTR 60 /* max. all fields filled in */ -#define NFSX_V3SRVSATTR (sizeof (struct nfsv3_sattr)) -#define NFSX_V3POSTOPATTR (NFSX_V3FATTR + NFSX_UNSIGNED) -#define NFSX_V3WCCDATA (NFSX_V3POSTOPATTR + 8 * NFSX_UNSIGNED) -#define NFSX_V3COOKIEVERF 8 -#define NFSX_V3WRITEVERF 8 -#define NFSX_V3CREATEVERF 8 -#define NFSX_V3STATFS 52 -#define NFSX_V3FSINFO 48 -#define NFSX_V3PATHCONF 24 - -/* variants for both versions */ -#define NFSX_FH(v3) ((v3) ? (NFSX_V3FHMAX + NFSX_UNSIGNED) : \ - NFSX_V2FH) -#define NFSX_SRVFH(v3) ((v3) ? NFSX_V3FH : NFSX_V2FH) -#define NFSX_FATTR(v3) ((v3) ? NFSX_V3FATTR : NFSX_V2FATTR) -#define NFSX_PREOPATTR(v3) ((v3) ? (7 * NFSX_UNSIGNED) : 0) -#define NFSX_POSTOPATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : 0) -#define NFSX_POSTOPORFATTR(v3) ((v3) ? (NFSX_V3FATTR + NFSX_UNSIGNED) : \ - NFSX_V2FATTR) -#define NFSX_WCCDATA(v3) ((v3) ? NFSX_V3WCCDATA : 0) -#define NFSX_WCCORFATTR(v3) ((v3) ? NFSX_V3WCCDATA : NFSX_V2FATTR) -#define NFSX_SATTR(v3) ((v3) ? NFSX_V3SATTR : NFSX_V2SATTR) -#define NFSX_COOKIEVERF(v3) ((v3) ? NFSX_V3COOKIEVERF : 0) -#define NFSX_WRITEVERF(v3) ((v3) ? NFSX_V3WRITEVERF : 0) -#define NFSX_READDIR(v3) ((v3) ? (5 * NFSX_UNSIGNED) : \ - (2 * NFSX_UNSIGNED)) -#define NFSX_STATFS(v3) ((v3) ? NFSX_V3STATFS : NFSX_V2STATFS) - -/* nfs rpc procedure numbers (before version mapping) */ -#define NFSPROC_NULL 0 -#define NFSPROC_GETATTR 1 -#define NFSPROC_SETATTR 2 -#define NFSPROC_LOOKUP 3 -#define NFSPROC_ACCESS 4 -#define NFSPROC_READLINK 5 -#define NFSPROC_READ 6 -#define NFSPROC_WRITE 7 -#define NFSPROC_CREATE 8 -#define NFSPROC_MKDIR 9 -#define NFSPROC_SYMLINK 10 -#define NFSPROC_MKNOD 11 -#define NFSPROC_REMOVE 12 -#define NFSPROC_RMDIR 13 -#define NFSPROC_RENAME 14 -#define NFSPROC_LINK 15 -#define NFSPROC_READDIR 16 -#define NFSPROC_READDIRPLUS 17 -#define NFSPROC_FSSTAT 18 -#define NFSPROC_FSINFO 19 -#define NFSPROC_PATHCONF 20 -#define NFSPROC_COMMIT 21 - -/* And leasing (nqnfs) procedure numbers (must be last) */ -#define NQNFSPROC_GETLEASE 22 -#define NQNFSPROC_VACATED 23 -#define NQNFSPROC_EVICTED 24 - -#define NFSPROC_NOOP 25 -#define NFS_NPROCS 26 - -/* Actual Version 2 procedure numbers */ -#define NFSV2PROC_NULL 0 -#define NFSV2PROC_GETATTR 1 -#define NFSV2PROC_SETATTR 2 -#define NFSV2PROC_NOOP 3 -#define NFSV2PROC_ROOT NFSV2PROC_NOOP /* Obsolete */ -#define NFSV2PROC_LOOKUP 4 -#define NFSV2PROC_READLINK 5 -#define NFSV2PROC_READ 6 -#define NFSV2PROC_WRITECACHE NFSV2PROC_NOOP /* Obsolete */ -#define NFSV2PROC_WRITE 8 -#define NFSV2PROC_CREATE 9 -#define NFSV2PROC_REMOVE 10 -#define NFSV2PROC_RENAME 11 -#define NFSV2PROC_LINK 12 -#define NFSV2PROC_SYMLINK 13 -#define NFSV2PROC_MKDIR 14 -#define NFSV2PROC_RMDIR 15 -#define NFSV2PROC_READDIR 16 -#define NFSV2PROC_STATFS 17 - -/* - * Constants used by the Version 3 protocol for various RPCs - */ -#define NFSV3SATTRTIME_DONTCHANGE 0 -#define NFSV3SATTRTIME_TOSERVER 1 -#define NFSV3SATTRTIME_TOCLIENT 2 - -#define NFSV3ATTRTIME_NMODES 3 - -#define NFSV3ACCESS_READ 0x01 -#define NFSV3ACCESS_LOOKUP 0x02 -#define NFSV3ACCESS_MODIFY 0x04 -#define NFSV3ACCESS_EXTEND 0x08 -#define NFSV3ACCESS_DELETE 0x10 -#define NFSV3ACCESS_EXECUTE 0x20 - -#define NFSV3WRITE_UNSTABLE 0 -#define NFSV3WRITE_DATASYNC 1 -#define NFSV3WRITE_FILESYNC 2 - -#define NFSV3WRITE_NMODES 3 - -#define NFSV3CREATE_UNCHECKED 0 -#define NFSV3CREATE_GUARDED 1 -#define NFSV3CREATE_EXCLUSIVE 2 - -#define NFSV3CREATE_NMODES 3 - -#define NFSV3FSINFO_LINK 0x01 -#define NFSV3FSINFO_SYMLINK 0x02 -#define NFSV3FSINFO_HOMOGENEOUS 0x08 -#define NFSV3FSINFO_CANSETTIME 0x10 - -/* Conversion macros */ -#define vtonfsv2_mode(t,m) \ - txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ - MAKEIMODE((t), (m))) -#define vtonfsv3_mode(m) txdr_unsigned((m) & 07777) -#define nfstov_mode(a) (fxdr_unsigned(u_int16_t, (a))&07777) -#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))]) -#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))]) -#define nfsv2tov_type(a) nv2tov_type[fxdr_unsigned(u_int32,(a))&0x7] -#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32,(a))&0x7] - -/* File types */ -typedef enum { NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5, - NFSOCK=6, NFFIFO=7 } nfstype; - -/* Structs for common parts of the rpc's */ -/* - * File Handle (32 bytes for version 2), variable up to 64 for version 3. - * File Handles of up to NFS_SMALLFH in size are stored directly in the - * nfs node, whereas larger ones are malloc'd. (This never happens when - * NFS_SMALLFH is set to 64.) - * NFS_SMALLFH should be in the range of 32 to 64 and be divisible by 4. - */ -#ifndef NFS_SMALLFH -#define NFS_SMALLFH 64 -#endif -union nfsfh { -/* fhandle_t fh_generic; */ - u_char fh_bytes[NFS_SMALLFH]; -}; -typedef union nfsfh nfsfh_t; - -struct nfsv2_time { - u_int32 nfsv2_sec; - u_int32 nfsv2_usec; -}; -typedef struct nfsv2_time nfstime2; - -struct nfsv3_time { - u_int32 nfsv3_sec; - u_int32 nfsv3_nsec; -}; -typedef struct nfsv3_time nfstime3; - -/* - * Quads are defined as arrays of 2 longs to ensure dense packing for the - * protocol and to facilitate xdr conversion. - */ -struct nfs_uquad { - u_int32 nfsuquad[2]; -}; -typedef struct nfs_uquad nfsuint64; - -/* - * Used to convert between two u_longs and a u_quad_t. - */ -union nfs_quadconvert { - u_int32 lval[2]; - u_quad_t qval; -}; -typedef union nfs_quadconvert nfsquad_t; - -/* - * NFS Version 3 special file number. - */ -struct nfsv3_spec { - u_int32 specdata1; - u_int32 specdata2; -}; -typedef struct nfsv3_spec nfsv3spec; - -/* - * File attributes and setable attributes. These structures cover both - * NFS version 2 and the version 3 protocol. Note that the union is only - * used so that one pointer can refer to both variants. These structures - * go out on the wire and must be densely packed, so no quad data types - * are used. (all fields are longs or u_longs or structures of same) - * NB: You can't do sizeof(struct nfs_fattr), you must use the - * NFSX_FATTR(v3) macro. - */ -struct nfs_fattr { - u_int32 fa_type; - u_int32 fa_mode; - u_int32 fa_nlink; - u_int32 fa_uid; - u_int32 fa_gid; - union { - struct { - u_int32 nfsv2fa_size; - u_int32 nfsv2fa_blocksize; - u_int32 nfsv2fa_rdev; - u_int32 nfsv2fa_blocks; - u_int32 nfsv2fa_fsid; - u_int32 nfsv2fa_fileid; - nfstime2 nfsv2fa_atime; - nfstime2 nfsv2fa_mtime; - nfstime2 nfsv2fa_ctime; - } fa_nfsv2; - struct { - nfsuint64 nfsv3fa_size; - nfsuint64 nfsv3fa_used; - nfsv3spec nfsv3fa_rdev; - nfsuint64 nfsv3fa_fsid; - nfsuint64 nfsv3fa_fileid; - nfstime3 nfsv3fa_atime; - nfstime3 nfsv3fa_mtime; - nfstime3 nfsv3fa_ctime; - } fa_nfsv3; - } fa_un; -}; - -/* and some ugly defines for accessing union components */ -#define fa2_size fa_un.fa_nfsv2.nfsv2fa_size -#define fa2_blocksize fa_un.fa_nfsv2.nfsv2fa_blocksize -#define fa2_rdev fa_un.fa_nfsv2.nfsv2fa_rdev -#define fa2_blocks fa_un.fa_nfsv2.nfsv2fa_blocks -#define fa2_fsid fa_un.fa_nfsv2.nfsv2fa_fsid -#define fa2_fileid fa_un.fa_nfsv2.nfsv2fa_fileid -#define fa2_atime fa_un.fa_nfsv2.nfsv2fa_atime -#define fa2_mtime fa_un.fa_nfsv2.nfsv2fa_mtime -#define fa2_ctime fa_un.fa_nfsv2.nfsv2fa_ctime -#define fa3_size fa_un.fa_nfsv3.nfsv3fa_size -#define fa3_used fa_un.fa_nfsv3.nfsv3fa_used -#define fa3_rdev fa_un.fa_nfsv3.nfsv3fa_rdev -#define fa3_fsid fa_un.fa_nfsv3.nfsv3fa_fsid -#define fa3_fileid fa_un.fa_nfsv3.nfsv3fa_fileid -#define fa3_atime fa_un.fa_nfsv3.nfsv3fa_atime -#define fa3_mtime fa_un.fa_nfsv3.nfsv3fa_mtime -#define fa3_ctime fa_un.fa_nfsv3.nfsv3fa_ctime - -struct nfsv2_sattr { - u_int32 sa_mode; - u_int32 sa_uid; - u_int32 sa_gid; - u_int32 sa_size; - nfstime2 sa_atime; - nfstime2 sa_mtime; -}; - -/* - * NFS Version 3 sattr structure for the new node creation case. - */ -struct nfsv3_sattr { - u_int32 sa_modeset; - u_int32 sa_mode; - u_int32 sa_uidset; - u_int32 sa_uid; - u_int32 sa_gidset; - u_int32 sa_gid; - u_int32 sa_sizeset; - u_int32 sa_size; - u_int32 sa_atimetype; - nfstime3 sa_atime; - u_int32 sa_mtimetype; - nfstime3 sa_mtime; -}; - -struct nfs_statfs { - union { - struct { - u_int32 nfsv2sf_tsize; - u_int32 nfsv2sf_bsize; - u_int32 nfsv2sf_blocks; - u_int32 nfsv2sf_bfree; - u_int32 nfsv2sf_bavail; - } sf_nfsv2; - struct { - nfsuint64 nfsv3sf_tbytes; - nfsuint64 nfsv3sf_fbytes; - nfsuint64 nfsv3sf_abytes; - nfsuint64 nfsv3sf_tfiles; - nfsuint64 nfsv3sf_ffiles; - nfsuint64 nfsv3sf_afiles; - u_int32 nfsv3sf_invarsec; - } sf_nfsv3; - } sf_un; -}; - -#define sf_tsize sf_un.sf_nfsv2.nfsv2sf_tsize -#define sf_bsize sf_un.sf_nfsv2.nfsv2sf_bsize -#define sf_blocks sf_un.sf_nfsv2.nfsv2sf_blocks -#define sf_bfree sf_un.sf_nfsv2.nfsv2sf_bfree -#define sf_bavail sf_un.sf_nfsv2.nfsv2sf_bavail -#define sf_tbytes sf_un.sf_nfsv3.nfsv3sf_tbytes -#define sf_fbytes sf_un.sf_nfsv3.nfsv3sf_fbytes -#define sf_abytes sf_un.sf_nfsv3.nfsv3sf_abytes -#define sf_tfiles sf_un.sf_nfsv3.nfsv3sf_tfiles -#define sf_ffiles sf_un.sf_nfsv3.nfsv3sf_ffiles -#define sf_afiles sf_un.sf_nfsv3.nfsv3sf_afiles -#define sf_invarsec sf_un.sf_nfsv3.nfsv3sf_invarsec - -struct nfsv3_fsinfo { - u_int32 fs_rtmax; - u_int32 fs_rtpref; - u_int32 fs_rtmult; - u_int32 fs_wtmax; - u_int32 fs_wtpref; - u_int32 fs_wtmult; - u_int32 fs_dtpref; - nfsuint64 fs_maxfilesize; - nfstime3 fs_timedelta; - u_int32 fs_properties; -}; - -struct nfsv3_pathconf { - u_int32 pc_linkmax; - u_int32 pc_namemax; - u_int32 pc_notrunc; - u_int32 pc_chownrestricted; - u_int32 pc_caseinsensitive; - u_int32 pc_casepreserving; -}; diff --git a/tcpdump.tproj/nfsfh.h b/tcpdump.tproj/nfsfh.h deleted file mode 100644 index f354eec..0000000 --- a/tcpdump.tproj/nfsfh.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/nfsfh.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ - * - * nfsfh.h - NFS file handle definitions (for portable use) - * - * Jeffrey C. Mogul - * Digital Equipment Corporation - * Western Research Laboratory - */ - -/* - * Internal representation of dev_t, because different NFS servers - * that we might be spying upon use different external representations. - */ -typedef struct { - u_int32_t Minor; /* upper case to avoid clashing with macro names */ - u_int32_t Major; -} my_devt; - -#define dev_eq(a,b) ((a.Minor == b.Minor) && (a.Major == b.Major)) - -/* - * Many file servers now use a large file system ID. This is - * our internal representation of that. - */ -typedef struct { - my_devt Fsid_dev; /* XXX avoid name conflict with AIX */ - u_int32_t fsid_code; -} my_fsid; - -#define fsid_eq(a,b) ((a.fsid_code == b.fsid_code) &&\ - dev_eq(a.fsid_dev, b.fsid_dev)) - -extern void Parse_fh(caddr_t *, my_fsid *, ino_t *, char **, char **, int); diff --git a/tcpdump.tproj/nfsv2.h b/tcpdump.tproj/nfsv2.h deleted file mode 100644 index d991ddc..0000000 --- a/tcpdump.tproj/nfsv2.h +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1994, 1995, 1996 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Rick Macklem at The University of Guelph. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)nfsv2.h 7.11 (Berkeley) 9/30/92 - */ - -/* - * nfs definitions as per the version 2 specs - */ - -/* - * Constants as defined in the Sun NFS Version 2 spec. - * "NFS: Network File System Protocol Specification" RFC1094 - */ - -#define NFS_PORT 2049 -#define NFS_PROG 100003 -#define NFS_VER2 2 -#define NFS_MAXDGRAMDATA 8192 -#define NFS_MAXDATA 32768 -#define NFS_MAXPATHLEN 1024 -#define NFS_MAXNAMLEN 255 -#define NFS_FHSIZE 32 -#define NFS_MAXPKTHDR 404 -#define NFS_MAXPACKET (NFS_MAXPKTHDR+NFS_MAXDATA) -#define NFS_MINPACKET 20 -#define NFS_FABLKSIZE 512 /* Size in bytes of a block wrt fa_blocks */ - -/* Stat numbers for rpc returns */ -#define NFS_OK 0 -#define NFSERR_PERM 1 -#define NFSERR_NOENT 2 -#define NFSERR_IO 5 -#define NFSERR_NXIO 6 -#define NFSERR_ACCES 13 -#define NFSERR_EXIST 17 -#define NFSERR_NODEV 19 -#define NFSERR_NOTDIR 20 -#define NFSERR_ISDIR 21 -#define NFSERR_FBIG 27 -#define NFSERR_NOSPC 28 -#define NFSERR_ROFS 30 -#define NFSERR_NAMETOL 63 -#define NFSERR_NOTEMPTY 66 -#define NFSERR_DQUOT 69 -#define NFSERR_STALE 70 -#define NFSERR_WFLUSH 99 - -/* Sizes in bytes of various nfs rpc components */ -#define NFSX_FH 32 -#define NFSX_UNSIGNED 4 -#define NFSX_NFSFATTR 68 -#define NFSX_NQFATTR 92 -#define NFSX_NFSSATTR 32 -#define NFSX_NQSATTR 44 -#define NFSX_COOKIE 4 -#define NFSX_NFSSTATFS 20 -#define NFSX_NQSTATFS 28 -#define NFSX_FATTR(isnq) ((isnq) ? NFSX_NQFATTR : NFSX_NFSFATTR) -#define NFSX_SATTR(isnq) ((isnq) ? NFSX_NQSATTR : NFSX_NFSSATTR) -#define NFSX_STATFS(isnq) ((isnq) ? NFSX_NQSTATFS : NFSX_NFSSTATFS) - -/* nfs rpc procedure numbers */ -#define NFSPROC_NULL 0 -#define NFSPROC_GETATTR 1 -#define NFSPROC_SETATTR 2 -#define NFSPROC_NOOP 3 -#define NFSPROC_ROOT NFSPROC_NOOP /* Obsolete */ -#define NFSPROC_LOOKUP 4 -#define NFSPROC_READLINK 5 -#define NFSPROC_READ 6 -#define NFSPROC_WRITECACHE NFSPROC_NOOP /* Obsolete */ -#define NFSPROC_WRITE 8 -#define NFSPROC_CREATE 9 -#define NFSPROC_REMOVE 10 -#define NFSPROC_RENAME 11 -#define NFSPROC_LINK 12 -#define NFSPROC_SYMLINK 13 -#define NFSPROC_MKDIR 14 -#define NFSPROC_RMDIR 15 -#define NFSPROC_READDIR 16 -#define NFSPROC_STATFS 17 - -/* NQ nfs numbers */ -#define NQNFSPROC_READDIRLOOK 18 -#define NQNFSPROC_GETLEASE 19 -#define NQNFSPROC_VACATED 20 -#define NQNFSPROC_EVICTED 21 -#define NQNFSPROC_ACCESS 22 - -#define NFS_NPROCS 23 -/* Conversion macros */ -extern int vttoif_tab[]; -#define vtonfs_mode(t,m) \ - txdr_unsigned(((t) == VFIFO) ? MAKEIMODE(VCHR, (m)) : \ - MAKEIMODE((t), (m))) -#define nfstov_mode(a) (fxdr_unsigned(u_short, (a))&07777) -#define vtonfs_type(a) txdr_unsigned(nfs_type[((int32_t)(a))]) -#define nfstov_type(a) ntov_type[fxdr_unsigned(u_int32_t,(a))&0x7] - -/* File types */ -typedef enum { - NFNON=0, NFREG=1, NFDIR=2, NFBLK=3, NFCHR=4, NFLNK=5 -} tcpdump_nfstype; - -/* Structs for common parts of the rpc's */ -struct nfsv2_time { - u_int32_t nfs_sec; - u_int32_t nfs_usec; -}; - -struct nqnfs_time { - u_int32_t nq_sec; - u_int32_t nq_nsec; -}; - -/* - * File attributes and setable attributes. These structures cover both - * NFS version 2 and the NQNFS protocol. Note that the union is only - * used to that one pointer can refer to both variants. These structures - * go out on the wire and must be densely packed, so no quad data types - * are used. (all fields are int32_t or u_int32_t's or structures of same) - * NB: You can't do sizeof(struct nfsv2_fattr), you must use the - * NFSX_FATTR(isnq) macro. - */ -struct nfsv2_fattr { - u_int32_t fa_type; - u_int32_t fa_mode; - u_int32_t fa_nlink; - u_int32_t fa_uid; - u_int32_t fa_gid; - union { - struct { - u_int32_t nfsfa_size; - u_int32_t nfsfa_blocksize; - u_int32_t nfsfa_rdev; - u_int32_t nfsfa_blocks; - u_int32_t nfsfa_fsid; - u_int32_t nfsfa_fileid; - struct nfsv2_time nfsfa_atime; - struct nfsv2_time nfsfa_mtime; - struct nfsv2_time nfsfa_ctime; - } fa_nfsv2; - struct { - struct { - u_int32_t nqfa_qsize[2]; - } nqfa_size; - u_int32_t nqfa_blocksize; - u_int32_t nqfa_rdev; - struct { - u_int32_t nqfa_qbytes[2]; - } nqfa_bytes; - u_int32_t nqfa_fsid; - u_int32_t nqfa_fileid; - struct nqnfs_time nqfa_atime; - struct nqnfs_time nqfa_mtime; - struct nqnfs_time nqfa_ctime; - u_int32_t nqfa_flags; - u_int32_t nqfa_gen; - struct { - u_int32_t nqfa_qfilerev[2]; - } nqfa_filerev; - } fa_nqnfs; - } fa_un; -}; - -/* and some ugly defines for accessing union components */ -#define fa_nfssize fa_un.fa_nfsv2.nfsfa_size -#define fa_nfsblocksize fa_un.fa_nfsv2.nfsfa_blocksize -#define fa_nfsrdev fa_un.fa_nfsv2.nfsfa_rdev -#define fa_nfsblocks fa_un.fa_nfsv2.nfsfa_blocks -#define fa_nfsfsid fa_un.fa_nfsv2.nfsfa_fsid -#define fa_nfsfileid fa_un.fa_nfsv2.nfsfa_fileid -#define fa_nfsatime fa_un.fa_nfsv2.nfsfa_atime -#define fa_nfsmtime fa_un.fa_nfsv2.nfsfa_mtime -#define fa_nfsctime fa_un.fa_nfsv2.nfsfa_ctime -#define fa_nqsize fa_un.fa_nqnfs.nqfa_size -#define fa_nqblocksize fa_un.fa_nqnfs.nqfa_blocksize -#define fa_nqrdev fa_un.fa_nqnfs.nqfa_rdev -#define fa_nqbytes fa_un.fa_nqnfs.nqfa_bytes -#define fa_nqfsid fa_un.fa_nqnfs.nqfa_fsid -#define fa_nqfileid fa_un.fa_nqnfs.nqfa_fileid -#define fa_nqatime fa_un.fa_nqnfs.nqfa_atime -#define fa_nqmtime fa_un.fa_nqnfs.nqfa_mtime -#define fa_nqctime fa_un.fa_nqnfs.nqfa_ctime -#define fa_nqflags fa_un.fa_nqnfs.nqfa_flags -#define fa_nqgen fa_un.fa_nqnfs.nqfa_gen -#define fa_nqfilerev fa_un.fa_nqnfs.nqfa_filerev - -struct nfsv2_sattr { - u_int32_t sa_mode; - u_int32_t sa_uid; - u_int32_t sa_gid; - union { - struct { - u_int32_t nfssa_size; - struct nfsv2_time nfssa_atime; - struct nfsv2_time nfssa_mtime; - } sa_nfsv2; - struct { - struct { - u_int32_t nqsa_qsize[2]; - } nqsa_size; - struct nqnfs_time nqsa_atime; - struct nqnfs_time nqsa_mtime; - u_int32_t nqsa_flags; - u_int32_t nqsa_rdev; - } sa_nqnfs; - } sa_un; -}; - -/* and some ugly defines for accessing the unions */ -#define sa_nfssize sa_un.sa_nfsv2.nfssa_size -#define sa_nfsatime sa_un.sa_nfsv2.nfssa_atime -#define sa_nfsmtime sa_un.sa_nfsv2.nfssa_mtime -#define sa_nqsize sa_un.sa_nqnfs.nqsa_size -#define sa_nqatime sa_un.sa_nqnfs.nqsa_atime -#define sa_nqmtime sa_un.sa_nqnfs.nqsa_mtime -#define sa_nqflags sa_un.sa_nqnfs.nqsa_flags -#define sa_nqrdev sa_un.sa_nqnfs.nqsa_rdev - -struct nfsv2_statfs { - u_int32_t sf_tsize; - u_int32_t sf_bsize; - u_int32_t sf_blocks; - u_int32_t sf_bfree; - u_int32_t sf_bavail; - u_int32_t sf_files; /* Nqnfs only */ - u_int32_t sf_ffree; /* ditto */ -}; diff --git a/tcpdump.tproj/ntp.h b/tcpdump.tproj/ntp.h deleted file mode 100644 index dd69af9..0000000 --- a/tcpdump.tproj/ntp.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/ntp.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ */ - -/* - * Based on ntp.h from the U of MD implementation - * This file is based on Version 2 of the NTP spec (RFC1119). - */ - -/* - * Definitions for the masses - */ -#define JAN_1970 2208988800 /* 1970 - 1900 in seconds */ - -/* - * Structure definitions for NTP fixed point values - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Integer Part | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Fraction Part | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Integer Part | Fraction Part | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -*/ -struct l_fixedpt { - u_int32_t int_part; - u_int32_t fraction; -}; - -struct s_fixedpt { - u_short int_part; - u_short fraction; -}; - -/* ================= Table 3.3. Packet Variables ================= */ -/* - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * |LI | VN | Mode| Stratum | Poll | Precision | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Synchronizing Distance | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Synchronizing Dispersion | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Reference Clock Identifier | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * | Reference Timestamp (64 bits) | - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * | Originate Timestamp (64 bits) | - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * | Receive Timestamp (64 bits) | - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * | Transmit Timestamp (64 bits) | - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -*/ -struct ntpdata { - u_char status; /* status of local clock and leap info */ - u_char stratum; /* Stratum level */ - u_char ppoll; /* poll value */ - int precision:8; - struct s_fixedpt distance; - struct s_fixedpt dispersion; - u_int32_t refid; - struct l_fixedpt reftime; - struct l_fixedpt org; - struct l_fixedpt rec; - struct l_fixedpt xmt; -}; -/* - * Leap Second Codes (high order two bits) - */ -#define NO_WARNING 0x00 /* no warning */ -#define PLUS_SEC 0x40 /* add a second (61 seconds) */ -#define MINUS_SEC 0x80 /* minus a second (59 seconds) */ -#define ALARM 0xc0 /* alarm condition (clock unsynchronized) */ - -/* - * Clock Status Bits that Encode Version - */ -#define NTPVERSION_1 0x08 -#define VERSIONMASK 0x38 -#define LEAPMASK 0xc0 -#define MODEMASK 0x07 - -/* - * Code values - */ -#define MODE_UNSPEC 0 /* unspecified */ -#define MODE_SYM_ACT 1 /* symmetric active */ -#define MODE_SYM_PAS 2 /* symmetric passive */ -#define MODE_CLIENT 3 /* client */ -#define MODE_SERVER 4 /* server */ -#define MODE_BROADCAST 5 /* broadcast */ -#define MODE_RES1 6 /* reserved */ -#define MODE_RES2 7 /* reserved */ - -/* - * Stratum Definitions - */ -#define UNSPECIFIED 0 -#define PRIM_REF 1 /* radio clock */ -#define INFO_QUERY 62 /* **** THIS implementation dependent **** */ -#define INFO_REPLY 63 /* **** THIS implementation dependent **** */ diff --git a/tcpdump.tproj/os-solaris2.h b/tcpdump.tproj/os-solaris2.h deleted file mode 100644 index 440d65c..0000000 --- a/tcpdump.tproj/os-solaris2.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1993, 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. - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/os-solaris2.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL) - */ - -/* Prototypes missing in SunOS 5 */ -int daemon(int, int); -int dn_expand(u_char *, u_char *, u_char *, u_char *, int); -int dn_skipname(u_char *, u_char *); -int flock(int, int); -int getdtablesize(void); -int gethostname(char *, int); -int getpagesize(void); -char *getusershell(void); -char *getwd(char *); -int iruserok(u_int, int, char *, char *); -#ifdef __STDC__ -struct utmp; -void login(struct utmp *); -#endif -int logout(const char *); -int res_query(char *, int, int, u_char *, int); -int setenv(const char *, const char *, int); -#if defined(_STDIO_H) && defined(HAVE_SETLINEBUF) -int setlinebuf(FILE *); -#endif -int sigblock(int); -int sigsetmask(int); -char *strerror(int); -int snprintf(char *, size_t, const char *, ...); -int strcasecmp(const char *, const char *); -void unsetenv(const char *); -#ifdef __STDC__ -struct timeval; -#endif -int utimes(const char *, struct timeval *); diff --git a/tcpdump.tproj/os-sunos4.h b/tcpdump.tproj/os-sunos4.h deleted file mode 100644 index 01389d1..0000000 --- a/tcpdump.tproj/os-sunos4.h +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1989, 1990, 1993, 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. - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/os-sunos4.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL) - */ - -/* Prototypes missing in SunOS 4 */ -#ifdef FILE -int _filbuf(FILE *); -int _flsbuf(u_char, FILE *); -int fclose(FILE *); -int fflush(FILE *); -int fgetc(FILE *); -int fprintf(FILE *, const char *, ...); -int fputc(int, FILE *); -int fputs(const char *, FILE *); -u_int fread(void *, u_int, u_int, FILE *); -int fseek(FILE *, long, int); -u_int fwrite(const void *, u_int, u_int, FILE *); -int pclose(FILE *); -void rewind(FILE *); -void setbuf(FILE *, char *); -int setlinebuf(FILE *); -int ungetc(int, FILE *); -int vfprintf(FILE *, const char *, ...); -int vprintf(const char *, ...); -#endif - -#if __GNUC__ <= 1 -int read(int, char *, u_int); -int write(int, char *, u_int); -#endif - -long a64l(const char *); -#ifdef __STDC__ -struct sockaddr; -#endif -int accept(int, struct sockaddr *, int *); -int bind(int, struct sockaddr *, int); -int bcmp(const void *, const void *, u_int); -void bcopy(const void *, void *, u_int); -void bzero(void *, int); -int chroot(const char *); -int close(int); -void closelog(void); -int connect(int, struct sockaddr *, int); -char *crypt(const char *, const char *); -int daemon(int, int); -int fchmod(int, int); -int fchown(int, int, int); -void endgrent(void); -void endpwent(void); -void endservent(void); -#ifdef __STDC__ -struct ether_addr; -#endif -struct ether_addr *ether_aton(const char *); -int flock(int, int); -#ifdef __STDC__ -struct stat; -#endif -int fstat(int, struct stat *); -#ifdef __STDC__ -struct statfs; -#endif -int fstatfs(int, struct statfs *); -int fsync(int); -#ifdef __STDC__ -struct timeb; -#endif -int ftime(struct timeb *); -int ftruncate(int, off_t); -int getdtablesize(void); -long gethostid(void); -int gethostname(char *, int); -int getopt(int, char * const *, const char *); -int getpagesize(void); -char *getpass(char *); -int getpeername(int, struct sockaddr *, int *); -int getpriority(int, int); -#ifdef __STDC__ -struct rlimit; -#endif -int getrlimit(int, struct rlimit *); -int getsockname(int, struct sockaddr *, int *); -int getsockopt(int, int, int, char *, int *); -#ifdef __STDC__ -struct timeval; -struct timezone; -#endif -int gettimeofday(struct timeval *, struct timezone *); -char *getusershell(void); -char *getwd(char *); -int initgroups(const char *, int); -int ioctl(int, int, caddr_t); -int iruserok(u_long, int, char *, char *); -int isatty(int); -int killpg(int, int); -int listen(int, int); -#ifdef __STDC__ -struct utmp; -#endif -void login(struct utmp *); -int logout(const char *); -off_t lseek(int, off_t, int); -int lstat(const char *, struct stat *); -int mkstemp(char *); -char *mktemp(char *); -int munmap(caddr_t, int); -void openlog(const char *, int, int); -void perror(const char *); -int printf(const char *, ...); -int puts(const char *); -long random(void); -int readlink(const char *, char *, int); -#ifdef __STDC__ -struct iovec; -#endif -int readv(int, struct iovec *, int); -int recv(int, char *, u_int, int); -int recvfrom(int, char *, u_int, int, struct sockaddr *, int *); -int rename(const char *, const char *); -int rcmd(char **, u_short, char *, char *, char *, int *); -int rresvport(int *); -int send(int, char *, u_int, int); -int sendto(int, char *, u_int, int, struct sockaddr *, int); -int setenv(const char *, const char *, int); -int seteuid(int); -int setpriority(int, int, int); -int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); -int setpgrp(int, int); -void setpwent(void); -int setrlimit(int, struct rlimit *); -void setservent(int); -int setsockopt(int, int, int, char *, int); -int shutdown(int, int); -int sigblock(int); -void (*signal (int, void (*) (int))) (int); -int sigpause(int); -int sigsetmask(int); -#ifdef __STDC__ -struct sigvec; -#endif -int sigvec(int, struct sigvec *, struct sigvec*); -int snprintf(char *, size_t, const char *, ...); -int socket(int, int, int); -int socketpair(int, int, int, int *); -int symlink(const char *, const char *); -void srandom(int); -int sscanf(char *, const char *, ...); -int stat(const char *, struct stat *); -int statfs(char *, struct statfs *); -char *strerror(int); -int strcasecmp(const char *, const char *); -#ifdef __STDC__ -struct tm; -#endif -int strftime(char *, int, char *, struct tm *); -int strncasecmp(const char *, const char *, int); -long strtol(const char *, char **, int); -void sync(void); -void syslog(int, const char *, ...); -int system(const char *); -long tell(int); -time_t time(time_t *); -char *timezone(int, int); -int tolower(int); -int toupper(int); -int truncate(char *, off_t); -void unsetenv(const char *); -int vfork(void); -int vsprintf(char *, const char *, ...); -int writev(int, struct iovec *, int); -#ifdef __STDC__ -struct rusage; -#endif -int utimes(const char *, struct timeval *); -#if __GNUC__ <= 1 -int wait(int *); -pid_t wait3(int *, int, struct rusage *); -#endif - -/* Ugly signal hacking */ -#ifdef SIG_ERR -#undef SIG_ERR -#define SIG_ERR (void (*)(int))-1 -#undef SIG_DFL -#define SIG_DFL (void (*)(int))0 -#undef SIG_IGN -#define SIG_IGN (void (*)(int))1 - -#ifdef KERNEL -#undef SIG_CATCH -#define SIG_CATCH (void (*)(int))2 -#endif -#undef SIG_HOLD -#define SIG_HOLD (void (*)(int))3 -#endif diff --git a/tcpdump.tproj/os-ultrix4.h b/tcpdump.tproj/os-ultrix4.h deleted file mode 100644 index 623d80a..0000000 --- a/tcpdump.tproj/os-ultrix4.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1993, 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. - * - * @(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/os-ultrix4.h,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL) - */ - -/* Prototypes missing in Ultrix 4 */ -int bcmp(const char *, const char *, u_int); -void bcopy(const void *, void *, u_int); -void bzero(void *, u_int); -void endservent(void); -int getopt(int, char * const *, const char *); -#ifdef __STDC__ -struct timeval; -struct timezone; -#endif -int gettimeofday(struct timeval *, struct timezone *); -int ioctl(int, int, caddr_t); -int pfopen(char *, int); -int setlinebuf(FILE *); -int socket(int, int, int); -int strcasecmp(const char *, const char *); diff --git a/tcpdump.tproj/ospf.h b/tcpdump.tproj/ospf.h deleted file mode 100644 index 9be2236..0000000 --- a/tcpdump.tproj/ospf.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1991, 1993, 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. - * - * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) - */ -#define OSPF_TYPE_UMD 0 /* UMd's special monitoring packets */ -#define OSPF_TYPE_HELLO 1 /* Hello */ -#define OSPF_TYPE_DB 2 /* Database Description */ -#define OSPF_TYPE_LSR 3 /* Link State Request */ -#define OSPF_TYPE_LSU 4 /* Link State Update */ -#define OSPF_TYPE_LSA 5 /* Link State Ack */ -#define OSPF_TYPE_MAX 6 - -/* Options *_options */ -#define OSPF_OPTION_T 0x01 /* T bit: TOS support */ -#define OSPF_OPTION_E 0x02 /* E bit: External routes advertised */ -#define OSPF_OPTION_MC 0x04 /* MC bit: Multicast capable */ - -/* ospf_authtype */ -#define OSPF_AUTH_NONE 0 /* No auth-data */ -#define OSPF_AUTH_SIMPLE 1 /* Simple password */ - -/* db_flags */ -#define OSPF_DB_INIT 0x04 /* */ -#define OSPF_DB_MORE 0x02 -#define OSPF_DB_MASTER 0x01 - -/* ls_type */ -#define LS_TYPE_ROUTER 1 /* router link */ -#define LS_TYPE_NETWORK 2 /* network link */ -#define LS_TYPE_SUM_IP 3 /* summary link */ -#define LS_TYPE_SUM_ABR 4 /* summary area link */ -#define LS_TYPE_ASE 5 /* ASE */ -#define LS_TYPE_GROUP 6 /* Group membership (multicast */ - /* extensions 23 July 1991) */ -#define LS_TYPE_MAX 7 - -/************************************************* - * - * is the above a bug in the documentation? - * - *************************************************/ - - -/* rla_link.link_type */ -#define RLA_TYPE_ROUTER 1 /* point-to-point to another router */ -#define RLA_TYPE_TRANSIT 2 /* connection to transit network */ -#define RLA_TYPE_STUB 3 /* connection to stub network */ -#define RLA_TYPE_VIRTUAL 4 /* virtual link */ - -/* rla_flags */ -#define RLA_FLAG_B 0x01 -#define RLA_FLAG_E 0x02 -#define RLA_FLAG_W1 0x04 -#define RLA_FLAG_W2 0x08 - -/* sla_tosmetric breakdown */ -#define SLA_MASK_TOS 0x7f000000 -#define SLA_MASK_METRIC 0x00ffffff -#define SLA_SHIFT_TOS 24 - -/* asla_tosmetric breakdown */ -#define ASLA_FLAG_EXTERNAL 0x80000000 -#define ASLA_MASK_TOS 0x7f000000 -#define ASLA_SHIFT_TOS 24 -#define ASLA_MASK_METRIC 0x00ffffff - -/* multicast vertex type */ -#define MCLA_VERTEX_ROUTER 1 -#define MCLA_VERTEX_NETWORK 2 - -/* link state advertisement header */ -struct lsa_hdr { - u_short ls_age; - u_char ls_options; - u_char ls_type; - struct in_addr ls_stateid; - struct in_addr ls_router; - u_int32_t ls_seq; - u_short ls_chksum; - u_short ls_length; -} ; - -/* link state advertisement */ -struct lsa { - struct lsa_hdr ls_hdr; - - /* Link state types */ - union { - /* Router links advertisements */ - struct { - u_char rla_flags; - u_char rla_zero[1]; - u_short rla_count; - struct rlalink { - struct in_addr link_id; - struct in_addr link_data; - u_char link_type; - u_char link_toscount; - u_short link_tos0metric; - } rla_link[1]; /* may repeat */ - } un_rla; - - /* Network links advertisements */ - struct { - struct in_addr nla_mask; - struct in_addr nla_router[1]; /* may repeat */ - } un_nla; - - /* Summary links advertisements */ - struct { - struct in_addr sla_mask; - u_int32_t sla_tosmetric[1]; /* may repeat */ - } un_sla; - - /* AS external links advertisements */ - struct { - struct in_addr asla_mask; - struct aslametric { - u_int32_t asla_tosmetric; - struct in_addr asla_forward; - struct in_addr asla_tag; - } asla_metric[1]; /* may repeat */ - } un_asla; - - /* Multicast group membership */ - struct mcla { - u_int32_t mcla_vtype; - struct in_addr mcla_vid; - } un_mcla[1]; - } lsa_un; -} ; - - -/* - * TOS metric struct (will be 0 or more in router links update) - */ -struct tos_metric { - u_char tos_type; - u_char tos_zero; - u_short tos_metric; -} ; - -#define OSPF_AUTH_SIZE 8 - -/* - * the main header - */ -struct ospfhdr { - u_char ospf_version; - u_char ospf_type; - u_short ospf_len; - struct in_addr ospf_routerid; - struct in_addr ospf_areaid; - u_short ospf_chksum; - u_short ospf_authtype; - u_char ospf_authdata[OSPF_AUTH_SIZE]; - union { - - /* Hello packet */ - struct { - struct in_addr hello_mask; - u_short hello_helloint; - u_char hello_options; - u_char hello_priority; - u_int32_t hello_deadint; - struct in_addr hello_dr; - struct in_addr hello_bdr; - struct in_addr hello_neighbor[1]; /* may repeat */ - } un_hello; - - /* Database Description packet */ - struct { - u_char db_zero[2]; - u_char db_options; - u_char db_flags; - u_int32_t db_seq; - struct lsa_hdr db_lshdr[1]; /* may repeat */ - } un_db; - - /* Link State Request */ - struct lsr { - u_int32_t ls_type; - struct in_addr ls_stateid; - struct in_addr ls_router; - } un_lsr[1]; /* may repeat */ - - /* Link State Update */ - struct { - u_int32_t lsu_count; - struct lsa lsu_lsa[1]; /* may repeat */ - } un_lsu; - - /* Link State Acknowledgement */ - struct { - struct lsa_hdr lsa_lshdr[1]; /* may repeat */ - } un_lsa ; - } ospf_un ; -} ; - -#define ospf_hello ospf_un.un_hello -#define ospf_db ospf_un.un_db -#define ospf_lsr ospf_un.un_lsr -#define ospf_lsu ospf_un.un_lsu -#define ospf_lsa ospf_un.un_lsa - diff --git a/tcpdump.tproj/parsenfsfh.c b/tcpdump.tproj/parsenfsfh.c deleted file mode 100644 index bdfdf43..0000000 --- a/tcpdump.tproj/parsenfsfh.c +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * parsenfsfh.c - portable parser for NFS file handles - * uses all sorts of heuristics - * - * Jeffrey C. Mogul - * Digital Equipment Corporation - * Western Research Laboratory - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/parsenfsfh.c,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include -#include -#include -#include - -#include "interface.h" -#include "nfsfh.h" - -/* - * This routine attempts to parse a file handle (in network byte order), - * using heuristics to guess what kind of format it is in. See the - * file "fhandle_layouts" for a detailed description of the various - * patterns we know about. - * - * The file handle is parsed into our internal representation of a - * file-system id, and an internal representation of an inode-number. - */ - -#define FHT_UNKNOWN 0 -#define FHT_AUSPEX 1 -#define FHT_DECOSF 2 -#define FHT_IRIX4 3 -#define FHT_IRIX5 4 -#define FHT_SUNOS3 5 -#define FHT_SUNOS4 6 -#define FHT_ULTRIX 7 -#define FHT_VMSUCX 8 -#define FHT_SUNOS5 9 -#define FHT_AIX32 10 -#define FHT_HPUX9 11 - -#ifdef ultrix -/* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */ -#define XFF(x) ((u_int32_t)(x)) -#else -#define XFF(x) (x) -#endif - -#define make_uint32(msb,b,c,lsb)\ - (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24)) - -#define make_uint24(msb,b, lsb)\ - (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16)) - -#define make_uint16(msb,lsb)\ - (XFF(lsb) + (XFF(msb)<<8)) - -#ifdef __alpha - /* or other 64-bit systems */ -#define make_uint48(msb,b,c,d,e,lsb)\ - ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40)) -#else - /* on 32-bit systems ignore high-order bits */ -#define make_uint48(msb,b,c,d,e,lsb)\ - ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24)) -#endif - -static int is_UCX(unsigned char *); - -void -Parse_fh(fh, fsidp, inop, osnamep, fsnamep, ourself) -register caddr_t *fh; -my_fsid *fsidp; -ino_t *inop; -char **osnamep; /* if non-NULL, return OS name here */ -char **fsnamep; /* if non-NULL, return server fs name here (for VMS) */ -int ourself; /* true if file handle was generated on this host */ -{ - register unsigned char *fhp = (unsigned char *)fh; - u_int32_t temp; - int fhtype = FHT_UNKNOWN; - - if (ourself) { - /* File handle generated on this host, no need for guessing */ -#if defined(IRIX40) - fhtype = FHT_IRIX4; -#endif -#if defined(IRIX50) - fhtype = FHT_IRIX5; -#endif -#if defined(IRIX51) - fhtype = FHT_IRIX5; -#endif -#if defined(SUNOS4) - fhtype = FHT_SUNOS4; -#endif -#if defined(SUNOS5) - fhtype = FHT_SUNOS5; -#endif -#if defined(ultrix) - fhtype = FHT_ULTRIX; -#endif -#if defined(__osf__) - fhtype = FHT_DECOSF; -#endif - } - /* - * This is basically a big decision tree - */ - else if ((fhp[0] == 0) && (fhp[1] == 0)) { - /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */ - /* probably rules out HP-UX, AIX unless they allow major=0 */ - if ((fhp[2] == 0) && (fhp[3] == 0)) { - /* bytes[2,3] == (0,0); must be Auspex */ - /* XXX or could be Ultrix+MASSBUS "hp" disk? */ - fhtype = FHT_AUSPEX; - } - else { - /* - * bytes[2,3] != (0,0); rules out Auspex, could be - * DECOSF, SUNOS4, or IRIX4 - */ - if ((fhp[4] != 0) && (fhp[5] == 0) && - (fhp[8] == 12) && (fhp[9] == 0)) { - /* seems to be DECOSF, with minor == 0 */ - fhtype = FHT_DECOSF; - } - else { - /* could be SUNOS4 or IRIX4 */ - /* XXX the test of fhp[5] == 8 could be wrong */ - if ((fhp[4] == 0) && (fhp[5] == 8) && (fhp[6] == 0) && - (fhp[7] == 0)) { - /* looks like a length, not a file system typecode */ - fhtype = FHT_IRIX4; - } - else { - /* by elimination */ - fhtype = FHT_SUNOS4; - } - } - } - } - else { - /* - * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4 - * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5 - * could be AIX, HP-UX - */ - if ((fhp[2] == 0) && (fhp[3] == 0)) { - /* - * bytes[2,3] == (0,0); rules out OSF, probably not UCX - * (unless the exported device name is just one letter!), - * could be Ultrix, IRIX5, AIX, or SUNOS5 - * might be HP-UX (depends on their values for minor devs) - */ - /*XXX we probably only need to test of these two bytes */ - if ((fhp[21] == 0) && (fhp[23] == 0)) { - fhtype = FHT_ULTRIX; - } - else { - /* Could be SUNOS5/IRIX5, maybe AIX */ - /* XXX no obvious difference between SUNOS5 and IRIX5 */ - if (fhp[9] == 10) - fhtype = FHT_SUNOS5; - /* XXX what about AIX? */ - } - } - else { - /* - * bytes[2,3] != (0,0); rules out Ultrix, could be - * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX - */ - if ((fhp[8] == 12) && (fhp[9] == 0)) { - fhtype = FHT_DECOSF; - } - else if ((fhp[8] == 0) && (fhp[9] == 10)) { - /* could be SUNOS5/IRIX5, AIX, HP-UX */ - if ((fhp[7] == 0) && (fhp[6] == 0) && - (fhp[5] == 0) && (fhp[4] == 0)) { - /* XXX is this always true of HP-UX? */ - fhtype = FHT_HPUX9; - } - else if (fhp[7] == 2) { - /* This would be MNT_NFS on AIX, which is impossible */ - fhtype = FHT_SUNOS5; /* or maybe IRIX5 */ - } - else { - /* - * XXX Could be SUNOS5/IRIX5 or AIX. I don't - * XXX see any way to disambiguate these, so - * XXX I'm going with the more likely guess. - * XXX Sorry, Big Blue. - */ - fhtype = FHT_SUNOS5; /* or maybe IRIX5 */ - } - } - else { - if (is_UCX(fhp)) { - fhtype = FHT_VMSUCX; - } - else { - fhtype = FHT_UNKNOWN; - } - } - } - } - - /* XXX still needs to handle SUNOS3 */ - - switch (fhtype) { - case FHT_AUSPEX: - fsidp->Fsid_dev.Minor = fhp[7]; - fsidp->Fsid_dev.Major = fhp[6]; - fsidp->fsid_code = 0; - - temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); - *inop = temp; - - if (osnamep) - *osnamep = "Auspex"; - break; - - case FHT_DECOSF: - fsidp->fsid_code = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]); - /* XXX could ignore 3 high-order bytes */ - - temp = make_uint32(fhp[3], fhp[2], fhp[1], fhp[0]); - fsidp->Fsid_dev.Minor = temp & 0xFFFFF; - fsidp->Fsid_dev.Major = (temp>>20) & 0xFFF; - - temp = make_uint32(fhp[15], fhp[14], fhp[13], fhp[12]); - *inop = temp; - if (osnamep) - *osnamep = "OSF"; - break; - - case FHT_IRIX4: - fsidp->Fsid_dev.Minor = fhp[3]; - fsidp->Fsid_dev.Major = fhp[2]; - fsidp->fsid_code = 0; - - temp = make_uint32(fhp[8], fhp[9], fhp[10], fhp[11]); - *inop = temp; - - if (osnamep) - *osnamep = "IRIX4"; - break; - - case FHT_IRIX5: - fsidp->Fsid_dev.Minor = make_uint16(fhp[2], fhp[3]); - fsidp->Fsid_dev.Major = make_uint16(fhp[0], fhp[1]); - fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); - - temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); - *inop = temp; - - if (osnamep) - *osnamep = "IRIX5"; - break; - - case FHT_SUNOS3: - if (osnamep) - *osnamep = "SUNOS3"; - break; - - case FHT_SUNOS4: - fsidp->Fsid_dev.Minor = fhp[3]; - fsidp->Fsid_dev.Major = fhp[2]; - fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); - - temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); - *inop = temp; - - if (osnamep) - *osnamep = "SUNOS4"; - break; - - case FHT_SUNOS5: - temp = make_uint16(fhp[0], fhp[1]); - fsidp->Fsid_dev.Major = (temp>>2) & 0x3FFF; - temp = make_uint24(fhp[1], fhp[2], fhp[3]); - fsidp->Fsid_dev.Minor = temp & 0x3FFFF; - fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); - - temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); - *inop = temp; - - if (osnamep) - *osnamep = "SUNOS5"; - break; - - case FHT_ULTRIX: - fsidp->fsid_code = 0; - fsidp->Fsid_dev.Minor = fhp[0]; - fsidp->Fsid_dev.Major = fhp[1]; - - temp = make_uint32(fhp[7], fhp[6], fhp[5], fhp[4]); - *inop = temp; - if (osnamep) - *osnamep = "Ultrix"; - break; - - case FHT_VMSUCX: - /* No numeric file system ID, so hash on the device-name */ - if (sizeof(*fsidp) >= 14) { - if (sizeof(*fsidp) > 14) - memset((char *)fsidp, 0, sizeof(*fsidp)); - memcpy((char *)fsidp, fh, 14); /* just use the whole thing */ - } - else { - u_int32_t tempa[4]; /* at least 16 bytes, maybe more */ - - memset((char *)tempa, 0, sizeof(tempa)); - memcpy((char *)tempa, fh, 14); /* ensure alignment */ - fsidp->Fsid_dev.Minor = tempa[0] + (tempa[1]<<1); - fsidp->Fsid_dev.Major = tempa[2] + (tempa[3]<<1); - fsidp->fsid_code = 0; - } - - /* VMS file ID is: (RVN, FidHi, FidLo) */ - *inop = make_uint32(fhp[26], fhp[27], fhp[23], fhp[22]); - - /* Caller must save (and null-terminate?) this value */ - if (fsnamep) - *fsnamep = (char *)&(fhp[1]); - - if (osnamep) - *osnamep = "VMS"; - break; - - case FHT_AIX32: - fsidp->Fsid_dev.Minor = make_uint16(fhp[2], fhp[3]); - fsidp->Fsid_dev.Major = make_uint16(fhp[0], fhp[1]); - fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); - - temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); - *inop = temp; - - if (osnamep) - *osnamep = "AIX32"; - break; - - case FHT_HPUX9: - fsidp->Fsid_dev.Major = fhp[0]; - temp = make_uint24(fhp[1], fhp[2], fhp[3]); - fsidp->Fsid_dev.Minor = temp; - fsidp->fsid_code = make_uint32(fhp[4], fhp[5], fhp[6], fhp[7]); - - temp = make_uint32(fhp[12], fhp[13], fhp[14], fhp[15]); - *inop = temp; - - if (osnamep) - *osnamep = "HPUX9"; - break; - - case FHT_UNKNOWN: -#ifdef DEBUG - { - /* XXX debugging */ - int i; - for (i = 0; i < 32; i++) - (void)fprintf(stderr, "%x.", fhp[i]); - (void)fprintf(stderr, "\n"); - } -#endif - /* XXX for now, give "bogus" values to aid debugging */ - fsidp->fsid_code = 0; - fsidp->Fsid_dev.Minor = 257; - fsidp->Fsid_dev.Major = 257; - *inop = 1; - - /* display will show this string instead of (257,257) */ - if (fsnamep) - *fsnamep = "Unknown"; - - if (osnamep) - *osnamep = "Unknown"; - break; - - } -} - -/* - * Is this a VMS UCX file handle? - * Check for: - * (1) leading code byte [XXX not yet] - * (2) followed by string of printing chars & spaces - * (3) followed by string of nulls - */ -static int -is_UCX(fhp) -unsigned char *fhp; -{ - register int i; - int seen_null = 0; - - for (i = 1; i < 14; i++) { - if (isprint(fhp[i])) { - if (seen_null) - return(0); - else - continue; - } - else if (fhp[i] == 0) { - seen_null = 1; - continue; - } - else - return(0); - } - - return(1); -} diff --git a/tcpdump.tproj/print-arp.c b/tcpdump.tproj/print-arp.c deleted file mode 100644 index 0fe851b..0000000 --- a/tcpdump.tproj/print-arp.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-arp.c,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include - -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "ethertype.h" -#include "extract.h" /* must come after interface.h */ - -/* Compatibility */ -#ifndef REVARP_REQUEST -#define REVARP_REQUEST 3 -#endif -#ifndef REVARP_REPLY -#define REVARP_REPLY 4 -#endif - -static u_char ezero[6]; - -void -arp_print(register const u_char *bp, u_int length, u_int caplen) -{ - register const struct ether_arp *ap; - register const struct ether_header *eh; - register u_short pro, hrd, op; - - ap = (struct ether_arp *)bp; - if ((u_char *)(ap + 1) > snapend) { - printf("[|arp]"); - return; - } - if (length < sizeof(struct ether_arp)) { - (void)printf("truncated-arp"); - default_print((u_char *)ap, length); - return; - } - - pro = EXTRACT_16BITS(&ap->arp_pro); - hrd = EXTRACT_16BITS(&ap->arp_hrd); - op = EXTRACT_16BITS(&ap->arp_op); - - if ((pro != ETHERTYPE_IP && pro != ETHERTYPE_TRAIL) - || ap->arp_hln != sizeof(SHA(ap)) - || ap->arp_pln != sizeof(SPA(ap))) { - (void)printf("arp-#%d for proto #%d (%d) hardware #%d (%d)", - op, pro, ap->arp_pln, - hrd, ap->arp_hln); - return; - } - if (pro == ETHERTYPE_TRAIL) - (void)printf("trailer-"); - eh = (struct ether_header *)packetp; - switch (op) { - - case ARPOP_REQUEST: - (void)printf("arp who-has %s", ipaddr_string(TPA(ap))); - if (memcmp((char *)ezero, (char *)THA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(THA(ap))); - (void)printf(" tell %s", ipaddr_string(SPA(ap))); - if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(SHA(ap))); - break; - - case ARPOP_REPLY: - (void)printf("arp reply %s", ipaddr_string(SPA(ap))); - if (memcmp((char *)ESRC(eh), (char *)SHA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(SHA(ap))); - (void)printf(" is-at %s", etheraddr_string(SHA(ap))); - if (memcmp((char *)EDST(eh), (char *)THA(ap), 6) != 0) - (void)printf(" (%s)", etheraddr_string(THA(ap))); - break; - - case REVARP_REQUEST: - (void)printf("rarp who-is %s tell %s", - etheraddr_string(THA(ap)), - etheraddr_string(SHA(ap))); - break; - - case REVARP_REPLY: - (void)printf("rarp reply %s at %s", - etheraddr_string(THA(ap)), - ipaddr_string(TPA(ap))); - break; - - default: - (void)printf("arp-#%d", op); - default_print((u_char *)ap, caplen); - return; - } - if (hrd != ARPHRD_ETHER) - printf(" hardware #%d", hrd); -} diff --git a/tcpdump.tproj/print-atalk.c b/tcpdump.tproj/print-atalk.c deleted file mode 100644 index f939466..0000000 --- a/tcpdump.tproj/print-atalk.c +++ /dev/null @@ -1,595 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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 AppleTalk packets. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-atalk.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "ethertype.h" -#include "extract.h" /* must come after interface.h */ -#include "appletalk.h" - -static struct tok type2str[] = { - { ddpRTMP, "rtmp" }, - { ddpRTMPrequest, "rtmpReq" }, - { ddpECHO, "echo" }, - { ddpIP, "IP" }, - { ddpARP, "ARP" }, - { ddpKLAP, "KLAP" }, - { 0, NULL } -}; - -struct aarp { - u_short htype, ptype; - u_char halen, palen; - u_short op; - u_char hsaddr[6]; - u_char psaddr[4]; - u_char hdaddr[6]; - u_char pdaddr[4]; -}; - -static char tstr[] = "[|atalk]"; - -static void atp_print(const struct atATP *, u_int); -static void atp_bitmap_print(u_char); -static void nbp_print(const struct atNBP *, u_int, u_short, u_char, u_char); -static const char *print_cstring(const char *, const u_char *); -static const struct atNBPtuple *nbp_tuple_print(const struct atNBPtuple *, - const u_char *, - u_short, u_char, u_char); -static const struct atNBPtuple *nbp_name_print(const struct atNBPtuple *, - const u_char *); -static const char *ataddr_string(u_short, u_char); -static void ddp_print(const u_char *, u_int, int, u_short, u_char, u_char); -static const char *ddpskt_string(int); - -/* - * Print AppleTalk Datagram Delivery Protocol packets. - */ -void -atalk_print(register const u_char *bp, u_int length) -{ - register const struct LAP *lp; - register const struct atDDP *dp; - register const struct atShortDDP *sdp; - u_short snet; - - lp = (struct LAP *)bp; - bp += sizeof(*lp); - length -= sizeof(*lp); - switch (lp->type) { - - case lapShortDDP: - if (length < ddpSSize) { - (void)printf(" [|sddp %d]", length); - return; - } - sdp = (const struct atShortDDP *)bp; - printf("%s.%s", - ataddr_string(0, lp->src), ddpskt_string(sdp->srcSkt)); - printf(" > %s.%s:", - ataddr_string(0, lp->dst), ddpskt_string(sdp->dstSkt)); - bp += ddpSSize; - length -= ddpSSize; - ddp_print(bp, length, sdp->type, 0, lp->src, sdp->srcSkt); - break; - - case lapDDP: - if (length < ddpSize) { - (void)printf(" [|ddp %d]", length); - return; - } - dp = (const struct atDDP *)bp; - snet = EXTRACT_16BITS(&dp->srcNet); - printf("%s.%s", ataddr_string(snet, dp->srcNode), - ddpskt_string(dp->srcSkt)); - printf(" > %s.%s:", - ataddr_string(EXTRACT_16BITS(&dp->dstNet), dp->dstNode), - ddpskt_string(dp->dstSkt)); - bp += ddpSize; - length -= ddpSize; - ddp_print(bp, length, dp->type, snet, dp->srcNode, dp->srcSkt); - break; - -#ifdef notdef - case lapKLAP: - klap_print(bp, length); - break; -#endif - - default: - printf("%d > %d at-lap#%d %d", - lp->src, lp->dst, lp->type, length); - break; - } -} - -/* XXX should probably pass in the snap header and do checks like arp_print() */ -void -aarp_print(register const u_char *bp, u_int length) -{ - register const struct aarp *ap; - -#define AT(member) ataddr_string((ap->member[1]<<8)|ap->member[2],ap->member[3]) - - printf("aarp "); - ap = (const struct aarp *)bp; - if (ap->htype == 1 && ap->ptype == ETHERTYPE_ATALK && - ap->halen == 6 && ap->palen == 4 ) - switch (ap->op) { - - case 1: /* request */ - (void)printf("who-has %s tell %s", - AT(pdaddr), AT(psaddr)); - return; - - case 2: /* response */ - (void)printf("reply %s is-at %s", - AT(pdaddr), etheraddr_string(ap->hdaddr)); - return; - - case 3: /* probe (oy!) */ - (void)printf("probe %s tell %s", - AT(pdaddr), AT(psaddr)); - return; - } - (void)printf("len %d op %d htype %d ptype %#x halen %d palen %d", - length, ap->op, ap->htype, ap->ptype, ap->halen, ap->palen ); -} - -static void -ddp_print(register const u_char *bp, register u_int length, register int t, - register u_short snet, register u_char snode, u_char skt) -{ - - switch (t) { - - case ddpNBP: - nbp_print((const struct atNBP *)bp, length, snet, snode, skt); - break; - - case ddpATP: - atp_print((const struct atATP *)bp, length); - break; - - default: - (void)printf(" at-%s %d", tok2str(type2str, NULL, t), length); - break; - } -} - -static void -atp_print(register const struct atATP *ap, u_int length) -{ - char c; - u_int32_t data; - - if ((const u_char *)(ap + 1) > snapend) { - /* Just bail if we don't have the whole chunk. */ - fputs(tstr, stdout); - return; - } - length -= sizeof(*ap); - switch (ap->control & 0xc0) { - - case atpReqCode: - (void)printf(" atp-req%s %d", - ap->control & atpXO? " " : "*", - EXTRACT_16BITS(&ap->transID)); - - atp_bitmap_print(ap->bitmap); - - if (length != 0) - (void)printf(" [len=%d]", length); - - switch (ap->control & (atpEOM|atpSTS)) { - case atpEOM: - (void)printf(" [EOM]"); - break; - case atpSTS: - (void)printf(" [STS]"); - break; - case atpEOM|atpSTS: - (void)printf(" [EOM,STS]"); - break; - } - break; - - case atpRspCode: - (void)printf(" atp-resp%s%d:%d (%d)", - ap->control & atpEOM? "*" : " ", - EXTRACT_16BITS(&ap->transID), ap->bitmap, length); - switch (ap->control & (atpXO|atpSTS)) { - case atpXO: - (void)printf(" [XO]"); - break; - case atpSTS: - (void)printf(" [STS]"); - break; - case atpXO|atpSTS: - (void)printf(" [XO,STS]"); - break; - } - break; - - case atpRelCode: - (void)printf(" atp-rel %d", EXTRACT_16BITS(&ap->transID)); - - atp_bitmap_print(ap->bitmap); - - /* length should be zero */ - if (length) - (void)printf(" [len=%d]", length); - - /* there shouldn't be any control flags */ - if (ap->control & (atpXO|atpEOM|atpSTS)) { - c = '['; - if (ap->control & atpXO) { - (void)printf("%cXO", c); - c = ','; - } - if (ap->control & atpEOM) { - (void)printf("%cEOM", c); - c = ','; - } - if (ap->control & atpSTS) { - (void)printf("%cSTS", c); - c = ','; - } - (void)printf("]"); - } - break; - - default: - (void)printf(" atp-0x%x %d (%d)", ap->control, - EXTRACT_16BITS(&ap->transID), length); - break; - } - data = EXTRACT_32BITS(&ap->userData); - if (data != 0) - (void)printf(" 0x%x", data); -} - -static void -atp_bitmap_print(register u_char bm) -{ - register char c; - register int i; - - /* - * The '& 0xff' below is needed for compilers that want to sign - * extend a u_char, which is the case with the Ultrix compiler. - * (gcc is smart enough to eliminate it, at least on the Sparc). - */ - if ((bm + 1) & (bm & 0xff)) { - c = '<'; - for (i = 0; bm; ++i) { - if (bm & 1) { - (void)printf("%c%d", c, i); - c = ','; - } - bm >>= 1; - } - (void)printf(">"); - } else { - for (i = 0; bm; ++i) - bm >>= 1; - if (i > 1) - (void)printf("<0-%d>", i - 1); - else - (void)printf("<0>"); - } -} - -static void -nbp_print(register const struct atNBP *np, u_int length, register u_short snet, - register u_char snode, register u_char skt) -{ - register const struct atNBPtuple *tp = - (struct atNBPtuple *)((u_char *)np + nbpHeaderSize); - int i; - const u_char *ep; - - length -= nbpHeaderSize; - if (length < 8) { - /* must be room for at least one tuple */ - (void)printf(" truncated-nbp %d", length + nbpHeaderSize); - return; - } - /* ep points to end of available data */ - ep = snapend; - if ((const u_char *)tp > ep) { - fputs(tstr, stdout); - return; - } - switch (i = np->control & 0xf0) { - - case nbpBrRq: - case nbpLkUp: - (void)printf(i == nbpLkUp? " nbp-lkup %d:":" nbp-brRq %d:", - np->id); - if ((const u_char *)(tp + 1) > ep) { - fputs(tstr, stdout); - return; - } - (void)nbp_name_print(tp, ep); - /* - * look for anomalies: the spec says there can only - * be one tuple, the address must match the source - * address and the enumerator should be zero. - */ - if ((np->control & 0xf) != 1) - (void)printf(" [ntup=%d]", np->control & 0xf); - if (tp->enumerator) - (void)printf(" [enum=%d]", tp->enumerator); - if (EXTRACT_16BITS(&tp->net) != snet || - tp->node != snode || tp->skt != skt) - (void)printf(" [addr=%s.%d]", - ataddr_string(EXTRACT_16BITS(&tp->net), - tp->node), tp->skt); - break; - - case nbpLkUpReply: - (void)printf(" nbp-reply %d:", np->id); - - /* print each of the tuples in the reply */ - for (i = np->control & 0xf; --i >= 0 && tp; ) - tp = nbp_tuple_print(tp, ep, snet, snode, skt); - break; - - default: - (void)printf(" nbp-0x%x %d (%d)", np->control, np->id, - length); - break; - } -} - -/* print a counted string */ -static const char * -print_cstring(register const char *cp, register const u_char *ep) -{ - register u_int length; - - if (cp >= (const char *)ep) { - fputs(tstr, stdout); - return (0); - } - length = *cp++; - - /* Spec says string can be at most 32 bytes long */ - if (length < 0 || length > 32) { - (void)printf("[len=%d]", length); - return (0); - } - while (--length >= 0) { - if (cp >= (char *)ep) { - fputs(tstr, stdout); - return (0); - } - putchar(*cp++); - } - return (cp); -} - -static const struct atNBPtuple * -nbp_tuple_print(register const struct atNBPtuple *tp, - register const u_char *ep, - register u_short snet, register u_char snode, - register u_char skt) -{ - register const struct atNBPtuple *tpn; - - if ((const u_char *)(tp + 1) > ep) { - fputs(tstr, stdout); - return 0; - } - tpn = nbp_name_print(tp, ep); - - /* if the enumerator isn't 1, print it */ - if (tp->enumerator != 1) - (void)printf("(%d)", tp->enumerator); - - /* if the socket doesn't match the src socket, print it */ - if (tp->skt != skt) - (void)printf(" %d", tp->skt); - - /* if the address doesn't match the src address, it's an anomaly */ - if (EXTRACT_16BITS(&tp->net) != snet || tp->node != snode) - (void)printf(" [addr=%s]", - ataddr_string(EXTRACT_16BITS(&tp->net), tp->node)); - - return (tpn); -} - -static const struct atNBPtuple * -nbp_name_print(const struct atNBPtuple *tp, register const u_char *ep) -{ - register const char *cp = (const char *)tp + nbpTupleSize; - - putchar(' '); - - /* Object */ - putchar('"'); - if ((cp = print_cstring(cp, ep)) != NULL) { - /* Type */ - putchar(':'); - if ((cp = print_cstring(cp, ep)) != NULL) { - /* Zone */ - putchar('@'); - if ((cp = print_cstring(cp, ep)) != NULL) - putchar('"'); - } - } - return ((const struct atNBPtuple *)cp); -} - - -#define HASHNAMESIZE 4096 - -struct hnamemem { - int addr; - char *name; - struct hnamemem *nxt; -}; - -static struct hnamemem hnametable[HASHNAMESIZE]; - -static const char * -ataddr_string(u_short atnet, u_char athost) -{ - register struct hnamemem *tp, *tp2; - register int i = (atnet << 8) | athost; - char nambuf[256]; - static int first = 1; - FILE *fp; - - /* - * if this is the first call, see if there's an AppleTalk - * number to name map file. - */ - if (first && (first = 0, !nflag) - && (fp = fopen("/etc/atalk.names", "r"))) { - char line[256]; - int i1, i2, i3; - - while (fgets(line, sizeof(line), fp)) { - if (line[0] == '\n' || line[0] == 0 || line[0] == '#') - continue; - if (sscanf(line, "%d.%d.%d %s", &i1, &i2, &i3, - nambuf) == 4) - /* got a hostname. */ - i3 |= ((i1 << 8) | i2) << 8; - else if (sscanf(line, "%d.%d %s", &i1, &i2, - nambuf) == 3) - /* got a net name */ - i3 = (((i1 << 8) | i2) << 8) | 255; - else - continue; - - for (tp = &hnametable[i3 & (HASHNAMESIZE-1)]; - tp->nxt; tp = tp->nxt) - ; - tp->addr = i3; - tp->nxt = newhnamemem(); - tp->name = savestr(nambuf); - } - fclose(fp); - } - - for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt) - if (tp->addr == i) - return (tp->name); - - /* didn't have the node name -- see if we've got the net name */ - i |= 255; - for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt) - if (tp2->addr == i) { - tp->addr = (atnet << 8) | athost; - tp->nxt = newhnamemem(); - (void)sprintf(nambuf, "%s.%d", tp2->name, athost); - tp->name = savestr(nambuf); - return (tp->name); - } - - tp->addr = (atnet << 8) | athost; - tp->nxt = newhnamemem(); - if (athost != 255) - (void)sprintf(nambuf, "%d.%d.%d", - atnet >> 8, atnet & 0xff, athost); - else - (void)sprintf(nambuf, "%d.%d", atnet >> 8, atnet & 0xff); - tp->name = savestr(nambuf); - - return (tp->name); -} - -static struct tok skt2str[] = { - { rtmpSkt, "rtmp" }, /* routing table maintenance */ - { nbpSkt, "nis" }, /* name info socket */ - { echoSkt, "echo" }, /* AppleTalk echo protocol */ - { zipSkt, "zip" }, /* zone info protocol */ - { 0, NULL } -}; - -static const char * -ddpskt_string(register int skt) -{ - static char buf[8]; - - if (nflag) { - (void)sprintf(buf, "%d", skt); - return (buf); - } - return (tok2str(skt2str, "%d", skt)); -} diff --git a/tcpdump.tproj/print-atm.c b/tcpdump.tproj/print-atm.c deleted file mode 100644 index 4abe2ad..0000000 --- a/tcpdump.tproj/print-atm.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - */ -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-atm.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "addrtoname.h" -#include "ethertype.h" -#include "interface.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/tcpdump.tproj/print-bootp.c b/tcpdump.tproj/print-bootp.c deleted file mode 100644 index c938728..0000000 --- a/tcpdump.tproj/print-bootp.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1993, 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 bootp packets. - */ -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-bootp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include - -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "bootp.h" - -static void rfc1048_print(const u_char *, u_int); -static void cmu_print(const u_char *, u_int); - -static char tstr[] = " [|bootp]"; - -/* - * Print bootp requests - */ -void -bootp_print(register const u_char *cp, u_int length, - u_short sport, u_short dport) -{ - register const struct bootp *bp; - static u_char vm_cmu[4] = VM_CMU; - static u_char vm_rfc1048[4] = VM_RFC1048; - - bp = (struct bootp *)cp; - TCHECK(bp->bp_op); - switch (bp->bp_op) { - - case BOOTREQUEST: - /* Usually, a request goes from a client to a server */ - if (sport != IPPORT_BOOTPC || dport != IPPORT_BOOTPS) - printf(" (request)"); - break; - - case BOOTREPLY: - /* Usually, a reply goes from a server to a client */ - if (sport != IPPORT_BOOTPS || dport != IPPORT_BOOTPC) - printf(" (reply)"); - break; - - default: - printf(" bootp-#%d", bp->bp_op); - } - - TCHECK(bp->bp_secs); - - /* The usual hardware address type is 1 (10Mb Ethernet) */ - if (bp->bp_htype != 1) - printf(" htype-#%d", bp->bp_htype); - - /* The usual length for 10Mb Ethernet address is 6 bytes */ - if (bp->bp_htype != 1 || bp->bp_hlen != 6) - printf(" hlen:%d", bp->bp_hlen); - - /* Only print interesting fields */ - if (bp->bp_hops) - printf(" hops:%d", bp->bp_hops); - if (bp->bp_xid) - printf(" xid:0x%x", (u_int32_t)ntohl(bp->bp_xid)); - if (bp->bp_secs) - printf(" secs:%d", ntohs(bp->bp_secs)); - - /* Client's ip address */ - TCHECK(bp->bp_ciaddr); - if (bp->bp_ciaddr.s_addr) - printf(" C:%s", ipaddr_string(&bp->bp_ciaddr)); - - /* 'your' ip address (bootp client) */ - TCHECK(bp->bp_yiaddr); - if (bp->bp_yiaddr.s_addr) - printf(" Y:%s", ipaddr_string(&bp->bp_yiaddr)); - - /* Server's ip address */ - TCHECK(bp->bp_siaddr); - if (bp->bp_siaddr.s_addr) - printf(" S:%s", ipaddr_string(&bp->bp_siaddr)); - - /* Gateway's ip address */ - TCHECK(bp->bp_giaddr); - if (bp->bp_giaddr.s_addr) - printf(" G:%s", ipaddr_string(&bp->bp_giaddr)); - - /* Client's Ethernet address */ - if (bp->bp_htype == 1 && bp->bp_hlen == 6) { - register const struct ether_header *eh; - register const char *e; - - TCHECK2(bp->bp_chaddr[0], 6); - eh = (struct ether_header *)packetp; - if (bp->bp_op == BOOTREQUEST) - e = (const char *)ESRC(eh); - else if (bp->bp_op == BOOTREPLY) - e = (const char *)EDST(eh); - else - e = 0; - if (e == 0 || memcmp((char *)bp->bp_chaddr, e, 6) != 0) - printf(" ether %s", etheraddr_string(bp->bp_chaddr)); - } - - TCHECK2(bp->bp_sname[0], 1); /* check first char only */ - if (*bp->bp_sname) { - printf(" sname \""); - if (fn_print(bp->bp_sname, snapend)) { - putchar('"'); - fputs(tstr + 1, stdout); - return; - } - } - TCHECK2(bp->bp_sname[0], 1); /* check first char only */ - if (*bp->bp_file) { - printf(" file \""); - if (fn_print(bp->bp_file, snapend)) { - putchar('"'); - fputs(tstr + 1, stdout); - return; - } - } - - /* Decode the vendor buffer */ - TCHECK(bp->bp_vend[0]); - length -= sizeof(*bp) - sizeof(bp->bp_vend); - if (memcmp((char *)bp->bp_vend, (char *)vm_rfc1048, - sizeof(u_int32_t)) == 0) - rfc1048_print(bp->bp_vend, length); - else if (memcmp((char *)bp->bp_vend, (char *)vm_cmu, - sizeof(u_int32_t)) == 0) - cmu_print(bp->bp_vend, length); - else { - u_int32_t ul; - - memcpy((char *)&ul, (char *)bp->bp_vend, sizeof(ul)); - if (ul != 0) - printf("vend-#0x%x", ul); - } - - return; -trunc: - fputs(tstr, stdout); -} - -/* The first character specifies the format to print */ -static struct tok tag2str[] = { -/* RFC1048 tags */ - { TAG_PAD, " PAD" }, - { TAG_SUBNET_MASK, "iSM" }, /* subnet mask (RFC950) */ - { TAG_TIME_OFFSET, "lTZ" }, /* seconds from UTC */ - { TAG_GATEWAY, "iDG" }, /* default gateway */ - { TAG_TIME_SERVER, "iTS" }, /* time servers (RFC868) */ - { TAG_NAME_SERVER, "iIEN" }, /* IEN name servers (IEN116) */ - { TAG_DOMAIN_SERVER, "iNS" }, /* domain name (RFC1035) */ - { TAG_LOG_SERVER, "iLOG" }, /* MIT log servers */ - { TAG_COOKIE_SERVER, "iCS" }, /* cookie servers (RFC865) */ - { TAG_LPR_SERVER, "iLPR" }, /* lpr server (RFC1179) */ - { TAG_IMPRESS_SERVER, "iIM" }, /* impress servers (Imagen) */ - { TAG_RLP_SERVER, "iRL" }, /* resource location (RFC887) */ - { TAG_HOSTNAME, "aHN" }, /* ascii hostname */ - { TAG_BOOTSIZE, "sBS" }, /* 512 byte blocks */ - { TAG_END, " END" }, -/* RFC1497 tags */ - { TAG_DUMPPATH, "aDP" }, - { TAG_DOMAINNAME, "aDN" }, - { TAG_SWAP_SERVER, "iSS" }, - { TAG_ROOTPATH, "aRP" }, - { TAG_EXTPATH, "aEP" }, - { 0, NULL } -}; - -static void -rfc1048_print(register const u_char *bp, register u_int length) -{ - register u_char tag; - register u_int len, size; - register const char *cp; - register char c; - int first; - u_int32_t ul; - u_short us; - - printf(" vend-rfc1048"); - - /* Step over magic cookie */ - bp += sizeof(int32_t); - - /* Loop while we there is a tag left in the buffer */ - while (bp + 1 < snapend) { - tag = *bp++; - if (tag == TAG_PAD) - continue; - if (tag == TAG_END) - return; - cp = tok2str(tag2str, "?T%d", tag); - c = *cp++; - printf(" %s:", cp); - - /* Get the length; check for truncation */ - if (bp + 1 >= snapend) { - fputs(tstr, stdout); - return; - } - len = *bp++; - if (bp + len >= snapend) { - fputs(tstr, stdout); - return; - } - - /* Print data */ - size = len; - if (c == '?') { - /* Base default formats for unknown tags on data size */ - if (size & 1) - c = 'b'; - else if (size & 2) - c = 's'; - else - c = 'l'; - } - first = 1; - switch (c) { - - case 'a': - /* ascii strings */ - putchar('"'); - (void)fn_printn(bp, size, NULL); - putchar('"'); - bp += size; - size = 0; - break; - - case 'i': - case 'l': - /* ip addresses/32-bit words */ - while (size >= sizeof(ul)) { - if (!first) - putchar(','); - memcpy((char *)&ul, (char *)bp, sizeof(ul)); - if (c == 'i') - printf("%s", ipaddr_string(&ul)); - else - printf("%u", ul); - bp += sizeof(ul); - size -= sizeof(ul); - first = 0; - } - break; - - case 's': - /* shorts */ - while (size >= sizeof(us)) { - if (!first) - putchar(','); - memcpy((char *)&us, (char *)bp, sizeof(us)); - printf("%d", us); - bp += sizeof(us); - size -= sizeof(us); - first = 0; - } - break; - - case 'b': - default: - /* Bytes */ - while (size > 0) { - if (!first) - putchar('.'); - printf("%d", *bp); - ++bp; - --size; - first = 0; - } - break; - } - /* Data left over? */ - if (size) - printf("[len %d]", len); - } -} - -static void -cmu_print(register const u_char *bp, register u_int length) -{ - register const struct cmu_vend *cmu; - char *fmt = " %s:%s"; - -#define PRINTCMUADDR(m, s) { TCHECK(cmu->m); \ - if (cmu->m.s_addr != 0) \ - printf(fmt, s, ipaddr_string(&cmu->m.s_addr)); } - - printf(" vend-cmu"); - cmu = (struct cmu_vend *)bp; - - /* Only print if there are unknown bits */ - TCHECK(cmu->v_flags); - if ((cmu->v_flags & ~(VF_SMASK)) != 0) - printf(" F:0x%x", cmu->v_flags); - PRINTCMUADDR(v_dgate, "DG"); - PRINTCMUADDR(v_smask, cmu->v_flags & VF_SMASK ? "SM" : "SM*"); - PRINTCMUADDR(v_dns1, "NS1"); - PRINTCMUADDR(v_dns2, "NS2"); - PRINTCMUADDR(v_ins1, "IEN1"); - PRINTCMUADDR(v_ins2, "IEN2"); - PRINTCMUADDR(v_ts1, "TS1"); - PRINTCMUADDR(v_ts2, "TS2"); - return; - -trunc: - fputs(tstr, stdout); -#undef PRINTCMUADDR -} diff --git a/tcpdump.tproj/print-decnet.c b/tcpdump.tproj/print-decnet.c deleted file mode 100644 index a65152e..0000000 --- a/tcpdump.tproj/print-decnet.c +++ /dev/null @@ -1,798 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-decnet.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#ifdef HAVE_LIBDNET -#include -#endif - -#include -#include -#include -#include -#include - -#include "decnet.h" -#include "extract.h" -#include "interface.h" -#include "addrtoname.h" - -/* Forwards */ -static void print_decnet_ctlmsg(const union routehdr *, u_int); -static void print_t_info(int); -static void print_l1_routes(const char *, u_int); -static void print_l2_routes(const char *, u_int); -static void print_i_info(int); -static void print_elist(const char *, u_int); -static void print_nsp(const u_char *, u_int); -static void print_reason(int); -#ifdef PRINT_NSPDATA -static void pdata(u_char *, int); -#endif - -#ifdef HAVE_LIBDNET -extern char *dnet_htoa(struct dn_naddr *); -#endif - -void -decnet_print(register const u_char *ap, register u_int length, - register u_int caplen) -{ - static union routehdr rhcopy; - register union routehdr *rhp = &rhcopy; - register int mflags; - int dst, src, hops; - u_int rhlen, nsplen, pktlen; - const u_char *nspp; - - if (length < sizeof(struct shorthdr)) { - (void)printf("[|decnet]"); - return; - } - - pktlen = EXTRACT_LE_16BITS(ap); - - rhlen = min(length, caplen); - rhlen = min(rhlen, sizeof(*rhp)); - memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen); - - mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); - - if (mflags & RMF_PAD) { - /* pad bytes of some sort in front of message */ - u_int padlen = mflags & RMF_PADMASK; - if (vflag) - (void) printf("[pad:%d] ", padlen); - ap += padlen; - length -= padlen; - caplen -= padlen; - rhlen = min(length, caplen); - rhlen = min(rhlen, sizeof(*rhp)); - memcpy((char *)rhp, (char *)&(ap[sizeof(short)]), rhlen); - mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); - } - - if (mflags & RMF_FVER) { - (void) printf("future-version-decnet"); - default_print(ap, length); - return; - } - - /* is it a control message? */ - if (mflags & RMF_CTLMSG) { - print_decnet_ctlmsg(rhp, min(length, caplen)); - return; - } - - switch (mflags & RMF_MASK) { - case RMF_LONG: - dst = - EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr); - src = - EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr); - hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits); - nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]); - nsplen = min((length - sizeof(struct longhdr)), - (caplen - sizeof(struct longhdr))); - break; - case RMF_SHORT: - dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst); - src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src); - hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1; - nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]); - nsplen = min((length - sizeof(struct shorthdr)), - (caplen - sizeof(struct shorthdr))); - break; - default: - (void) printf("unknown message flags under mask"); - default_print((u_char *)ap, length); - return; - } - - (void)printf("%s > %s %d ", - dnaddr_string(src), dnaddr_string(dst), pktlen); - if (vflag) { - if (mflags & RMF_RQR) - (void)printf("RQR "); - if (mflags & RMF_RTS) - (void)printf("RTS "); - if (mflags & RMF_IE) - (void)printf("IE "); - (void)printf("%d hops ", hops); - } - - print_nsp(nspp, nsplen); -} - -static void -print_decnet_ctlmsg(register const union routehdr *rhp, u_int length) -{ - int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags); - register union controlmsg *cmp = (union controlmsg *)rhp; - int src, dst, info, blksize, eco, ueco, hello, other, vers; - etheraddr srcea, rtea; - int priority; - char *rhpx = (char *)rhp; - - switch (mflags & RMF_CTLMASK) { - case RMF_INIT: - (void)printf("init "); - src = EXTRACT_LE_16BITS(cmp->cm_init.in_src); - info = EXTRACT_LE_8BITS(cmp->cm_init.in_info); - blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize); - vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers); - eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco); - ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco); - hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello); - print_t_info(info); - (void)printf( - "src %sblksize %d vers %d eco %d ueco %d hello %d", - dnaddr_string(src), blksize, vers, eco, ueco, - hello); - break; - case RMF_VER: - (void)printf("verification "); - src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src); - other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval); - (void)printf("src %s fcnval %o", dnaddr_string(src), other); - break; - case RMF_TEST: - (void)printf("test "); - src = EXTRACT_LE_16BITS(cmp->cm_test.te_src); - other = EXTRACT_LE_8BITS(cmp->cm_test.te_data); - (void)printf("src %s data %o", dnaddr_string(src), other); - break; - case RMF_L1ROUT: - (void)printf("lev-1-routing "); - src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src); - (void)printf("src %s ", dnaddr_string(src)); - print_l1_routes(&(rhpx[sizeof(struct l1rout)]), - length - sizeof(struct l1rout)); - break; - case RMF_L2ROUT: - (void)printf("lev-2-routing "); - src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src); - (void)printf("src %s ", dnaddr_string(src)); - print_l2_routes(&(rhpx[sizeof(struct l2rout)]), - length - sizeof(struct l2rout)); - break; - case RMF_RHELLO: - (void)printf("router-hello "); - vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers); - eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco); - ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco); - memcpy((char *)&srcea, (char *)&(cmp->cm_rhello.rh_src), - sizeof(srcea)); - src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr); - info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info); - blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize); - priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority); - hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello); - print_i_info(info); - (void)printf( - "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d", - vers, eco, ueco, dnaddr_string(src), - blksize, priority, hello); - print_elist(&(rhpx[sizeof(struct rhellomsg)]), - length - sizeof(struct rhellomsg)); - break; - case RMF_EHELLO: - (void)printf("endnode-hello "); - vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers); - eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco); - ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco); - memcpy((char *)&srcea, (char *)&(cmp->cm_ehello.eh_src), - sizeof(srcea)); - src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr); - info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info); - blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize); - /*seed*/ - memcpy((char *)&rtea, (char *)&(cmp->cm_ehello.eh_router), - sizeof(rtea)); - dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr); - hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello); - other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data); - print_i_info(info); - (void)printf( - "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o", - vers, eco, ueco, dnaddr_string(src), - blksize, dnaddr_string(dst), hello, other); - break; - - default: - (void)printf("unknown control message"); - default_print((u_char *)rhp, length); - break; - } -} - -static void -print_t_info(int info) -{ - int ntype = info & 3; - switch (ntype) { - case 0: (void)printf("reserved-ntype? "); break; - case TI_L2ROUT: (void)printf("l2rout "); break; - case TI_L1ROUT: (void)printf("l1rout "); break; - case TI_ENDNODE: (void)printf("endnode "); break; - } - if (info & TI_VERIF) - (void)printf("verif "); - if (info & TI_BLOCK) - (void)printf("blo "); -} - -static void -print_l1_routes(const char *rp, u_int len) -{ - int count; - int id; - int info; - - /* The last short is a checksum */ - while (len > (3 * sizeof(short))) { - count = EXTRACT_LE_16BITS(rp); - if (count > 1024) - return; /* seems to be bogus from here on */ - rp += sizeof(short); - len -= sizeof(short); - id = EXTRACT_LE_16BITS(rp); - rp += sizeof(short); - len -= sizeof(short); - info = EXTRACT_LE_16BITS(rp); - rp += sizeof(short); - len -= sizeof(short); - (void)printf("{ids %d-%d cost %d hops %d} ", id, id + count, - RI_COST(info), RI_HOPS(info)); - } -} - -static void -print_l2_routes(const char *rp, u_int len) -{ - int count; - int area; - int info; - - /* The last short is a checksum */ - while (len > (3 * sizeof(short))) { - count = EXTRACT_LE_16BITS(rp); - if (count > 1024) - return; /* seems to be bogus from here on */ - rp += sizeof(short); - len -= sizeof(short); - area = EXTRACT_LE_16BITS(rp); - rp += sizeof(short); - len -= sizeof(short); - info = EXTRACT_LE_16BITS(rp); - rp += sizeof(short); - len -= sizeof(short); - (void)printf("{areas %d-%d cost %d hops %d} ", area, area + count, - RI_COST(info), RI_HOPS(info)); - } -} - -static void -print_i_info(int info) -{ - int ntype = info & II_TYPEMASK; - switch (ntype) { - case 0: (void)printf("reserved-ntype? "); break; - case II_L2ROUT: (void)printf("l2rout "); break; - case II_L1ROUT: (void)printf("l1rout "); break; - case II_ENDNODE: (void)printf("endnode "); break; - } - if (info & II_VERIF) - (void)printf("verif "); - if (info & II_NOMCAST) - (void)printf("nomcast "); - if (info & II_BLOCK) - (void)printf("blo "); -} - -static void -print_elist(const char *elp, u_int len) -{ - /* Not enough examples available for me to debug this */ -} - -static void -print_nsp(const u_char *nspp, u_int nsplen) -{ - const struct nsphdr *nsphp = (struct nsphdr *)nspp; - int dst, src, flags; - - flags = EXTRACT_LE_8BITS(nsphp->nh_flags); - dst = EXTRACT_LE_16BITS(nsphp->nh_dst); - src = EXTRACT_LE_16BITS(nsphp->nh_src); - - switch (flags & NSP_TYPEMASK) { - case MFT_DATA: - switch (flags & NSP_SUBMASK) { - case MFS_BOM: - case MFS_MOM: - case MFS_EOM: - case MFS_BOM+MFS_EOM: - printf("data %d>%d ", src, dst); - { - struct seghdr *shp = (struct seghdr *)nspp; - int ack; -#ifdef PRINT_NSPDATA - u_char *dp; -#endif - u_int data_off = sizeof(struct minseghdr); - - ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); - if (ack & SGQ_ACK) { /* acknum field */ - if ((ack & SGQ_NAK) == SGQ_NAK) - (void)printf("nak %d ", ack & SGQ_MASK); - else - (void)printf("ack %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); - data_off += sizeof(short); - if (ack & SGQ_OACK) { /* ackoth field */ - if ((ack & SGQ_ONAK) == SGQ_ONAK) - (void)printf("onak %d ", ack & SGQ_MASK); - else - (void)printf("oack %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); - data_off += sizeof(short); - } - } - (void)printf("seg %d ", ack & SGQ_MASK); -#ifdef PRINT_NSPDATA - dp = &(nspp[data_off]); - pdata(dp, 10); -#endif - } - break; - case MFS_ILS+MFS_INT: - printf("intr "); - { - struct seghdr *shp = (struct seghdr *)nspp; - int ack; -#ifdef PRINT_NSPDATA - u_char *dp; -#endif - u_int data_off = sizeof(struct minseghdr); - - ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); - if (ack & SGQ_ACK) { /* acknum field */ - if ((ack & SGQ_NAK) == SGQ_NAK) - (void)printf("nak %d ", ack & SGQ_MASK); - else - (void)printf("ack %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); - data_off += sizeof(short); - if (ack & SGQ_OACK) { /* ackdat field */ - if ((ack & SGQ_ONAK) == SGQ_ONAK) - (void)printf("nakdat %d ", ack & SGQ_MASK); - else - (void)printf("ackdat %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); - data_off += sizeof(short); - } - } - (void)printf("seg %d ", ack & SGQ_MASK); -#ifdef PRINT_NSPDATA - dp = &(nspp[data_off]); - pdata(dp, 10); -#endif - } - break; - case MFS_ILS: - (void)printf("link-service %d>%d ", src, dst); - { - struct seghdr *shp = (struct seghdr *)nspp; - struct lsmsg *lsmp = - (struct lsmsg *)&(nspp[sizeof(struct seghdr)]); - int ack; - int lsflags, fcval; - - ack = EXTRACT_LE_16BITS(shp->sh_seq[0]); - if (ack & SGQ_ACK) { /* acknum field */ - if ((ack & SGQ_NAK) == SGQ_NAK) - (void)printf("nak %d ", ack & SGQ_MASK); - else - (void)printf("ack %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(shp->sh_seq[1]); - if (ack & SGQ_OACK) { /* ackdat field */ - if ((ack & SGQ_ONAK) == SGQ_ONAK) - (void)printf("nakdat %d ", ack & SGQ_MASK); - else - (void)printf("ackdat %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(shp->sh_seq[2]); - } - } - (void)printf("seg %d ", ack & SGQ_MASK); - lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags); - fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval); - switch (lsflags & LSI_MASK) { - case LSI_DATA: - (void)printf("dat seg count %d ", fcval); - switch (lsflags & LSM_MASK) { - case LSM_NOCHANGE: - break; - case LSM_DONOTSEND: - (void)printf("donotsend-data "); - break; - case LSM_SEND: - (void)printf("send-data "); - break; - default: - (void)printf("reserved-fcmod? %x", lsflags); - break; - } - break; - case LSI_INTR: - (void)printf("intr req count %d ", fcval); - break; - default: - (void)printf("reserved-fcval-int? %x", lsflags); - break; - } - } - break; - default: - (void)printf("reserved-subtype? %x %d > %d", flags, src, dst); - break; - } - break; - case MFT_ACK: - switch (flags & NSP_SUBMASK) { - case MFS_DACK: - (void)printf("data-ack %d>%d ", src, dst); - { - struct ackmsg *amp = (struct ackmsg *)nspp; - int ack; - - ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); - if (ack & SGQ_ACK) { /* acknum field */ - if ((ack & SGQ_NAK) == SGQ_NAK) - (void)printf("nak %d ", ack & SGQ_MASK); - else - (void)printf("ack %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); - if (ack & SGQ_OACK) { /* ackoth field */ - if ((ack & SGQ_ONAK) == SGQ_ONAK) - (void)printf("onak %d ", ack & SGQ_MASK); - else - (void)printf("oack %d ", ack & SGQ_MASK); - } - } - } - break; - case MFS_IACK: - (void)printf("ils-ack %d>%d ", src, dst); - { - struct ackmsg *amp = (struct ackmsg *)nspp; - int ack; - - ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]); - if (ack & SGQ_ACK) { /* acknum field */ - if ((ack & SGQ_NAK) == SGQ_NAK) - (void)printf("nak %d ", ack & SGQ_MASK); - else - (void)printf("ack %d ", ack & SGQ_MASK); - ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]); - if (ack & SGQ_OACK) { /* ackdat field */ - if ((ack & SGQ_ONAK) == SGQ_ONAK) - (void)printf("nakdat %d ", ack & SGQ_MASK); - else - (void)printf("ackdat %d ", ack & SGQ_MASK); - } - } - } - break; - case MFS_CACK: - (void)printf("conn-ack %d", dst); - break; - default: - (void)printf("reserved-acktype? %x %d > %d", flags, src, dst); - break; - } - break; - case MFT_CTL: - switch (flags & NSP_SUBMASK) { - case MFS_CI: - case MFS_RCI: - if ((flags & NSP_SUBMASK) == MFS_CI) - (void)printf("conn-initiate "); - else - (void)printf("retrans-conn-initiate "); - (void)printf("%d>%d ", src, dst); - { - struct cimsg *cimp = (struct cimsg *)nspp; - int services, info, segsize; -#ifdef PRINT_NSPDATA - u_char *dp; -#endif - - services = EXTRACT_LE_8BITS(cimp->ci_services); - info = EXTRACT_LE_8BITS(cimp->ci_info); - segsize = EXTRACT_LE_16BITS(cimp->ci_segsize); - - switch (services & COS_MASK) { - case COS_NONE: - break; - case COS_SEGMENT: - (void)printf("seg "); - break; - case COS_MESSAGE: - (void)printf("msg "); - break; - case COS_CRYPTSER: - (void)printf("crypt "); - break; - } - switch (info & COI_MASK) { - case COI_32: - (void)printf("ver 3.2 "); - break; - case COI_31: - (void)printf("ver 3.1 "); - break; - case COI_40: - (void)printf("ver 4.0 "); - break; - case COI_41: - (void)printf("ver 4.1 "); - break; - } - (void)printf("segsize %d ", segsize); -#ifdef PRINT_NSPDATA - dp = &(nspp[sizeof(struct cimsg)]); - pdata(dp, nsplen - sizeof(struct cimsg)); -#endif - } - break; - case MFS_CC: - (void)printf("conn-confirm %d>%d ", src, dst); - { - struct ccmsg *ccmp = (struct ccmsg *)nspp; - int services, info; - u_int segsize, optlen; -#ifdef PRINT_NSPDATA - u_char *dp; -#endif - - services = EXTRACT_LE_8BITS(ccmp->cc_services); - info = EXTRACT_LE_8BITS(ccmp->cc_info); - segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize); - optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen); - - switch (services & COS_MASK) { - case COS_NONE: - break; - case COS_SEGMENT: - (void)printf("seg "); - break; - case COS_MESSAGE: - (void)printf("msg "); - break; - case COS_CRYPTSER: - (void)printf("crypt "); - break; - } - switch (info & COI_MASK) { - case COI_32: - (void)printf("ver 3.2 "); - break; - case COI_31: - (void)printf("ver 3.1 "); - break; - case COI_40: - (void)printf("ver 4.0 "); - break; - case COI_41: - (void)printf("ver 4.1 "); - break; - } - (void)printf("segsize %d ", segsize); - if (optlen) { - (void)printf("optlen %d ", optlen); -#ifdef PRINT_NSPDATA - optlen = min(optlen, nsplen - sizeof(struct ccmsg)); - dp = &(nspp[sizeof(struct ccmsg)]); - pdata(dp, optlen); -#endif - } - } - break; - case MFS_DI: - (void)printf("disconn-initiate %d>%d ", src, dst); - { - struct dimsg *dimp = (struct dimsg *)nspp; - int reason; - u_int optlen; -#ifdef PRINT_NSPDATA - u_char *dp; -#endif - - reason = EXTRACT_LE_16BITS(dimp->di_reason); - optlen = EXTRACT_LE_8BITS(dimp->di_optlen); - - print_reason(reason); - if (optlen) { - (void)printf("optlen %d ", optlen); -#ifdef PRINT_NSPDATA - optlen = min(optlen, nsplen - sizeof(struct dimsg)); - dp = &(nspp[sizeof(struct dimsg)]); - pdata(dp, optlen); -#endif - } - } - break; - case MFS_DC: - (void)printf("disconn-confirm %d>%d ", src, dst); - { - struct dcmsg *dcmp = (struct dcmsg *)nspp; - int reason; - - reason = EXTRACT_LE_16BITS(dcmp->dc_reason); - - print_reason(reason); - } - break; - default: - (void)printf("reserved-ctltype? %x %d > %d", flags, src, dst); - break; - } - break; - default: - (void)printf("reserved-type? %x %d > %d", flags, src, dst); - break; - } -} - -static struct tok reason2str[] = { - { UC_OBJREJECT, "object rejected connect" }, - { UC_RESOURCES, "insufficient resources" }, - { UC_NOSUCHNODE, "unrecognized node name" }, - { DI_SHUT, "node is shutting down" }, - { UC_NOSUCHOBJ, "unrecognized object" }, - { UC_INVOBJFORMAT, "invalid object name format" }, - { UC_OBJTOOBUSY, "object too busy" }, - { DI_PROTOCOL, "protocol error discovered" }, - { DI_TPA, "third party abort" }, - { UC_USERABORT, "user abort" }, - { UC_INVNODEFORMAT, "invalid node name format" }, - { UC_LOCALSHUT, "local node shutting down" }, - { DI_LOCALRESRC, "insufficient local resources" }, - { DI_REMUSERRESRC, "insufficient remote user resources" }, - { UC_ACCESSREJECT, "invalid access control information" }, - { DI_BADACCNT, "bad ACCOUNT information" }, - { UC_NORESPONSE, "no response from object" }, - { UC_UNREACHABLE, "node unreachable" }, - { DC_NOLINK, "no link terminate" }, - { DC_COMPLETE, "disconnect complete" }, - { DI_BADIMAGE, "bad image data in connect" }, - { DI_SERVMISMATCH, "cryptographic service mismatch" }, - { 0, NULL } -}; - -static void -print_reason(register int reason) -{ - printf("%s ", tok2str(reason2str, "reason-%d", reason)); -} - -char * -dnnum_string(u_short dnaddr) -{ - char *str; - int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT; - int node = dnaddr & NODEMASK; - - str = (char *)malloc(sizeof("00.0000")); - if (str == NULL) - error("dnnum_string: malloc"); - sprintf(str, "%d.%d", area, node); - return(str); -} - -char * -dnname_string(u_short dnaddr) -{ -#ifdef HAVE_LIBDNET - struct dn_naddr dna; - - dna.a_len = sizeof(short); - memcpy((char *)dna.a_addr, (char *)&dnaddr, sizeof(short)); - return (savestr(dnet_htoa(&dna))); -#else - return(dnnum_string(dnaddr)); /* punt */ -#endif -} - -#ifdef PRINT_NSPDATA -static void -pdata(u_char *dp, u_int maxlen) -{ - char c; - u_int x = maxlen; - - while (x-- > 0) { - c = *dp++; - if (isprint(c)) - putchar(c); - else - printf("\\%o", c & 0xFF); - } -} -#endif diff --git a/tcpdump.tproj/print-domain.c b/tcpdump.tproj/print-domain.c deleted file mode 100644 index c6175ae..0000000 --- a/tcpdump.tproj/print-domain.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-domain.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#undef NOERROR /* Solaris sucks */ -#undef T_UNSPEC /* SINIX does too */ -#include - -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ - -/* Compatibility */ -#ifndef T_TXT -#define T_TXT 16 /* text strings */ -#endif -#ifndef T_RP -#define T_RP 17 /* responsible person */ -#endif -#ifndef T_AFSDB -#define T_AFSDB 18 /* AFS cell database */ -#endif -#ifndef T_X25 -#define T_X25 19 /* X_25 calling address */ -#endif -#ifndef T_ISDN -#define T_ISDN 20 /* ISDN calling address */ -#endif -#ifndef T_RT -#define T_RT 21 /* router */ -#endif -#ifndef T_NSAP -#define T_NSAP 22 /* NSAP address */ -#endif -#ifndef T_NSAP_PTR -#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */ -#endif -#ifndef T_SIG -#define T_SIG 24 /* security signature */ -#endif -#ifndef T_KEY -#define T_KEY 25 /* security key */ -#endif -#ifndef T_PX -#define T_PX 26 /* X.400 mail mapping */ -#endif -#ifndef T_GPOS -#define T_GPOS 27 /* geographical position (withdrawn) */ -#endif -#ifndef T_AAAA -#define T_AAAA 28 /* IP6 Address */ -#endif -#ifndef T_LOC -#define T_LOC 29 /* Location Information */ -#endif - -#ifndef T_UNSPEC -#define T_UNSPEC 103 /* Unspecified format (binary data) */ -#endif -#ifndef T_UNSPECA -#define T_UNSPECA 104 /* "unspecified ascii". Ugly MIT hack */ -#endif - -#ifndef C_CHAOS -#define C_CHAOS 3 /* for chaos net (MIT) */ -#endif -#ifndef C_HS -#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */ -#endif - -static char *ns_ops[] = { - "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7", - " op8", " updataA", " updateD", " updateDA", - " updateM", " updateMA", " zoneInit", " zoneRef", -}; - -static char *ns_resp[] = { - "", " FormErr", " ServFail", " NXDomain", - " NotImp", " Refused", " Resp6", " Resp7", - " Resp8", " Resp9", " Resp10", " Resp11", - " Resp12", " Resp13", " Resp14", " NoChange", -}; - -/* skip over a domain name */ -static const u_char * -ns_nskip(register const u_char *cp, register const u_char *bp) -{ - register u_char i; - - if (((i = *cp++) & INDIR_MASK) == INDIR_MASK) - return (cp + 1); - while (i && cp < snapend) { - cp += i; - i = *cp++; - } - return (cp); -} - -/* print a */ -static const u_char * -ns_nprint(register const u_char *cp, register const u_char *bp) -{ - register u_int i; - register const u_char *rp; - register int compress; - - i = *cp++; - rp = cp + i; - if ((i & INDIR_MASK) == INDIR_MASK) { - rp = cp + 1; - compress = 1; - } else - compress = 0; - if (i != 0) - while (i && cp < snapend) { - if ((i & INDIR_MASK) == INDIR_MASK) { - cp = bp + (((i << 8) | *cp) & 0x3fff); - i = *cp++; - continue; - } - if (fn_printn(cp, i, snapend)) - break; - cp += i; - putchar('.'); - i = *cp++; - if (!compress) - rp += i + 1; - } - else - putchar('.'); - return (rp); -} - -/* print a */ -static const u_char * -ns_cprint(register const u_char *cp, register const u_char *bp) -{ - register u_int i; - - i = *cp++; - (void)fn_printn(cp, i, snapend); - return (cp + i); -} - -static struct tok type2str[] = { - { T_A, "A" }, - { T_NS, "NS" }, - { T_MD, "MD" }, - { T_MF, "MF" }, - { T_CNAME, "CNAME" }, - { T_SOA, "SOA" }, - { T_MB, "MB" }, - { T_MG, "MG" }, - { T_MR, "MR" }, - { T_NULL, "NULL" }, - { T_WKS, "WKS" }, - { T_PTR, "PTR" }, - { T_HINFO, "HINFO" }, - { T_MINFO, "MINFO" }, - { T_MX, "MX" }, - { T_TXT, "TXT" }, - { T_RP, "RP" }, - { T_AFSDB, "AFSDB" }, - { T_X25, "X25" }, - { T_ISDN, "ISDN" }, - { T_RT, "RT" }, - { T_NSAP, "NSAP" }, - { T_NSAP_PTR, "NSAP_PTR" }, - { T_SIG, "SIG" }, - { T_KEY, "KEY" }, - { T_PX, "PX" }, - { T_GPOS, "GPOS" }, - { T_AAAA, "AAAA" }, - { T_LOC , "LOC " }, - { T_UINFO, "UINFO" }, - { T_UID, "UID" }, - { T_GID, "GID" }, - { T_UNSPEC, "UNSPEC" }, - { T_UNSPECA, "UNSPECA" }, - { T_AXFR, "AXFR" }, - { T_MAILB, "MAILB" }, - { T_MAILA, "MAILA" }, - { T_ANY, "ANY" }, - { 0, NULL } -}; - -static struct tok class2str[] = { - { C_IN, "IN" }, /* Not used */ - { C_CHAOS, "CHAOS)" }, - { C_HS, "HS" }, - { C_ANY, "ANY" }, - { 0, NULL } -}; - -/* print a query */ -static void -ns_qprint(register const u_char *cp, register const u_char *bp) -{ - register const u_char *np = cp; - register u_int i; - - cp = ns_nskip(cp, bp); - - if (cp + 4 > snapend) - return; - - /* print the qtype and qclass (if it's not IN) */ - i = *cp++ << 8; - i |= *cp++; - printf(" %s", tok2str(type2str, "Type%d", i)); - i = *cp++ << 8; - i |= *cp++; - if (i != C_IN) - printf(" %s", tok2str(class2str, "(Class %d)", i)); - - fputs("? ", stdout); - ns_nprint(np, bp); -} - -/* print a reply */ -static const u_char * -ns_rprint(register const u_char *cp, register const u_char *bp) -{ - register u_int i; - register u_short typ, len; - register const u_char *rp; - - if (vflag) { - putchar(' '); - cp = ns_nprint(cp, bp); - } else - cp = ns_nskip(cp, bp); - - if (cp + 10 > snapend) - return (snapend); - - /* print the type/qtype and class (if it's not IN) */ - typ = *cp++ << 8; - typ |= *cp++; - i = *cp++ << 8; - i |= *cp++; - if (i != C_IN) - printf(" %s", tok2str(class2str, "(Class %d)", i)); - - /* ignore ttl */ - cp += 4; - - len = *cp++ << 8; - len |= *cp++; - - rp = cp + len; - - printf(" %s", tok2str(type2str, "Type%d", typ)); - switch (typ) { - - case T_A: - printf(" %s", ipaddr_string(cp)); - break; - - case T_NS: - case T_CNAME: - case T_PTR: - putchar(' '); - (void)ns_nprint(cp, bp); - break; - - case T_MX: - putchar(' '); - (void)ns_nprint(cp + 2, bp); - printf(" %d", EXTRACT_16BITS(cp)); - break; - - case T_TXT: - putchar(' '); - (void)ns_cprint(cp, bp); - break; - - case T_UNSPECA: /* One long string */ - printf(" %.*s", len, cp); - break; - } - return (rp); /* XXX This isn't always right */ -} - -void -ns_print(register const u_char *bp, u_int length) -{ - register const HEADER *np; - register int qdcount, ancount, nscount, arcount; - register const u_char *cp; - - np = (const HEADER *)bp; - /* get the byte-order right */ - qdcount = ntohs(np->qdcount); - ancount = ntohs(np->ancount); - nscount = ntohs(np->nscount); - arcount = ntohs(np->arcount); - - if (np->qr) { - /* this is a response */ - printf(" %d%s%s%s%s%s", - ntohs(np->id), - ns_ops[np->opcode], - ns_resp[np->rcode], - np->aa? "*" : "", - np->ra? "" : "-", - np->tc? "|" : ""); - if (qdcount != 1) - printf(" [%dq]", qdcount); - /* Print QUESTION section on -vv */ - if (vflag > 1) { - fputs(" q: ", stdout); - cp = ns_nprint((const u_char *)(np + 1), bp); - } else - cp = ns_nskip((const u_char *)(np + 1), bp); - printf(" %d/%d/%d", ancount, nscount, arcount); - if (ancount--) { - cp = ns_rprint(cp + 4, bp); - while (ancount-- && cp < snapend) { - putchar(','); - cp = ns_rprint(cp, bp); - } - } - } - else { - /* this is a request */ - printf(" %d%s%s", - ntohs(np->id), - ns_ops[np->opcode], - np->rd? "+" : ""); - - /* any weirdness? */ - if (*(((u_short *)np)+1) & htons(0x6ff)) - printf(" [b2&3=0x%x]", ntohs(*(((u_short *)np)+1))); - - if (np->opcode == IQUERY) { - if (qdcount) - printf(" [%dq]", qdcount); - if (ancount != 1) - printf(" [%da]", ancount); - } - else { - if (ancount) - printf(" [%da]", ancount); - if (qdcount != 1) - printf(" [%dq]", qdcount); - } - if (nscount) - printf(" [%dn]", nscount); - if (arcount) - printf(" [%dau]", arcount); - - ns_qprint((const u_char *)(np + 1), (const u_char *)np); - } - printf(" (%d)", length); -} diff --git a/tcpdump.tproj/print-dvmrp.c b/tcpdump.tproj/print-dvmrp.c deleted file mode 100644 index a396cf9..0000000 --- a/tcpdump.tproj/print-dvmrp.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-dvmrp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#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/tcpdump.tproj/print-egp.c b/tcpdump.tproj/print-egp.c deleted file mode 100644 index 092c2b5..0000000 --- a/tcpdump.tproj/print-egp.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1991, 1992, 1993, 1994, 1995, 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU). - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-egp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -struct egp_packet { - u_char egp_version; -#define EGP_VERSION 2 - u_char egp_type; -#define EGPT_ACQUIRE 3 -#define EGPT_REACH 5 -#define EGPT_POLL 2 -#define EGPT_UPDATE 1 -#define EGPT_ERROR 8 - u_char egp_code; -#define EGPC_REQUEST 0 -#define EGPC_CONFIRM 1 -#define EGPC_REFUSE 2 -#define EGPC_CEASE 3 -#define EGPC_CEASEACK 4 -#define EGPC_HELLO 0 -#define EGPC_HEARDU 1 - u_char egp_status; -#define EGPS_UNSPEC 0 -#define EGPS_ACTIVE 1 -#define EGPS_PASSIVE 2 -#define EGPS_NORES 3 -#define EGPS_ADMIN 4 -#define EGPS_GODOWN 5 -#define EGPS_PARAM 6 -#define EGPS_PROTO 7 -#define EGPS_INDET 0 -#define EGPS_UP 1 -#define EGPS_DOWN 2 -#define EGPS_UNSOL 0x80 - u_short egp_checksum; - u_short egp_as; - u_short egp_sequence; - union { - u_short egpu_hello; - u_char egpu_gws[2]; - u_short egpu_reason; -#define EGPR_UNSPEC 0 -#define EGPR_BADHEAD 1 -#define EGPR_BADDATA 2 -#define EGPR_NOREACH 3 -#define EGPR_XSPOLL 4 -#define EGPR_NORESP 5 -#define EGPR_UVERSION 6 - } egp_handg; -#define egp_hello egp_handg.egpu_hello -#define egp_intgw egp_handg.egpu_gws[0] -#define egp_extgw egp_handg.egpu_gws[1] -#define egp_reason egp_handg.egpu_reason - union { - u_short egpu_poll; - u_int32_t egpu_sourcenet; - } egp_pands; -#define egp_poll egp_pands.egpu_poll -#define egp_sourcenet egp_pands.egpu_sourcenet -}; - -char *egp_acquire_codes[] = { - "request", - "confirm", - "refuse", - "cease", - "cease_ack" -}; - -char *egp_acquire_status[] = { - "unspecified", - "active_mode", - "passive_mode", - "insufficient_resources", - "administratively_prohibited", - "going_down", - "parameter_violation", - "protocol_violation" -}; - -char *egp_reach_codes[] = { - "hello", - "i-h-u" -}; - -char *egp_status_updown[] = { - "indeterminate", - "up", - "down" -}; - -char *egp_reasons[] = { - "unspecified", - "bad_EGP_header_format", - "bad_EGP_data_field_format", - "reachability_info_unavailable", - "excessive_polling_rate", - "no_response", - "unsupported_version" -}; - -static void -egpnrprint(register const struct egp_packet *egp, register u_int length) -{ - register const u_char *cp; - u_int32_t addr; - register u_int32_t net; - register u_int netlen; - int gateways, distances, networks; - int t_gateways; - char *comma; - - addr = egp->egp_sourcenet; - if (IN_CLASSA(addr)) { - net = addr & IN_CLASSA_NET; - netlen = 1; - } else if (IN_CLASSB(addr)) { - net = addr & IN_CLASSB_NET; - netlen = 2; - } else if (IN_CLASSC(addr)) { - net = addr & IN_CLASSC_NET; - netlen = 3; - } else { - net = 0; - netlen = 0; - } - cp = (u_char *)(egp + 1); - - t_gateways = egp->egp_intgw + egp->egp_extgw; - for (gateways = 0; gateways < t_gateways; ++gateways) { - /* Pickup host part of gateway address */ - addr = 0; - TCHECK2(cp[0], 4 - netlen); - switch (netlen) { - - case 1: - addr = *cp++; - /* fall through */ - case 2: - addr = (addr << 8) | *cp++; - /* fall through */ - case 3: - addr = (addr << 8) | *cp++; - } - addr |= net; - TCHECK2(cp[0], 1); - distances = *cp++; - printf(" %s %s ", - gateways < (int)egp->egp_intgw ? "int" : "ext", - ipaddr_string(&addr)); - - comma = ""; - putchar('('); - while (--distances >= 0) { - TCHECK2(cp[0], 2); - printf("%sd%d:", comma, (int)*cp++); - comma = ", "; - networks = *cp++; - while (--networks >= 0) { - /* Pickup network number */ - TCHECK2(cp[0], 1); - addr = (u_int32_t)*cp++ << 24; - if (IN_CLASSB(addr)) { - TCHECK2(cp[0], 1); - addr |= (u_int32_t)*cp++ << 16; - } else if (!IN_CLASSA(addr)) { - TCHECK2(cp[0], 2); - addr |= (u_int32_t)*cp++ << 16; - addr |= (u_int32_t)*cp++ << 8; - } - printf(" %s", ipaddr_string(&addr)); - } - } - putchar(')'); - } - return; -trunc: - fputs("[|]", stdout); -} - -void -egp_print(register const u_char *bp, register u_int length, - register const u_char *bp2) -{ - register const struct egp_packet *egp; - register const struct ip *ip; - register int status; - register int code; - register int type; - - egp = (struct egp_packet *)bp; - ip = (struct ip *)bp2; - (void)printf("%s > %s: egp: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - - if (egp->egp_version != EGP_VERSION) { - printf("[version %d]", egp->egp_version); - return; - } - printf("as:%d seq:%d", ntohs(egp->egp_as), ntohs(egp->egp_sequence)); - - type = egp->egp_type; - code = egp->egp_code; - status = egp->egp_status; - - switch (type) { - case EGPT_ACQUIRE: - printf(" acquire"); - switch (code) { - case EGPC_REQUEST: - case EGPC_CONFIRM: - printf(" %s", egp_acquire_codes[code]); - switch (status) { - case EGPS_UNSPEC: - case EGPS_ACTIVE: - case EGPS_PASSIVE: - printf(" %s", egp_acquire_status[status]); - break; - - default: - printf(" [status %d]", status); - break; - } - printf(" hello:%d poll:%d", - ntohs(egp->egp_hello), - ntohs(egp->egp_poll)); - break; - - case EGPC_REFUSE: - case EGPC_CEASE: - case EGPC_CEASEACK: - printf(" %s", egp_acquire_codes[code]); - switch (status ) { - case EGPS_UNSPEC: - case EGPS_NORES: - case EGPS_ADMIN: - case EGPS_GODOWN: - case EGPS_PARAM: - case EGPS_PROTO: - printf(" %s", egp_acquire_status[status]); - break; - - default: - printf("[status %d]", status); - break; - } - break; - - default: - printf("[code %d]", code); - break; - } - break; - - case EGPT_REACH: - switch (code) { - - case EGPC_HELLO: - case EGPC_HEARDU: - printf(" %s", egp_reach_codes[code]); - if (status <= EGPS_DOWN) - printf(" state:%s", egp_status_updown[status]); - else - printf(" [status %d]", status); - break; - - default: - printf("[reach code %d]", code); - break; - } - break; - - case EGPT_POLL: - printf(" poll"); - if (egp->egp_status <= EGPS_DOWN) - printf(" state:%s", egp_status_updown[status]); - else - printf(" [status %d]", status); - printf(" net:%s", ipaddr_string(&egp->egp_sourcenet)); - break; - - case EGPT_UPDATE: - printf(" update"); - if (status & EGPS_UNSOL) { - status &= ~EGPS_UNSOL; - printf(" unsolicited"); - } - if (status <= EGPS_DOWN) - printf(" state:%s", egp_status_updown[status]); - else - printf(" [status %d]", status); - printf(" %s int %d ext %d", - ipaddr_string(&egp->egp_sourcenet), - egp->egp_intgw, - egp->egp_extgw); - if (vflag) - egpnrprint(egp, length); - break; - - case EGPT_ERROR: - printf(" error"); - if (status <= EGPS_DOWN) - printf(" state:%s", egp_status_updown[status]); - else - printf(" [status %d]", status); - - if (ntohs(egp->egp_reason) <= EGPR_UVERSION) - printf(" %s", egp_reasons[ntohs(egp->egp_reason)]); - else - printf(" [reason %d]", ntohs(egp->egp_reason)); - break; - - default: - printf("[type %d]", type); - break; - } -} diff --git a/tcpdump.tproj/print-ether.c b/tcpdump.tproj/print-ether.c deleted file mode 100644 index ae9ddd9..0000000 --- a/tcpdump.tproj/print-ether.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ether.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#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" - -const u_char *packetp; -const u_char *snapend; - -static inline void -ether_print(register const u_char *bp, u_int length) -{ - register const struct ether_header *ep; - - ep = (const struct ether_header *)bp; - if (qflag) - (void)printf("%s %s %d: ", - etheraddr_string(ESRC(ep)), - etheraddr_string(EDST(ep)), - length); - else - (void)printf("%s %s %s %d: ", - etheraddr_string(ESRC(ep)), - etheraddr_string(EDST(ep)), - etherproto_string(ep->ether_type), - length); -} - -/* - * This is the top level routine of the printer. 'p' is the points - * to the ether 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 -ether_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - u_int caplen = h->caplen; - u_int length = h->len; - struct ether_header *ep; - u_short ether_type; - extern u_short extracted_ethertype; - - ts_print(&h->ts); - - if (caplen < sizeof(struct ether_header)) { - printf("[|ether]"); - goto out; - } - - if (eflag) - ether_print(p, length); - - /* - * 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 -= sizeof(struct ether_header); - caplen -= sizeof(struct ether_header); - ep = (struct ether_header *)p; - p += sizeof(struct ether_header); - - ether_type = ntohs(ep->ether_type); - - /* - * Is it (gag) an 802.3 encapsulation? - */ - extracted_ethertype = 0; - if (ether_type < ETHERMTU) { - /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(ep), EDST(ep)) == 0) { - /* ether_type not known, print raw packet */ - if (!eflag) - ether_print((u_char *)ep, length); - if (extracted_ethertype) { - printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); - } - if (!xflag && !qflag) - default_print(p, caplen); - } - } else if (ether_encap_print(ether_type, p, length, caplen) == 0) { - /* ether_type not known, print raw packet */ - if (!eflag) - ether_print((u_char *)ep, length + sizeof(*ep)); - if (!xflag && !qflag) - default_print(p, caplen); - } - if (xflag) - default_print(p, caplen); - out: - putchar('\n'); -} - -/* - * Prints the packet encapsulated in an Ethernet data segment - * (or an equivalent encapsulation), given the Ethernet type code. - * - * Returns non-zero if it can do so, zero if the ethertype is unknown. - * - * Stuffs the ether type into a global for the benefit of lower layers - * that might want to know what it is. - */ - -u_short extracted_ethertype; - -int -ether_encap_print(u_short ethertype, const u_char *p, - u_int length, u_int caplen) -{ - extracted_ethertype = ethertype; - - switch (ethertype) { - - case ETHERTYPE_IP: - ip_print(p, length); - return (1); - - case ETHERTYPE_ARP: - case ETHERTYPE_REVARP: - arp_print(p, length, caplen); - return (1); - - case ETHERTYPE_DN: - decnet_print(p, length, caplen); - return (1); - - case ETHERTYPE_ATALK: - if (vflag) - fputs("et1 ", stdout); - atalk_print(p, length); - return (1); - - case ETHERTYPE_AARP: - aarp_print(p, length); - return (1); - - case ETHERTYPE_LAT: - case ETHERTYPE_SCA: - case ETHERTYPE_MOPRC: - case ETHERTYPE_MOPDL: - /* default_print for now */ - default: - return (0); - } -} diff --git a/tcpdump.tproj/print-fddi.c b/tcpdump.tproj/print-fddi.c deleted file mode 100644 index 15f8297..0000000 --- a/tcpdump.tproj/print-fddi.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-fddi.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#ifdef HAVE_FDDI -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "ethertype.h" - -#include "fddi.h" - -/* - * Some FDDI interfaces use bit-swapped addresses. - */ -#if defined(ultrix) || defined(__alpha) -int fddi_bitswap = 0; -#else -int fddi_bitswap = 1; -#endif - -/* - * FDDI support for tcpdump, by Jeffrey Mogul [DECWRL], June 1992 - * - * Based in part on code by Van Jacobson, which bears this note: - * - * NOTE: This is a very preliminary hack for FDDI support. - * There are all sorts of wired in constants & nothing (yet) - * to print SMT packets as anything other than hex dumps. - * Most of the necessary changes are waiting on my redoing - * the "header" that a kernel fddi driver supplies to bpf: I - * want it to look like one byte of 'direction' (0 or 1 - * depending on whether the packet was inbound or outbound), - * two bytes of system/driver dependent data (anything an - * implementor thinks would be useful to filter on and/or - * save per-packet, then the real 21-byte FDDI header. - * Steve McCanne & I have also talked about adding the - * 'direction' byte to all bpf headers (e.g., in the two - * bytes of padding on an ethernet header). It's not clear - * we could do this in a backwards compatible way & we hate - * the idea of an incompatible bpf change. Discussions are - * proceeding. - * - * Also, to really support FDDI (and better support 802.2 - * over ethernet) we really need to re-think the rather simple - * minded assumptions about fixed length & fixed format link - * level headers made in gencode.c. One day... - * - * - vj - */ - -#define FDDI_HDRLEN (sizeof(struct fddi_header)) - -static u_char fddi_bit_swap[] = { - 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, - 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, - 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, - 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, - 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, - 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, - 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, - 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, - 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, - 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, - 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, - 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, - 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, - 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, - 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, - 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, - 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, - 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, - 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, - 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, - 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, - 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, - 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, - 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, - 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, - 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, - 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, - 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, - 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, - 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, - 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, - 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, -}; - -/* - * Print FDDI frame-control bits - */ -static inline void -print_fddi_fc(u_char fc) -{ - switch (fc) { - - case FDDIFC_VOID: /* Void frame */ - printf("void "); - break; - - case FDDIFC_NRT: /* Nonrestricted token */ - printf("nrt "); - break; - - case FDDIFC_RT: /* Restricted token */ - printf("rt "); - break; - - case FDDIFC_SMT_INFO: /* SMT Info */ - printf("info "); - break; - - case FDDIFC_SMT_NSA: /* SMT Next station adrs */ - printf("nsa "); - break; - - case FDDIFC_MAC_BEACON: /* MAC Beacon frame */ - printf("beacon "); - break; - - case FDDIFC_MAC_CLAIM: /* MAC Claim frame */ - printf("claim "); - break; - - default: - switch (fc & FDDIFC_CLFF) { - - case FDDIFC_MAC: - printf("mac%1x ", fc & FDDIFC_ZZZZ); - break; - - case FDDIFC_SMT: - printf("smt%1x ", fc & FDDIFC_ZZZZ); - break; - - case FDDIFC_LLC_ASYNC: - printf("async%1x ", fc & FDDIFC_ZZZZ); - break; - - case FDDIFC_LLC_SYNC: - printf("sync%1x ", fc & FDDIFC_ZZZZ); - break; - - case FDDIFC_IMP_ASYNC: - printf("imp_async%1x ", fc & FDDIFC_ZZZZ); - break; - - case FDDIFC_IMP_SYNC: - printf("imp_sync%1x ", fc & FDDIFC_ZZZZ); - break; - - default: - printf("%02x ", fc); - break; - } - } -} - -/* Extract src, dst addresses */ -static inline void -extract_fddi_addrs(const struct fddi_header *fddip, char *fsrc, char *fdst) -{ - register int i; - - if (fddi_bitswap) { - /* - * bit-swap the fddi addresses (isn't the IEEE standards - * process wonderful!) then convert them to names. - */ - for (i = 0; i < 6; ++i) - fdst[i] = fddi_bit_swap[fddip->fddi_dhost[i]]; - for (i = 0; i < 6; ++i) - fsrc[i] = fddi_bit_swap[fddip->fddi_shost[i]]; - } - else { - memcpy(fdst, (char *)fddip->fddi_dhost, 6); - memcpy(fsrc, (char *)fddip->fddi_shost, 6); - } -} - -/* - * Print the FDDI MAC header - */ -static inline void -fddi_print(register const struct fddi_header *fddip, register u_int length, - register const u_char *fsrc, register const u_char *fdst) -{ - char *srcname, *dstname; - - srcname = etheraddr_string(fsrc); - dstname = etheraddr_string(fdst); - - if (vflag) - (void) printf("%02x %s %s %d: ", - fddip->fddi_fc, - srcname, dstname, - length); - else if (qflag) - printf("%s %s %d: ", srcname, dstname, length); - else { - (void) print_fddi_fc(fddip->fddi_fc); - (void) printf("%s %s %d: ", srcname, dstname, length); - } -} - -static inline void -fddi_smt_print(const u_char *p, u_int length) -{ - printf(""); -} - -/* - * This is the top level routine of the printer. 'sp' is the points - * to the FDDI 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 -fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, - register const u_char *p) -{ - u_int caplen = h->caplen; - u_int length = h->len; - const struct fddi_header *fddip = (struct fddi_header *)p; - extern u_short extracted_ethertype; - struct ether_header ehdr; - - ts_print(&h->ts); - - if (caplen < FDDI_HDRLEN) { - printf("[|fddi]"); - goto out; - } - /* - * Get the FDDI addresses into a canonical form - */ - extract_fddi_addrs(fddip, (char *)ESRC(&ehdr), (char *)EDST(&ehdr)); - /* - * 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. - */ - snapend = p + caplen; - /* - * Actually, the only printer that uses packetp is print-bootp.c, - * and it assumes that packetp points to an Ethernet header. The - * right thing to do is to fix print-bootp.c to know which link - * type is in use when it excavates. XXX - */ - packetp = (u_char *)&ehdr; - - if (eflag) - fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); - - /* Skip over FDDI MAC header */ - length -= FDDI_HDRLEN; - p += FDDI_HDRLEN; - caplen -= FDDI_HDRLEN; - - /* Frame Control field determines interpretation of packet */ - extracted_ethertype = 0; - if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_LLC_ASYNC) { - /* Try to print the LLC-layer header & higher layers */ - if (llc_print(p, length, caplen, ESRC(&ehdr), EDST(&ehdr)) - == 0) { - /* - * Some kinds of LLC packet we cannot - * handle intelligently - */ - if (!eflag) - fddi_print(fddip, length, - ESRC(&ehdr), EDST(&ehdr)); - if (extracted_ethertype) { - printf("(LLC %s) ", - etherproto_string(htons(extracted_ethertype))); - } - if (!xflag && !qflag) - default_print(p, caplen); - } - } else if ((fddip->fddi_fc & FDDIFC_CLFF) == FDDIFC_SMT) - fddi_smt_print(p, caplen); - else { - /* Some kinds of FDDI packet we cannot handle intelligently */ - if (!eflag) - fddi_print(fddip, length, ESRC(&ehdr), EDST(&ehdr)); - if (!xflag && !qflag) - default_print(p, caplen); - } - if (xflag) - default_print(p, caplen); -out: - putchar('\n'); -} -#else -#include -#include - -#include - -#include "interface.h" -void -fddi_if_print(u_char *pcap, const struct pcap_pkthdr *h, - register const u_char *p) -{ - - error("not configured for fddi"); - /* NOTREACHED */ -} -#endif diff --git a/tcpdump.tproj/print-gre.c b/tcpdump.tproj/print-gre.c deleted file mode 100644 index 94e42db..0000000 --- a/tcpdump.tproj/print-gre.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-gre.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $"; -#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/tcpdump.tproj/print-icmp.c b/tcpdump.tproj/print-icmp.c deleted file mode 100644 index d4eb3fa..0000000 --- a/tcpdump.tproj/print-icmp.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-icmp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ - -/* rfc1700 */ -#ifndef ICMP_UNREACH_NET_UNKNOWN -#define ICMP_UNREACH_NET_UNKNOWN 6 /* destination net unknown */ -#endif -#ifndef ICMP_UNREACH_HOST_UNKNOWN -#define ICMP_UNREACH_HOST_UNKNOWN 7 /* destination host unknown */ -#endif -#ifndef ICMP_UNREACH_ISOLATED -#define ICMP_UNREACH_ISOLATED 8 /* source host isolated */ -#endif -#ifndef ICMP_UNREACH_NET_PROHIB -#define ICMP_UNREACH_NET_PROHIB 9 /* admin prohibited net */ -#endif -#ifndef ICMP_UNREACH_HOST_PROHIB -#define ICMP_UNREACH_HOST_PROHIB 10 /* admin prohibited host */ -#endif -#ifndef ICMP_UNREACH_TOSNET -#define ICMP_UNREACH_TOSNET 11 /* tos prohibited net */ -#endif -#ifndef ICMP_UNREACH_TOSHOST -#define ICMP_UNREACH_TOSHOST 12 /* tos prohibited host */ -#endif - -/* rfc1716 */ -#ifndef ICMP_UNREACH_FILTER_PROHIB -#define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohibited filter */ -#endif -#ifndef ICMP_UNREACH_HOST_PRECEDENCE -#define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host precedence violation */ -#endif -#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF -#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ -#endif - -/* rfc1256 */ -#ifndef ICMP_ROUTERADVERT -#define ICMP_ROUTERADVERT 9 /* router advertisement */ -#endif -#ifndef ICMP_ROUTERSOLICIT -#define ICMP_ROUTERSOLICIT 10 /* router solicitation */ -#endif - -/* Most of the icmp types */ -static struct tok icmp2str[] = { - { ICMP_ECHOREPLY, "echo reply" }, - { ICMP_SOURCEQUENCH, "source quench" }, - { ICMP_ECHO, "echo request" }, - { ICMP_ROUTERSOLICIT, "router solicitation" }, - { ICMP_TSTAMP, "time stamp request" }, - { ICMP_TSTAMPREPLY, "time stamp reply" }, - { ICMP_IREQ, "information request" }, - { ICMP_IREQREPLY, "information reply" }, - { ICMP_MASKREQ, "address mask request" }, - { 0, NULL } -}; - -/* Formats for most of the ICMP_UNREACH codes */ -static struct tok unreach2str[] = { - { ICMP_UNREACH_NET, "net %s unreachable" }, - { ICMP_UNREACH_HOST, "host %s unreachable" }, - { ICMP_UNREACH_SRCFAIL, - "%s unreachable - source route failed" }, - { ICMP_UNREACH_NET_UNKNOWN, "net %s unreachable - unknown" }, - { ICMP_UNREACH_HOST_UNKNOWN, "host %s unreachable - unknown" }, - { ICMP_UNREACH_ISOLATED, - "%s unreachable - source host isolated" }, - { ICMP_UNREACH_NET_PROHIB, - "net %s unreachable - admin prohibited" }, - { ICMP_UNREACH_HOST_PROHIB, - "host %s unreachable - admin prohibited" }, - { ICMP_UNREACH_TOSNET, - "net %s unreachable - tos prohibited" }, - { ICMP_UNREACH_TOSHOST, - "host %s unreachable - tos prohibited" }, - { ICMP_UNREACH_FILTER_PROHIB, - "host %s unreachable - admin prohibited filter" }, - { ICMP_UNREACH_HOST_PRECEDENCE, - "host %s unreachable - host precedence violation" }, - { ICMP_UNREACH_PRECEDENCE_CUTOFF, - "host %s unreachable - precedence cutoff" }, - { 0, NULL } -}; - -/* Formats for the ICMP_REDIRECT codes */ -static struct tok type2str[] = { - { ICMP_REDIRECT_NET, "redirect %s to net %s" }, - { ICMP_REDIRECT_HOST, "redirect %s to host %s" }, - { ICMP_REDIRECT_TOSNET, "redirect-tos %s to net %s" }, - { ICMP_REDIRECT_TOSHOST, "redirect-tos %s to net %s" }, - { 0, NULL } -}; - -/* rfc1191 */ -struct mtu_discovery { - short unused; - short nexthopmtu; -}; - -/* rfc1256 */ -struct ih_rdiscovery { - u_char ird_addrnum; - u_char ird_addrsiz; - u_short ird_lifetime; -}; - -struct id_rdiscovery { - u_int32_t ird_addr; - u_int32_t ird_pref; -}; - -void -icmp_print(register const u_char *bp, register const u_char *bp2) -{ - register char *cp; - register const struct icmp *dp; - register const struct ip *ip; - register const char *str, *fmt; - register const struct ip *oip; - register const struct udphdr *ouh; - register u_int hlen, dport, mtu; - char buf[256]; - - dp = (struct icmp *)bp; - ip = (struct ip *)bp2; - str = buf; - - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - - TCHECK(dp->icmp_code); - switch (dp->icmp_type) { - - case ICMP_UNREACH: - TCHECK(dp->icmp_ip.ip_dst); - switch (dp->icmp_code) { - - case ICMP_UNREACH_PROTOCOL: - TCHECK(dp->icmp_ip.ip_p); - (void)sprintf(buf, "%s protocol %d unreachable", - ipaddr_string(&dp->icmp_ip.ip_dst), - dp->icmp_ip.ip_p); - break; - - case ICMP_UNREACH_PORT: - TCHECK(dp->icmp_ip.ip_p); - oip = &dp->icmp_ip; - hlen = oip->ip_hl * 4; - ouh = (struct udphdr *)(((u_char *)oip) + hlen); - dport = ntohs(ouh->uh_dport); - switch (oip->ip_p) { - - case IPPROTO_TCP: - (void)sprintf(buf, - "%s tcp port %s unreachable", - ipaddr_string(&oip->ip_dst), - tcpport_string(dport)); - break; - - case IPPROTO_UDP: - (void)sprintf(buf, - "%s udp port %s unreachable", - ipaddr_string(&oip->ip_dst), - udpport_string(dport)); - break; - - default: - (void)sprintf(buf, - "%s protocol %d port %d unreachable", - ipaddr_string(&oip->ip_dst), - oip->ip_p, dport); - break; - } - break; - - case ICMP_UNREACH_NEEDFRAG: - { - register const struct mtu_discovery *mp; - - mp = (struct mtu_discovery *)&dp->icmp_void; - mtu = EXTRACT_16BITS(&mp->nexthopmtu); - if (mtu) - (void)sprintf(buf, - "%s unreachable - need to frag (mtu %d)", - ipaddr_string(&dp->icmp_ip.ip_dst), mtu); - else - (void)sprintf(buf, - "%s unreachable - need to frag", - ipaddr_string(&dp->icmp_ip.ip_dst)); - } - break; - - default: - fmt = tok2str(unreach2str, "#%d %%s unreachable", - dp->icmp_code); - (void)sprintf(buf, fmt, - ipaddr_string(&dp->icmp_ip.ip_dst)); - break; - } - break; - - case ICMP_REDIRECT: - TCHECK(dp->icmp_ip.ip_dst); - fmt = tok2str(type2str, "redirect-#%d %%s to net %%s", - dp->icmp_code); - (void)sprintf(buf, fmt, - ipaddr_string(&dp->icmp_ip.ip_dst), - ipaddr_string(&dp->icmp_gwaddr)); - break; - - case ICMP_ROUTERADVERT: - { - register const struct ih_rdiscovery *ihp; - register const struct id_rdiscovery *idp; - u_int lifetime, num, size; - - (void)strcpy(buf, "router advertisement"); - cp = buf + strlen(buf); - - ihp = (struct ih_rdiscovery *)&dp->icmp_void; - TCHECK(*ihp); - (void)strcpy(cp, " lifetime "); - cp = buf + strlen(buf); - lifetime = EXTRACT_16BITS(&ihp->ird_lifetime); - if (lifetime < 60) - (void)sprintf(cp, "%u", lifetime); - else if (lifetime < 60 * 60) - (void)sprintf(cp, "%u:%02u", - lifetime / 60, lifetime % 60); - else - (void)sprintf(cp, "%u:%02u:%02u", - lifetime / 3600, - (lifetime % 3600) / 60, - lifetime % 60); - cp = buf + strlen(buf); - - num = ihp->ird_addrnum; - (void)sprintf(cp, " %d:", num); - cp = buf + strlen(buf); - - size = ihp->ird_addrsiz; - if (size != 2) { - (void)sprintf(cp, " [size %d]", size); - break; - } - idp = (struct id_rdiscovery *)&dp->icmp_data; - while (num-- > 0) { - TCHECK(*idp); - (void)sprintf(cp, " {%s %u}", - ipaddr_string(&idp->ird_addr), - EXTRACT_32BITS(&idp->ird_pref)); - cp = buf + strlen(buf); - } - } - break; - - case ICMP_TIMXCEED: - TCHECK(dp->icmp_ip.ip_dst); - switch (dp->icmp_code) { - - case ICMP_TIMXCEED_INTRANS: - str = "time exceeded in-transit"; - break; - - case ICMP_TIMXCEED_REASS: - str = "ip reassembly time exceeded"; - break; - - default: - (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code); - break; - } - break; - - case ICMP_PARAMPROB: - if (dp->icmp_code) - (void)sprintf(buf, "parameter problem - code %d", - dp->icmp_code); - else { - TCHECK(dp->icmp_pptr); - (void)sprintf(buf, "parameter problem - octet %d", - dp->icmp_pptr); - } - break; - - case ICMP_MASKREPLY: - TCHECK(dp->icmp_mask); - (void)sprintf(buf, "address mask is 0x%08x", - (u_int32_t)ntohl(dp->icmp_mask)); - break; - - default: - str = tok2str(icmp2str, "type-#%d", dp->icmp_type); - break; - } - (void)printf("icmp: %s", str); - return; -trunc: - fputs("[|icmp]", stdout); -} diff --git a/tcpdump.tproj/print-igrp.c b/tcpdump.tproj/print-igrp.c deleted file mode 100644 index a35e6ac..0000000 --- a/tcpdump.tproj/print-igrp.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - * - * Initial contribution from Francis Dupont (francis.dupont@inria.fr) - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-igrp.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "addrtoname.h" -#include "interface.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/tcpdump.tproj/print-ip.c b/tcpdump.tproj/print-ip.c deleted file mode 100644 index 6c0c31c..0000000 --- a/tcpdump.tproj/print-ip.c +++ /dev/null @@ -1,547 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ip.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "addrtoname.h" -#include "interface.h" -#include "extract.h" /* must come after interface.h */ - -/* Compatibility */ -#ifndef IPPROTO_ND -#define IPPROTO_ND 77 -#endif - -#ifndef IN_CLASSD -#define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000) -#endif - -/* (following from ipmulti/mrouted/prune.h) */ - -/* - * The packet format for a traceroute request. - */ -struct tr_query { - u_int tr_src; /* traceroute source */ - u_int tr_dst; /* traceroute destination */ - u_int tr_raddr; /* traceroute response address */ -#ifdef WORDS_BIGENDIAN - struct { - u_int ttl : 8; /* traceroute response ttl */ - u_int qid : 24; /* traceroute query id */ - } q; -#else - struct { - u_int qid : 24; /* traceroute query id */ - u_int ttl : 8; /* traceroute response ttl */ - } q; -#endif -}; - -#define tr_rttl q.ttl -#define tr_qid q.qid - -/* - * Traceroute response format. A traceroute response has a tr_query at the - * beginning, followed by one tr_resp for each hop taken. - */ -struct tr_resp { - u_int tr_qarr; /* query arrival time */ - u_int tr_inaddr; /* incoming interface address */ - u_int tr_outaddr; /* outgoing interface address */ - u_int tr_rmtaddr; /* parent address in source tree */ - u_int tr_vifin; /* input packet count on interface */ - u_int tr_vifout; /* output packet count on interface */ - u_int tr_pktcnt; /* total incoming packets for src-grp */ - u_char tr_rproto; /* routing proto deployed on router */ - u_char tr_fttl; /* ttl required to forward on outvif */ - u_char tr_smask; /* subnet mask for src addr */ - u_char tr_rflags; /* forwarding error codes */ -}; - -/* defs within mtrace */ -#define TR_QUERY 1 -#define TR_RESP 2 - -/* fields for tr_rflags (forwarding error codes) */ -#define TR_NO_ERR 0 -#define TR_WRONG_IF 1 -#define TR_PRUNED 2 -#define TR_OPRUNED 3 -#define TR_SCOPED 4 -#define TR_NO_RTE 5 -#define TR_NO_FWD 7 -#define TR_NO_SPACE 0x81 -#define TR_OLD_ROUTER 0x82 - -/* fields for tr_rproto (routing protocol) */ -#define TR_PROTO_DVMRP 1 -#define TR_PROTO_MOSPF 2 -#define TR_PROTO_PIM 3 -#define TR_PROTO_CBT 4 - -static void print_mtrace(register const u_char *bp, register u_int len) -{ - register struct tr_query *tr = (struct tr_query *)(bp + 8); - - printf("mtrace %d: %s to %s reply-to %s", tr->tr_qid, - ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), - ipaddr_string(&tr->tr_raddr)); - if (IN_CLASSD(ntohl(tr->tr_raddr))) - printf(" with-ttl %d", tr->tr_rttl); -} - -static void print_mresp(register const u_char *bp, register u_int len) -{ - register struct tr_query *tr = (struct tr_query *)(bp + 8); - - printf("mresp %d: %s to %s reply-to %s", tr->tr_qid, - ipaddr_string(&tr->tr_src), ipaddr_string(&tr->tr_dst), - ipaddr_string(&tr->tr_raddr)); - if (IN_CLASSD(ntohl(tr->tr_raddr))) - printf(" with-ttl %d", tr->tr_rttl); -} - -static void -igmp_print(register const u_char *bp, register u_int len, - register const u_char *bp2) -{ - register const struct ip *ip; - - ip = (const struct ip *)bp2; - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - - TCHECK2(bp[0], 8); - switch (bp[0]) { - case 0x11: - (void)printf("igmp query"); - if (*(int *)&bp[4]) - (void)printf(" [gaddr %s]", ipaddr_string(&bp[4])); - if (len != 8) - (void)printf(" [len %d]", len); - break; - case 0x12: - (void)printf("igmp report %s", ipaddr_string(&bp[4])); - if (len != 8) - (void)printf(" [len %d]", len); - break; - case 0x16: - (void)printf("igmp nreport %s", ipaddr_string(&bp[4])); - break; - case 0x17: - (void)printf("igmp leave %s", ipaddr_string(&bp[4])); - break; - case 0x13: - (void)printf("igmp dvmrp"); - if (len < 8) - (void)printf(" [len %d]", len); - else - dvmrp_print(bp, len); - break; - case 0x14: - (void)printf("igmp pim"); - pim_print(bp, len); - break; - case 0x1e: - print_mresp(bp, len); - break; - case 0x1f: - print_mtrace(bp, len); - break; - default: - (void)printf("igmp-%d", bp[0] & 0xf); - break; - } - if ((bp[0] >> 4) != 1) - (void)printf(" [v%d]", bp[0] >> 4); - - TCHECK2(bp[0], len); - if (vflag) { - /* Check the IGMP checksum */ - u_int32_t sum = 0; - int count; - const u_short *sp = (u_short *)bp; - - for (count = len / 2; --count >= 0; ) - sum += *sp++; - if (len & 1) - sum += ntohs(*(u_char *) sp << 8); - while (sum >> 16) - sum = (sum & 0xffff) + (sum >> 16); - sum = 0xffff & ~sum; - if (sum != 0) - printf(" bad igmp cksum %x!", EXTRACT_16BITS(&bp[2])); - } - return; -trunc: - fputs("[|igmp]", stdout); -} - -/* - * print the recorded route in an IP RR, LSRR or SSRR option. - */ -static void -ip_printroute(const char *type, register const u_char *cp, u_int length) -{ - register u_int ptr = cp[2] - 1; - register u_int len; - - printf(" %s{", type); - if ((length + 1) & 3) - printf(" [bad length %d]", length); - if (ptr < 3 || ((ptr + 1) & 3) || ptr > length + 1) - printf(" [bad ptr %d]", cp[2]); - - type = ""; - for (len = 3; len < length; len += 4) { - if (ptr == len) - type = "#"; - printf("%s%s", type, ipaddr_string(&cp[len])); - type = " "; - } - printf("%s}", ptr == len? "#" : ""); -} - -/* - * print IP options. - */ -static void -ip_optprint(register const u_char *cp, u_int length) -{ - register u_int len; - - for (; length > 0; cp += len, length -= len) { - int tt = *cp; - - len = (tt == IPOPT_NOP || tt == IPOPT_EOL) ? 1 : cp[1]; - if (len <= 0) { - printf("[|ip op len %d]", len); - return; - } - if (&cp[1] >= snapend || cp + len > snapend) { - printf("[|ip]"); - return; - } - switch (tt) { - - case IPOPT_EOL: - printf(" EOL"); - if (length > 1) - printf("-%d", length - 1); - return; - - case IPOPT_NOP: - printf(" NOP"); - break; - - case IPOPT_TS: - printf(" TS{%d}", len); - break; - - case IPOPT_SECURITY: - printf(" SECURITY{%d}", len); - break; - - case IPOPT_RR: - printf(" RR{%d}=", len); - ip_printroute("RR", cp, len); - break; - - case IPOPT_SSRR: - ip_printroute("SSRR", cp, len); - break; - - case IPOPT_LSRR: - ip_printroute("LSRR", cp, len); - break; - - default: - printf(" IPOPT-%d{%d}", cp[0], len); - break; - } - } -} - -/* - * compute an IP header checksum. - * don't modifiy the packet. - */ -static int -in_cksum(const struct ip *ip) -{ - register const u_short *sp = (u_short *)ip; - register u_int32_t sum = 0; - register int count; - - /* - * No need for endian conversions. - */ - for (count = ip->ip_hl * 2; --count >= 0; ) - sum += *sp++; - while (sum > 0xffff) - sum = (sum & 0xffff) + (sum >> 16); - sum = ~sum & 0xffff; - - return (sum); -} - -/* - * print an IP datagram. - */ -void -ip_print(register const u_char *bp, register u_int length) -{ - register const struct ip *ip; - register u_int hlen, len, off; - register const u_char *cp; - - ip = (const struct ip *)bp; -#ifdef LBL_ALIGN - /* - * If the IP header is not aligned, copy into abuf. - * This will never happen with BPF. It does happen raw packet - * dumps from -r. - */ - if ((long)ip & 3) { - static u_char *abuf = NULL; - static int didwarn = 0; - - if (abuf == NULL) { - abuf = (u_char *)malloc(snaplen); - if (abuf == NULL) - error("ip_print: malloc"); - } - memcpy((char *)abuf, (char *)ip, min(length, snaplen)); - snapend += abuf - (u_char *)ip; - packetp = abuf; - ip = (struct ip *)abuf; - /* We really want libpcap to give us aligned packets */ - if (!didwarn) { - warning("compensating for unaligned libpcap packets"); - ++didwarn; - } - } -#endif - if ((u_char *)(ip + 1) > snapend) { - printf("[|ip]"); - return; - } - if (length < sizeof (struct ip)) { - (void)printf("truncated-ip %d", length); - return; - } - hlen = ip->ip_hl * 4; - - len = ntohs(ip->ip_len); - if (length < len) - (void)printf("truncated-ip - %d bytes missing!", - len - length); - len -= hlen; - - /* - * If this is fragment zero, hand it to the next higher - * level protocol. - */ - off = ntohs(ip->ip_off); - if ((off & 0x1fff) == 0) { - cp = (const u_char *)ip + hlen; - switch (ip->ip_p) { - - case IPPROTO_TCP: - tcp_print(cp, len, (const u_char *)ip); - break; - - case IPPROTO_UDP: - udp_print(cp, len, (const u_char *)ip); - break; - - case IPPROTO_ICMP: - icmp_print(cp, (const u_char *)ip); - break; - -#ifndef IPPROTO_IGRP -#define IPPROTO_IGRP 9 -#endif - case IPPROTO_IGRP: - igrp_print(cp, len, (const u_char *)ip); - break; - - case IPPROTO_ND: - (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - (void)printf(" nd %d", len); - break; - - case IPPROTO_EGP: - egp_print(cp, len, (const u_char *)ip); - break; - -#ifndef IPPROTO_OSPF -#define IPPROTO_OSPF 89 -#endif - case IPPROTO_OSPF: - ospf_print(cp, len, (const u_char *)ip); - break; - -#ifndef IPPROTO_IGMP -#define IPPROTO_IGMP 2 -#endif - case IPPROTO_IGMP: - igmp_print(cp, len, (const u_char *)ip); - break; - -#ifndef IPPROTO_ENCAP -#define IPPROTO_ENCAP 4 -#endif - case IPPROTO_ENCAP: - /* ip-in-ip encapsulation */ - if (vflag) - (void)printf("%s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - ip_print(cp, len); - if (! vflag) { - printf(" (encap)"); - return; - } - break; - -#ifndef IPPROTO_GRE -#define IPPROTO_GRE 47 -#endif - case IPPROTO_GRE: - if (vflag) - (void)printf("gre %s > %s: ", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - /* do it */ - gre_print(cp, len); - if (! vflag) { - printf(" (gre encap)"); - return; - } - break; - - default: - (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - (void)printf(" ip-proto-%d %d", ip->ip_p, len); - break; - } - } - /* - * for fragmented datagrams, print id:size@offset. On all - * but the last stick a "+". For unfragmented datagrams, note - * the don't fragment flag. - */ - if (off & 0x3fff) { - /* - * if this isn't the first frag, we're missing the - * next level protocol header. print the ip addr. - */ - if (off & 0x1fff) - (void)printf("%s > %s:", ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - (void)printf(" (frag %d:%d@%d%s)", ntohs(ip->ip_id), len, - (off & 0x1fff) * 8, - (off & IP_MF)? "+" : ""); - } else if (off & IP_DF) - (void)printf(" (DF)"); - - if (ip->ip_tos) - (void)printf(" [tos 0x%x]", (int)ip->ip_tos); - if (ip->ip_ttl <= 1) - (void)printf(" [ttl %d]", (int)ip->ip_ttl); - - if (vflag) { - int sum; - char *sep = ""; - - printf(" ("); - if (ip->ip_ttl > 1) { - (void)printf("%sttl %d", sep, (int)ip->ip_ttl); - sep = ", "; - } - if ((off & 0x3fff) == 0) { - (void)printf("%sid %d", sep, (int)ntohs(ip->ip_id)); - sep = ", "; - } - if ((u_char *)ip + hlen <= snapend) { - sum = in_cksum(ip); - if (sum != 0) { - (void)printf("%sbad cksum %x!", sep, - ntohs(ip->ip_sum)); - sep = ", "; - } - } - if ((hlen -= sizeof(struct ip)) > 0) { - (void)printf("%soptlen=%d", sep, hlen); - ip_optprint((u_char *)(ip + 1), hlen); - } - printf(")"); - } -} diff --git a/tcpdump.tproj/print-ipx.c b/tcpdump.tproj/print-ipx.c deleted file mode 100644 index f526160..0000000 --- a/tcpdump.tproj/print-ipx.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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 Novell IPX packets. - * Contributed by Brad Parker (brad@fcr.com). - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ipx.c,v 1.1.1.1 1999/05/02 03:58:33 wsanchez Exp $"; -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __STDC__ -#include -#endif -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "ipx.h" -#include "extract.h" - - -static const char *ipxaddr_string(u_int32_t, const u_char *); -void ipx_decode(const struct ipxHdr *, const u_char *, u_int); -void ipx_sap_print(const u_short *, u_int); -void ipx_rip_print(const u_short *, u_int); - -/* - * Print IPX datagram packets. - */ -void -ipx_print(const u_char *p, u_int length) -{ - const struct ipxHdr *ipx = (const struct ipxHdr *)p; - - TCHECK(ipx->srcSkt); - (void)printf("%s.%x > ", - ipxaddr_string(EXTRACT_32BITS(ipx->srcNet), ipx->srcNode), - EXTRACT_16BITS(&ipx->srcSkt)); - - (void)printf("%s.%x:", - ipxaddr_string(EXTRACT_32BITS(ipx->dstNet), ipx->dstNode), - EXTRACT_16BITS(&ipx->dstSkt)); - - /* take length from ipx header */ - TCHECK(ipx->length); - length = EXTRACT_16BITS(&ipx->length); - - ipx_decode(ipx, (u_char *)ipx + ipxSize, length - ipxSize); - return; -trunc: - printf("[|ipx %d]", length); -} - -static const char * -ipxaddr_string(u_int32_t net, const u_char *node) -{ - static char line[256]; - - sprintf(line, "%x.%02x:%02x:%02x:%02x:%02x:%02x", - net, node[0], node[1], node[2], node[3], node[4], node[5]); - - return line; -} - -void -ipx_decode(const struct ipxHdr *ipx, const u_char *datap, u_int length) -{ - register u_short dstSkt; - - dstSkt = EXTRACT_16BITS(&ipx->dstSkt); - switch (dstSkt) { - case IPX_SKT_NCP: - (void)printf(" ipx-ncp %d", length); - break; - case IPX_SKT_SAP: - ipx_sap_print((u_short *)datap, length); - break; - case IPX_SKT_RIP: - ipx_rip_print((u_short *)datap, length); - break; - case IPX_SKT_NETBIOS: - (void)printf(" ipx-netbios %d", length); - break; - case IPX_SKT_DIAGNOSTICS: - (void)printf(" ipx-diags %d", length); - break; - default: - (void)printf(" ipx-#%x %d", dstSkt, length); - break; - } -} - -void -ipx_sap_print(const u_short *ipx, u_int length) -{ - int command, i; - - TCHECK(ipx[0]); - command = EXTRACT_16BITS(ipx); - ipx++; - length -= 2; - - switch (command) { - case 1: - case 3: - if (command == 1) - (void)printf("ipx-sap-req"); - else - (void)printf("ipx-sap-nearest-req"); - - if (length > 0) { - TCHECK(ipx[1]); - (void)printf(" %x '", EXTRACT_16BITS(&ipx[0])); - fn_print((u_char *)&ipx[1], (u_char *)&ipx[1] + 48); - putchar('\''); - } - break; - - case 2: - case 4: - if (command == 2) - (void)printf("ipx-sap-resp"); - else - (void)printf("ipx-sap-nearest-resp"); - - for (i = 0; i < 8 && length > 0; i++) { - TCHECK2(ipx[27], 1); - (void)printf(" %x '", EXTRACT_16BITS(&ipx[0])); - fn_print((u_char *)&ipx[1], (u_char *)&ipx[1] + 48); - printf("' addr %s", - ipxaddr_string(EXTRACT_32BITS(&ipx[25]), (u_char *)&ipx[27])); - ipx += 32; - length -= 64; - } - break; - default: - (void)printf("ipx-sap-?%x", command); - break; - } - return; -trunc: - printf("[|ipx %d]", length); -} - -void -ipx_rip_print(const u_short *ipx, u_int length) -{ - int command, i; - - TCHECK(ipx[0]); - command = EXTRACT_16BITS(ipx); - ipx++; - length -= 2; - - switch (command) { - case 1: - (void)printf("ipx-rip-req"); - if (length > 0) { - TCHECK(ipx[3]); - (void)printf(" %u/%d.%d", EXTRACT_32BITS(&ipx[0]), - EXTRACT_16BITS(&ipx[2]), EXTRACT_16BITS(&ipx[3])); - } - break; - case 2: - (void)printf("ipx-rip-resp"); - for (i = 0; i < 50 && length > 0; i++) { - TCHECK(ipx[3]); - (void)printf(" %u/%d.%d", EXTRACT_32BITS(&ipx[0]), - EXTRACT_16BITS(&ipx[2]), EXTRACT_16BITS(&ipx[3])); - - ipx += 4; - length -= 8; - } - break; - default: - (void)printf("ipx-rip-?%x", command); - } - return; -trunc: - printf("[|ipx %d]", length); -} - diff --git a/tcpdump.tproj/print-isoclns.c b/tcpdump.tproj/print-isoclns.c deleted file mode 100644 index cea4a7e..0000000 --- a/tcpdump.tproj/print-isoclns.c +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - * - * Original code by Matt Thomas, Digital Equipment Corporation - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-isoclns.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include - -#include - -#include "interface.h" -#include "addrtoname.h" -#include "ethertype.h" - -#define CLNS 129 -#define ESIS 130 -#define ISIS 131 -#define NULLNS 0 - -static int osi_cksum(const u_char *, u_int, const u_char *, u_char *, u_char *); -static void esis_print(const u_char *, u_int); - -void -isoclns_print(const u_char *p, u_int length, u_int caplen, - const u_char *esrc, const u_char *edst) -{ - if (caplen < 1) { - printf("[|iso-clns] "); - if (!eflag) - printf("%s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - return; - } - - switch (*p) { - - case CLNS: - /* esis_print(&p, &length); */ - printf("iso-clns"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - break; - - case ESIS: - printf("iso-esis"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - esis_print(p, length); - return; - - case ISIS: - printf("iso-isis"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - /* isis_print(&p, &length); */ - (void)printf(" len=%d ", length); - if (caplen > 1) - default_print_unaligned(p, caplen); - break; - - case NULLNS: - printf("iso-nullns"); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - break; - - default: - printf("iso-clns %02x", p[0]); - if (!eflag) - (void)printf(" %s > %s", - etheraddr_string(esrc), - etheraddr_string(edst)); - (void)printf(" len=%d ", length); - if (caplen > 1) - default_print_unaligned(p, caplen); - break; - } -} - -#define ESIS_REDIRECT 6 -#define ESIS_ESH 2 -#define ESIS_ISH 4 - -struct esis_hdr { - u_char version; - u_char reserved; - u_char type; - u_char tmo[2]; - u_char cksum[2]; -}; - -static void -esis_print(const u_char *p, u_int length) -{ - const u_char *ep; - int li = p[1]; - const struct esis_hdr *eh = (const struct esis_hdr *) &p[2]; - u_char cksum[2]; - u_char off[2]; - - if (length == 2) { - if (qflag) - printf(" bad pkt!"); - else - printf(" no header at all!"); - return; - } - ep = p + li; - if (li > length) { - if (qflag) - printf(" bad pkt!"); - else - printf(" LI(%d) > PDU size (%d)!", li, length); - return; - } - if (li < sizeof(struct esis_hdr) + 2) { - if (qflag) - printf(" bad pkt!"); - else { - printf(" too short for esis header %d:", li); - while (--length >= 0) - printf("%02X", *p++); - } - return; - } - switch (eh->type & 0x1f) { - - case ESIS_REDIRECT: - printf(" redirect"); - break; - - case ESIS_ESH: - printf(" esh"); - break; - - case ESIS_ISH: - printf(" ish"); - break; - - default: - printf(" type %d", eh->type & 0x1f); - break; - } - off[0] = eh->cksum[0]; - off[1] = eh->cksum[1]; - if (vflag && osi_cksum(p, li, eh->cksum, cksum, off)) { - printf(" bad cksum (got %02x%02x want %02x%02x)", - eh->cksum[1], eh->cksum[0], cksum[1], cksum[0]); - return; - } - if (eh->version != 1) { - printf(" unsupported version %d", eh->version); - return; - } - p += sizeof(*eh) + 2; - li -= sizeof(*eh) + 2; /* protoid * li */ - - switch (eh->type & 0x1f) { - case ESIS_REDIRECT: { - const u_char *dst, *snpa, *is; - - dst = p; p += *p + 1; - if (p > snapend) - return; - printf(" %s", isonsap_string(dst)); - snpa = p; p += *p + 1; - is = p; p += *p + 1; - if (p > snapend) - return; - if (p > ep) { - printf(" [bad li]"); - return; - } - if (is[0] == 0) - printf(" > %s", etheraddr_string(&snpa[1])); - else - printf(" > %s", isonsap_string(is)); - li = ep - p; - break; - } -#if 0 - case ESIS_ESH: - printf(" esh"); - break; -#endif - case ESIS_ISH: { - const u_char *is; - - is = p; p += *p + 1; - if (p > ep) { - printf(" [bad li]"); - return; - } - if (p > snapend) - return; - printf(" %s", isonsap_string(is)); - li = ep - p; - break; - } - - default: - (void)printf(" len=%d", length); - if (length && p < snapend) { - length = snapend - p; - default_print(p, length); - } - return; - } - if (vflag) - while (p < ep && li) { - int op, opli; - const u_char *q; - - if (snapend - p < 2) - return; - if (li < 2) { - printf(" bad opts/li"); - return; - } - op = *p++; - opli = *p++; - li -= 2; - if (opli > li) { - printf(" opt (%d) too long", op); - return; - } - li -= opli; - q = p; - p += opli; - if (snapend < p) - return; - if (op == 198 && opli == 2) { - printf(" tmo=%d", q[0] * 256 + q[1]); - continue; - } - printf (" %d:<", op); - while (--opli >= 0) - printf("%02x", *q++); - printf (">"); - } -} - -static int -osi_cksum(register const u_char *p, register u_int len, - const u_char *toff, u_char *cksum, u_char *off) -{ - int x, y, f = (len - ((toff - p) + 1)); - int32_t c0 = 0, c1 = 0; - - if ((cksum[0] = off[0]) == 0 && (cksum[1] = off[1]) == 0) - return 0; - - off[0] = off[1] = 0; - while (--len >= 0) { - c0 += *p++; - c1 += c0; - c0 %= 255; - c1 %= 255; - } - x = (c0 * f - c1); - if (x < 0) - x = 255 - (-x % 255); - else - x %= 255; - y = -1 * (x + c0); - if (y < 0) - y = 255 - (-y % 255); - else - y %= 255; - - off[0] = x; - off[1] = y; - - return (off[0] != cksum[0] || off[1] != cksum[1]); -} diff --git a/tcpdump.tproj/print-krb.c b/tcpdump.tproj/print-krb.c deleted file mode 100644 index 16116a0..0000000 --- a/tcpdump.tproj/print-krb.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - * - * Initial contribution from John Hawkinson (jhawk@mit.edu). - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-krb.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $"; -#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 (ep == NULL || 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 - - TCHECK2(cp, 0); - PRINT; - TCHECK2(cp, 0); - putchar('.'); PRINT; - TCHECK2(cp, 0); - 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 */ - TCHECK2(cp, 0); - printf(" %dmin ", *cp++ * 5); - TCHECK2(cp, 0); - PRINT; - TCHECK2(cp, 0); - putchar('.'); PRINT; - break; - - case AUTH_MSG_APPL_REQUEST: - cp += 2; - TCHECK2(cp, 0); - printf("v%d ", *cp++); - TCHECK2(cp, 0); - PRINT; - TCHECK2(cp, 0); - printf(" (%d)", *cp++); - TCHECK2(cp, 0); - printf(" (%d)", *cp); - TCHECK2(cp, 0); - break; - - case AUTH_MSG_KDC_REPLY: - if ((cp = krb4_print_hdr(cp)) == NULL) - return; - cp += 10; /* timestamp + n + exp + kvno */ - TCHECK2(cp, 0); - len = KTOHSP(kp, cp); - printf(" (%d)", len); - TCHECK2(cp, 0); - break; - - case AUTH_MSG_ERR_REPLY: - if ((cp = krb4_print_hdr(cp)) == NULL) - return; - cp += 4; /* timestamp */ - TCHECK2(cp, 0); - printf(" %s ", tok2str(kerr2str, NULL, KTOHSP(kp, cp))); - cp += 4; - TCHECK2(cp, 0); - 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/tcpdump.tproj/print-llc.c b/tcpdump.tproj/print-llc.c deleted file mode 100644 index 4deb6ed..0000000 --- a/tcpdump.tproj/print-llc.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - * - * Code by Matt Thomas, Digital Equipment Corporation - * with an awful lot of hacking by Jeffrey Mogul, DECWRL - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-llc.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $"; -#endif - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ - -#include "llc.h" - -static struct tok cmd2str[] = { - { LLC_UI, "ui" }, - { LLC_TEST, "test" }, - { LLC_XID, "xid" }, - { LLC_UA, "ua" }, - { LLC_DISC, "disc" }, - { LLC_DM, "dm" }, - { LLC_SABME, "sabme" }, - { LLC_FRMR, "frmr" }, - { 0, NULL } -}; - -/* - * Returns non-zero IFF it succeeds in printing the header - */ -int -llc_print(const u_char *p, u_int length, u_int caplen, - const u_char *esrc, const u_char *edst) -{ - struct llc llc; - register u_short et; - register int ret; - - if (caplen < 3) { - (void)printf("[|llc]"); - default_print((u_char *)p, caplen); - return(0); - } - - /* Watch out for possible alignment problems */ - memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc))); - - if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) { - ipx_print(p, length); - return (1); - } -#ifdef notyet - else if (p[0] == 0xf0 && p[1] == 0xf0) - netbios_print(p, length); -#endif - if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS - && llc.llcui == LLC_UI) { - isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst); - return (1); - } - - if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP - && llc.llcui == LLC_UI) { - if (caplen < sizeof(llc)) { - (void)printf("[|llc-snap]"); - default_print((u_char *)p, caplen); - return (0); - } - if (vflag) - (void)printf("snap %s ", protoid_string(llc.llcpi)); - - caplen -= sizeof(llc); - length -= sizeof(llc); - p += sizeof(llc); - - /* This is an encapsulated Ethernet packet */ - et = EXTRACT_16BITS(&llc.ethertype[0]); - ret = ether_encap_print(et, p, length, caplen); - if (ret) - return (ret); - } - - if ((llc.ssap & ~LLC_GSAP) == llc.dsap) { - if (eflag) - (void)printf("%s ", llcsap_string(llc.dsap)); - else - (void)printf("%s > %s %s ", - etheraddr_string(esrc), - etheraddr_string(edst), - llcsap_string(llc.dsap)); - } else { - if (eflag) - (void)printf("%s > %s ", - llcsap_string(llc.ssap & ~LLC_GSAP), - llcsap_string(llc.dsap)); - else - (void)printf("%s %s > %s %s ", - etheraddr_string(esrc), - llcsap_string(llc.ssap & ~LLC_GSAP), - etheraddr_string(edst), - llcsap_string(llc.dsap)); - } - - if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) { - const char *m; - char f; - m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu)); - switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) { - case 0: f = 'C'; break; - case LLC_GSAP: f = 'R'; break; - case LLC_U_POLL: f = 'P'; break; - case LLC_GSAP|LLC_U_POLL: f = 'F'; break; - default: f = '?'; break; - } - - printf("%s/%c", m, f); - - p += 3; - length -= 3; - caplen -= 3; - - if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) { - if (*p == LLC_XID_FI) { - printf(": %02x %02x", p[1], p[2]); - p += 3; - length -= 3; - caplen -= 3; - } - } - } else { - char f; - llc.llcis = ntohs(llc.llcis); - switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) { - case 0: f = 'C'; break; - case LLC_GSAP: f = 'R'; break; - case LLC_U_POLL: f = 'P'; break; - case LLC_GSAP|LLC_U_POLL: f = 'F'; break; - default: f = '?'; break; - } - - if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) { - static char *llc_s[] = { "rr", "rej", "rnr", "03" }; - (void)printf("%s (r=%d,%c)", - llc_s[LLC_S_CMD(llc.llcis)], - LLC_IS_NR(llc.llcis), - f); - } else { - (void)printf("I (s=%d,r=%d,%c)", - LLC_I_NS(llc.llcis), - LLC_IS_NR(llc.llcis), - f); - } - p += 4; - length -= 4; - caplen -= 4; - } - (void)printf(" len=%d", length); - if (caplen > 0) { - default_print_unaligned(p, caplen); - } - return(1); -} diff --git a/tcpdump.tproj/print-netbios.c b/tcpdump.tproj/print-netbios.c deleted file mode 100644 index fdf16a3..0000000 --- a/tcpdump.tproj/print-netbios.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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). - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-netbios.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $"; -#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/tcpdump.tproj/print-nfs.c b/tcpdump.tproj/print-nfs.c deleted file mode 100644 index 9f7b5b2..0000000 --- a/tcpdump.tproj/print-nfs.c +++ /dev/null @@ -1,891 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-nfs.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -#include "nfsv2.h" -#include "nfsfh.h" - -static void nfs_printfh(const u_int32_t *); -static void xid_map_enter(const struct rpc_msg *, const struct ip *); -static int32_t xid_map_find(const struct rpc_msg *, const struct ip *); -static void interp_reply(const struct rpc_msg *, u_int32_t, u_int); - -static int nfserr; /* true if we error rather than trunc */ - -void -nfsreply_print(register const u_char *bp, u_int length, - register const u_char *bp2) -{ - register const struct rpc_msg *rp; - register const struct ip *ip; - int32_t proc; - - nfserr = 0; /* assume no error */ - rp = (const struct rpc_msg *)bp; - ip = (const struct ip *)bp2; - - if (!nflag) - (void)printf("%s.nfs > %s.%x: reply %s %d", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst), - (u_int32_t)ntohl(rp->rm_xid), - ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED? - "ok":"ERR", - length); - else - (void)printf("%s.%x > %s.%x: reply %s %d", - ipaddr_string(&ip->ip_src), - NFS_PORT, - ipaddr_string(&ip->ip_dst), - (u_int32_t)ntohl(rp->rm_xid), - ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED? - "ok":"ERR", - length); - - proc = xid_map_find(rp, ip); - if (proc >= 0) - interp_reply(rp, (u_int32_t)proc, length); -} - -/* - * Return a pointer to the first file handle in the packet. - * If the packet was truncated, return 0. - */ -static const u_int32_t * -parsereq(register const struct rpc_msg *rp, register u_int length) -{ - register const u_int32_t *dp; - register u_int len; - - /* - * find the start of the req data (if we captured it) - */ - dp = (u_int32_t *)&rp->rm_call.cb_cred; - TCHECK(dp[1]); - len = ntohl(dp[1]); - if (len < length) { - dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp); - TCHECK(dp[1]); - len = ntohl(dp[1]); - if (len < length) { - dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp); - TCHECK2(dp[0], 0); - return (dp); - } - } -trunc: - return (NULL); -} - -/* - * Print out an NFS file handle and return a pointer to following word. - * If packet was truncated, return 0. - */ -static const u_int32_t * -parsefh(register const u_int32_t *dp) -{ - if (dp + 8 <= (u_int32_t *)snapend) { - nfs_printfh(dp); - return (dp + 8); - } - return (NULL); -} - -/* - * Print out a file name and return pointer to 32-bit word past it. - * If packet was truncated, return 0. - */ -static const u_int32_t * -parsefn(register const u_int32_t *dp) -{ - register u_int32_t len; - register const u_char *cp; - - /* Bail if we don't have the string length */ - if ((u_char *)dp > snapend - sizeof(*dp)) - return (NULL); - - /* Fetch string length; convert to host order */ - len = *dp++; - NTOHL(len); - - cp = (u_char *)dp; - /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */ - dp += ((len + 3) & ~3) / sizeof(*dp); - if ((u_char *)dp > snapend) - return (NULL); - /* XXX seems like we should be checking the length */ - putchar('"'); - (void) fn_printn(cp, len, NULL); - putchar('"'); - - return (dp); -} - -/* - * Print out file handle and file name. - * Return pointer to 32-bit word past file name. - * If packet was truncated (or there was some other error), return 0. - */ -static const u_int32_t * -parsefhn(register const u_int32_t *dp) -{ - dp = parsefh(dp); - if (dp == NULL) - return (NULL); - putchar(' '); - return (parsefn(dp)); -} - -void -nfsreq_print(register const u_char *bp, u_int length, - register const u_char *bp2) -{ - register const struct rpc_msg *rp; - register const struct ip *ip; - register const u_int32_t *dp; - - nfserr = 0; /* assume no error */ - rp = (const struct rpc_msg *)bp; - ip = (const struct ip *)bp2; - if (!nflag) - (void)printf("%s.%x > %s.nfs: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - length); - else - (void)printf("%s.%x > %s.%x: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - NFS_PORT, - length); - - xid_map_enter(rp, ip); /* record proc number for later on */ - - switch (ntohl(rp->rm_call.cb_proc)) { -#ifdef NFSPROC_NOOP - case NFSPROC_NOOP: - printf(" nop"); - return; -#else -#define NFSPROC_NOOP -1 -#endif - case NFSPROC_NULL: - printf(" null"); - return; - - case NFSPROC_GETATTR: - printf(" getattr"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) - return; - break; - - case NFSPROC_SETATTR: - printf(" setattr"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) - return; - break; - -#if NFSPROC_ROOT != NFSPROC_NOOP - case NFSPROC_ROOT: - printf(" root"); - break; -#endif - case NFSPROC_LOOKUP: - printf(" lookup"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) - return; - break; - - case NFSPROC_READLINK: - printf(" readlink"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) - return; - break; - - case NFSPROC_READ: - printf(" read"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 3 * sizeof(*dp)); - printf(" %u bytes @ %u", - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); - return; - } - break; - -#if NFSPROC_WRITECACHE != NFSPROC_NOOP - case NFSPROC_WRITECACHE: - printf(" writecache"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 4 * sizeof(*dp)); - printf(" %u (%u) bytes @ %u (%u)", - (u_int32_t)ntohl(dp[3]), - (u_int32_t)ntohl(dp[2]), - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); - return; - } - break; -#endif - case NFSPROC_WRITE: - printf(" write"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 4 * sizeof(*dp)); - printf(" %u (%u) bytes @ %u (%u)", - (u_int32_t)ntohl(dp[3]), - (u_int32_t)ntohl(dp[2]), - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); - return; - } - break; - - case NFSPROC_CREATE: - printf(" create"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) - return; - break; - - case NFSPROC_REMOVE: - printf(" remove"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) - return; - break; - - case NFSPROC_RENAME: - printf(" rename"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefhn(dp)) != NULL) { - fputs(" ->", stdout); - if (parsefhn(dp) != NULL) - return; - } - break; - - case NFSPROC_LINK: - printf(" link"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - fputs(" ->", stdout); - if (parsefhn(dp) != NULL) - return; - } - break; - - case NFSPROC_SYMLINK: - printf(" symlink"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefhn(dp)) != NULL) { - fputs(" -> ", stdout); - if (parsefn(dp) != NULL) - return; - } - break; - - case NFSPROC_MKDIR: - printf(" mkdir"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) - return; - break; - - case NFSPROC_RMDIR: - printf(" rmdir"); - if ((dp = parsereq(rp, length)) != NULL && parsefhn(dp) != NULL) - return; - break; - - case NFSPROC_READDIR: - printf(" readdir"); - if ((dp = parsereq(rp, length)) != NULL && - (dp = parsefh(dp)) != NULL) { - TCHECK2(dp[0], 2 * sizeof(*dp)); - /* - * Print the offset as signed, since -1 is common, - * but offsets > 2^31 aren't. - */ - printf(" %u bytes @ %d", - (u_int32_t)ntohl(dp[1]), - (u_int32_t)ntohl(dp[0])); - return; - } - break; - - case NFSPROC_STATFS: - printf(" statfs"); - if ((dp = parsereq(rp, length)) != NULL && parsefh(dp) != NULL) - return; - break; - - default: - printf(" proc-%u", (u_int32_t)ntohl(rp->rm_call.cb_proc)); - return; - } -trunc: - if (!nfserr) - fputs(" [|nfs]", stdout); -} - -/* - * Print out an NFS file handle. - * We assume packet was not truncated before the end of the - * file handle pointed to by dp. - * - * Note: new version (using portable file-handle parser) doesn't produce - * generation number. It probably could be made to do that, with some - * additional hacking on the parser code. - */ -static void -nfs_printfh(register const u_int32_t *dp) -{ - my_fsid fsid; - ino_t ino; - char *sfsname = NULL; - - Parse_fh((caddr_t *)dp, &fsid, &ino, NULL, &sfsname, 0); - - if (sfsname) { - /* file system ID is ASCII, not numeric, for this server OS */ - static char temp[NFS_FHSIZE+1]; - - /* Make sure string is null-terminated */ - strncpy(temp, sfsname, NFS_FHSIZE); - /* Remove trailing spaces */ - sfsname = strchr(temp, ' '); - if (sfsname) - *sfsname = 0; - - (void)printf(" fh %s/%u", temp, (u_int32_t)ino); - } else { - (void)printf(" fh %u,%u/%u", - fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor, (u_int32_t)ino); - } -} - -/* - * Maintain a small cache of recent client.XID.server/proc pairs, to allow - * us to match up replies with requests and thus to know how to parse - * the reply. - */ - -struct xid_map_entry { - u_int32_t xid; /* transaction ID (net order) */ - struct in_addr client; /* client IP address (net order) */ - struct in_addr server; /* server IP address (net order) */ - u_int32_t proc; /* call proc number (host order) */ -}; - -/* - * Map entries are kept in an array that we manage as a ring; - * new entries are always added at the tail of the ring. Initially, - * all the entries are zero and hence don't match anything. - */ - -#define XIDMAPSIZE 64 - -struct xid_map_entry xid_map[XIDMAPSIZE]; - -int xid_map_next = 0; -int xid_map_hint = 0; - -static void -xid_map_enter(const struct rpc_msg *rp, const struct ip *ip) -{ - struct xid_map_entry *xmep; - - xmep = &xid_map[xid_map_next]; - - if (++xid_map_next >= XIDMAPSIZE) - xid_map_next = 0; - - xmep->xid = rp->rm_xid; - xmep->client = ip->ip_src; - xmep->server = ip->ip_dst; - xmep->proc = ntohl(rp->rm_call.cb_proc); -} - -/* Returns NFSPROC_xxx or -1 on failure */ -static int32_t -xid_map_find(const struct rpc_msg *rp, const struct ip *ip) -{ - int i; - struct xid_map_entry *xmep; - u_int32_t xid = rp->rm_xid; - u_int32_t clip = ip->ip_dst.s_addr; - u_int32_t sip = ip->ip_src.s_addr; - - /* Start searching from where we last left off */ - i = xid_map_hint; - do { - xmep = &xid_map[i]; - if (xmep->xid == xid && xmep->client.s_addr == clip && - xmep->server.s_addr == sip) { - /* match */ - xid_map_hint = i; - return ((int32_t)xmep->proc); - } - if (++i >= XIDMAPSIZE) - i = 0; - } while (i != xid_map_hint); - - /* search failed */ - return (-1); -} - -/* - * Routines for parsing reply packets - */ - -/* - * Return a pointer to the beginning of the actual results. - * If the packet was truncated, return 0. - */ -static const u_int32_t * -parserep(register const struct rpc_msg *rp, register u_int length) -{ - register const u_int32_t *dp; - u_int len; - enum accept_stat astat; - - /* - * Portability note: - * Here we find the address of the ar_verf credentials. - * Originally, this calculation was - * dp = (u_int32_t *)&rp->rm_reply.rp_acpt.ar_verf - * On the wire, the rp_acpt field starts immediately after - * the (32 bit) rp_stat field. However, rp_acpt (which is a - * "struct accepted_reply") contains a "struct opaque_auth", - * whose internal representation contains a pointer, so on a - * 64-bit machine the compiler inserts 32 bits of padding - * before rp->rm_reply.rp_acpt.ar_verf. So, we cannot use - * the internal representation to parse the on-the-wire - * representation. Instead, we skip past the rp_stat field, - * which is an "enum" and so occupies one 32-bit word. - */ - dp = ((const u_int32_t *)&rp->rm_reply) + 1; - TCHECK2(dp[0], 1); - len = ntohl(dp[1]); - if (len >= length) - return (NULL); - /* - * skip past the ar_verf credentials. - */ - dp += (len + (2*sizeof(u_int32_t) + 3)) / sizeof(u_int32_t); - TCHECK2(dp[0], 0); - - /* - * now we can check the ar_stat field - */ - astat = ntohl(*(enum accept_stat *)dp); - switch (astat) { - - case SUCCESS: - break; - - case PROG_UNAVAIL: - printf(" PROG_UNAVAIL"); - nfserr = 1; /* suppress trunc string */ - return (NULL); - - case PROG_MISMATCH: - printf(" PROG_MISMATCH"); - nfserr = 1; /* suppress trunc string */ - return (NULL); - - case PROC_UNAVAIL: - printf(" PROC_UNAVAIL"); - nfserr = 1; /* suppress trunc string */ - return (NULL); - - case GARBAGE_ARGS: - printf(" GARBAGE_ARGS"); - nfserr = 1; /* suppress trunc string */ - return (NULL); - - case SYSTEM_ERR: - printf(" SYSTEM_ERR"); - nfserr = 1; /* suppress trunc string */ - return (NULL); - - default: - printf(" ar_stat %d", astat); - nfserr = 1; /* suppress trunc string */ - return (NULL); - } - /* successful return */ - if ((sizeof(astat) + ((u_char *)dp)) < snapend) - return ((u_int32_t *) (sizeof(astat) + ((char *)dp))); - -trunc: - return (NULL); -} - -static const u_int32_t * -parsestatus(const u_int32_t *dp) -{ - register int errnum; - - TCHECK(dp[0]); - errnum = ntohl(dp[0]); - if (errnum != 0) { - if (!qflag) - printf(" ERROR: %s", pcap_strerror(errnum)); - nfserr = 1; /* suppress trunc string */ - return (NULL); - } - return (dp + 1); -trunc: - return (NULL); -} - -static struct tok type2str[] = { - { NFNON, "NON" }, - { NFREG, "REG" }, - { NFDIR, "DIR" }, - { NFBLK, "BLK" }, - { NFCHR, "CHR" }, - { NFLNK, "LNK" }, - { 0, NULL } -}; - -static const u_int32_t * -parsefattr(const u_int32_t *dp, int verbose) -{ - const struct nfsv2_fattr *fap; - - fap = (const struct nfsv2_fattr *)dp; - if (verbose) { - TCHECK(fap->fa_nfssize); - printf(" %s %o ids %u/%u sz %u ", - tok2str(type2str, "unk-ft %d ", - (u_int32_t)ntohl(fap->fa_type)), - (u_int32_t)ntohl(fap->fa_mode), - (u_int32_t)ntohl(fap->fa_uid), - (u_int32_t)ntohl(fap->fa_gid), - (u_int32_t)ntohl(fap->fa_nfssize)); - } - /* print lots more stuff */ - if (verbose > 1) { - TCHECK(fap->fa_nfsfileid); - printf("nlink %u rdev %x fsid %x nodeid %x a/m/ctime ", - (u_int32_t)ntohl(fap->fa_nlink), - (u_int32_t)ntohl(fap->fa_nfsrdev), - (u_int32_t)ntohl(fap->fa_nfsfsid), - (u_int32_t)ntohl(fap->fa_nfsfileid)); - TCHECK(fap->fa_nfsatime); - printf("%u.%06u ", - (u_int32_t)ntohl(fap->fa_nfsatime.nfs_sec), - (u_int32_t)ntohl(fap->fa_nfsatime.nfs_usec)); - TCHECK(fap->fa_nfsmtime); - printf("%u.%06u ", - (u_int32_t)ntohl(fap->fa_nfsmtime.nfs_sec), - (u_int32_t)ntohl(fap->fa_nfsmtime.nfs_usec)); - TCHECK(fap->fa_nfsctime); - printf("%u.%06u ", - (u_int32_t)ntohl(fap->fa_nfsctime.nfs_sec), - (u_int32_t)ntohl(fap->fa_nfsctime.nfs_usec)); - } - return ((const u_int32_t *)&fap[1]); -trunc: - return (NULL); -} - -static int -parseattrstat(const u_int32_t *dp, int verbose) -{ - - dp = parsestatus(dp); - if (dp == NULL) - return (0); - - return (parsefattr(dp, verbose) != NULL); -} - -static int -parsediropres(const u_int32_t *dp) -{ - - dp = parsestatus(dp); - if (dp == NULL) - return (0); - - dp = parsefh(dp); - if (dp == NULL) - return (0); - - return (parsefattr(dp, vflag) != NULL); -} - -static int -parselinkres(const u_int32_t *dp) -{ - dp = parsestatus(dp); - if (dp == NULL) - return (0); - - putchar(' '); - return (parsefn(dp) != NULL); -} - -static int -parsestatfs(const u_int32_t *dp) -{ - const struct nfsv2_statfs *sfsp; - - dp = parsestatus(dp); - if (dp == NULL) - return (0); - - if (!qflag) { - sfsp = (const struct nfsv2_statfs *)dp; - TCHECK(sfsp->sf_bavail); - printf(" tsize %u bsize %u blocks %u bfree %u bavail %u", - (u_int32_t)ntohl(sfsp->sf_tsize), - (u_int32_t)ntohl(sfsp->sf_bsize), - (u_int32_t)ntohl(sfsp->sf_blocks), - (u_int32_t)ntohl(sfsp->sf_bfree), - (u_int32_t)ntohl(sfsp->sf_bavail)); - } - - return (1); -trunc: - return (0); -} - -static int -parserddires(const u_int32_t *dp) -{ - dp = parsestatus(dp); - if (dp == NULL) - return (0); - if (!qflag) { - TCHECK(dp[0]); - printf(" offset %x", (u_int32_t)ntohl(dp[0])); - TCHECK(dp[1]); - printf(" size %u", (u_int32_t)ntohl(dp[1])); - TCHECK(dp[2]); - if (dp[2] != 0) - printf(" eof"); - } - - return (1); -trunc: - return (0); -} - -static void -interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int length) -{ - register const u_int32_t *dp; - - switch (proc) { - -#ifdef NFSPROC_NOOP - case NFSPROC_NOOP: - printf(" nop"); - return; -#else -#define NFSPROC_NOOP -1 -#endif - case NFSPROC_NULL: - printf(" null"); - return; - - case NFSPROC_GETATTR: - printf(" getattr"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, !qflag) != 0) - return; - break; - - case NFSPROC_SETATTR: - printf(" setattr"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, !qflag) != 0) - return; - break; - -#if NFSPROC_ROOT != NFSPROC_NOOP - case NFSPROC_ROOT: - printf(" root"); - break; -#endif - case NFSPROC_LOOKUP: - printf(" lookup"); - dp = parserep(rp, length); - if (dp != NULL && parsediropres(dp) != 0) - return; - break; - - case NFSPROC_READLINK: - printf(" readlink"); - dp = parserep(rp, length); - if (dp != NULL && parselinkres(dp) != 0) - return; - break; - - case NFSPROC_READ: - printf(" read"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, vflag) != 0) - return; - break; - -#if NFSPROC_WRITECACHE != NFSPROC_NOOP - case NFSPROC_WRITECACHE: - printf(" writecache"); - break; -#endif - case NFSPROC_WRITE: - printf(" write"); - dp = parserep(rp, length); - if (dp != NULL && parseattrstat(dp, vflag) != 0) - return; - break; - - case NFSPROC_CREATE: - printf(" create"); - dp = parserep(rp, length); - if (dp != NULL && parsediropres(dp) != 0) - return; - break; - - case NFSPROC_REMOVE: - printf(" remove"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; - break; - - case NFSPROC_RENAME: - printf(" rename"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; - break; - - case NFSPROC_LINK: - printf(" link"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; - break; - - case NFSPROC_SYMLINK: - printf(" symlink"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; - break; - - case NFSPROC_MKDIR: - printf(" mkdir"); - dp = parserep(rp, length); - if (dp != NULL && parsediropres(dp) != 0) - return; - break; - - case NFSPROC_RMDIR: - printf(" rmdir"); - dp = parserep(rp, length); - if (dp != NULL && parsestatus(dp) != 0) - return; - break; - - case NFSPROC_READDIR: - printf(" readdir"); - dp = parserep(rp, length); - if (dp != NULL && parserddires(dp) != 0) - return; - break; - - case NFSPROC_STATFS: - printf(" statfs"); - dp = parserep(rp, length); - if (dp != NULL && parsestatfs(dp) != 0) - return; - break; - - default: - printf(" proc-%u", proc); - return; - } - if (!nfserr) - fputs(" [|nfs]", stdout); -} diff --git a/tcpdump.tproj/print-ntp.c b/tcpdump.tproj/print-ntp.c deleted file mode 100644 index 52931a7..0000000 --- a/tcpdump.tproj/print-ntp.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1992, 1993, 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 ntp packets. - * By Jeffrey Mogul/DECWRL - * loosely based on print-bootp.c - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ntp.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include - -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#undef MODEMASK /* Solaris sucks */ -#include "ntp.h" - -static void p_sfix(const struct s_fixedpt *); -static void p_ntp_time(const struct l_fixedpt *); -static void p_ntp_delta(const struct l_fixedpt *, const struct l_fixedpt *); - -/* - * Print ntp requests - */ -void -ntp_print(register const u_char *cp, u_int length) -{ - register const struct ntpdata *bp; - int mode, version, leapind; - static char rclock[5]; - - bp = (struct ntpdata *)cp; - /* Note funny sized packets */ - if (length != sizeof(struct ntpdata)) - (void)printf(" [len=%d]", length); - - TCHECK(bp->status); - - version = (int)(bp->status & VERSIONMASK) >> 3; - printf(" v%d", version); - - leapind = bp->status & LEAPMASK; - switch (leapind) { - - case NO_WARNING: - break; - - case PLUS_SEC: - fputs(" +1s", stdout); - break; - - case MINUS_SEC: - fputs(" -1s", stdout); - break; - } - - mode = bp->status & MODEMASK; - switch (mode) { - - case MODE_UNSPEC: /* unspecified */ - fputs(" unspec", stdout); - break; - - case MODE_SYM_ACT: /* symmetric active */ - fputs(" sym_act", stdout); - break; - - case MODE_SYM_PAS: /* symmetric passive */ - fputs(" sym_pas", stdout); - break; - - case MODE_CLIENT: /* client */ - fputs(" client", stdout); - break; - - case MODE_SERVER: /* server */ - fputs(" server", stdout); - break; - - case MODE_BROADCAST: /* broadcast */ - fputs(" bcast", stdout); - break; - - case MODE_RES1: /* reserved */ - fputs(" res1", stdout); - break; - - case MODE_RES2: /* reserved */ - fputs(" res2", stdout); - break; - - } - - TCHECK(bp->stratum); - printf(" strat %d", bp->stratum); - - TCHECK(bp->ppoll); - printf(" poll %d", bp->ppoll); - - /* Can't TCHECK bp->precision bitfield so bp->distance + 0 instead */ - TCHECK2(bp->distance, 0); - printf(" prec %d", bp->precision); - - if (!vflag) - return; - - TCHECK(bp->distance); - fputs(" dist ", stdout); - p_sfix(&bp->distance); - - TCHECK(bp->dispersion); - fputs(" disp ", stdout); - p_sfix(&bp->dispersion); - - TCHECK(bp->refid); - fputs(" ref ", stdout); - /* Interpretation depends on stratum */ - switch (bp->stratum) { - - case UNSPECIFIED: - printf("(unspec)"); - break; - - case PRIM_REF: - strncpy(rclock, (char *)&(bp->refid), 4); - rclock[4] = '\0'; - fputs(rclock, stdout); - break; - - case INFO_QUERY: - printf("%s INFO_QUERY", ipaddr_string(&(bp->refid))); - /* this doesn't have more content */ - return; - - case INFO_REPLY: - printf("%s INFO_REPLY", ipaddr_string(&(bp->refid))); - /* this is too complex to be worth printing */ - return; - - default: - printf("%s", ipaddr_string(&(bp->refid))); - break; - } - - TCHECK(bp->reftime); - putchar('@'); - p_ntp_time(&(bp->reftime)); - - TCHECK(bp->org); - fputs(" orig ", stdout); - p_ntp_time(&(bp->org)); - - TCHECK(bp->rec); - fputs(" rec ", stdout); - p_ntp_delta(&(bp->org), &(bp->rec)); - - TCHECK(bp->xmt); - fputs(" xmt ", stdout); - p_ntp_delta(&(bp->org), &(bp->xmt)); - - return; - -trunc: - fputs(" [|ntp]", stdout); -} - -static void -p_sfix(register const struct s_fixedpt *sfp) -{ - register int i; - register int f; - register float ff; - - i = ntohs(sfp->int_part); - f = ntohs(sfp->fraction); - ff = f / 65536.0; /* shift radix point by 16 bits */ - f = ff * 1000000.0; /* Treat fraction as parts per million */ - printf("%d.%06d", i, f); -} - -#define FMAXINT (4294967296.0) /* floating point rep. of MAXINT */ - -static void -p_ntp_time(register const struct l_fixedpt *lfp) -{ - register int32_t i; - register u_int32_t uf; - register u_int32_t f; - register float ff; - - i = ntohl(lfp->int_part); - uf = ntohl(lfp->fraction); - ff = uf; - if (ff < 0.0) /* some compilers are buggy */ - ff += FMAXINT; - ff = ff / FMAXINT; /* shift radix point by 32 bits */ - f = ff * 1000000000.0; /* treat fraction as parts per billion */ - printf("%u.%09d", i, f); -} - -/* Prints time difference between *lfp and *olfp */ -static void -p_ntp_delta(register const struct l_fixedpt *olfp, - register const struct l_fixedpt *lfp) -{ - register int32_t i; - register u_int32_t uf; - register u_int32_t ouf; - register u_int32_t f; - register float ff; - int signbit; - - i = ntohl(lfp->int_part) - ntohl(olfp->int_part); - - uf = ntohl(lfp->fraction); - ouf = ntohl(olfp->fraction); - - if (i > 0) { /* new is definitely greater than old */ - signbit = 0; - f = uf - ouf; - if (ouf > uf) /* must borrow from high-order bits */ - i -= 1; - } else if (i < 0) { /* new is definitely less than old */ - signbit = 1; - f = ouf - uf; - if (uf > ouf) /* must carry into the high-order bits */ - i += 1; - i = -i; - } else { /* int_part is zero */ - if (uf > ouf) { - signbit = 0; - f = uf - ouf; - } else { - signbit = 1; - f = ouf - uf; - } - } - - ff = f; - if (ff < 0.0) /* some compilers are buggy */ - ff += FMAXINT; - ff = ff / FMAXINT; /* shift radix point by 32 bits */ - f = ff * 1000000000.0; /* treat fraction as parts per billion */ - if (signbit) - putchar('-'); - else - putchar('+'); - printf("%d.%09d", i, f); -} diff --git a/tcpdump.tproj/print-null.c b/tcpdump.tproj/print-null.c deleted file mode 100644 index 7dcf69b..0000000 --- a/tcpdump.tproj/print-null.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1991, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-null.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#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" - -#define NULL_HDRLEN 4 - -#ifndef AF_NS -#define AF_NS 6 /* XEROX NS protocols */ -#endif - -static void -null_print(const u_char *p, const struct ip *ip, u_int length) -{ - u_int family; - - memcpy((char *)&family, (char *)p, sizeof(family)); - - if (nflag) { - /* XXX just dump the header */ - return; - } - switch (family) { - - case AF_INET: - printf("ip: "); - break; - - case AF_NS: - printf("ns: "); - break; - - default: - printf("AF %d: ", family); - break; - } -} - -void -null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - u_int length = h->len; - u_int caplen = h->caplen; - const struct ip *ip; - - 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; - - length -= NULL_HDRLEN; - - ip = (struct ip *)(p + NULL_HDRLEN); - - if (eflag) - null_print(p, ip, length); - - ip_print((const u_char *)ip, length); - - if (xflag) - default_print((const u_char *)ip, caplen - NULL_HDRLEN); - putchar('\n'); -} - diff --git a/tcpdump.tproj/print-ospf.c b/tcpdump.tproj/print-ospf.c deleted file mode 100644 index 5012fb8..0000000 --- a/tcpdump.tproj/print-ospf.c +++ /dev/null @@ -1,603 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - * - * OSPF support contributed by Jeffrey Honig (jch@mitchell.cit.cornell.edu) - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ospf.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -#include "ospf.h" - -struct bits { - u_int32_t bit; - const char *str; -}; - -static const struct bits ospf_option_bits[] = { - { OSPF_OPTION_T, "T" }, - { OSPF_OPTION_E, "E" }, - { OSPF_OPTION_MC, "MC" }, - { 0, NULL } -}; - -static const struct bits ospf_rla_flag_bits[] = { - { RLA_FLAG_B, "B" }, - { RLA_FLAG_E, "E" }, - { RLA_FLAG_W1, "W1" }, - { RLA_FLAG_W2, "W2" }, - { 0, NULL } -}; - -static struct tok type2str[] = { - { OSPF_TYPE_UMD, "umd" }, - { OSPF_TYPE_HELLO, "hello" }, - { OSPF_TYPE_DB, "dd" }, - { OSPF_TYPE_LSR, "ls_req" }, - { OSPF_TYPE_LSU, "ls_upd" }, - { OSPF_TYPE_LSA, "ls_ack" }, - { 0, NULL } -}; - -static char tstr[] = " [|ospf]"; - -/* Forwards */ -static inline void ospf_print_seqage(u_int32_t, time_t); -static inline void ospf_print_bits(const struct bits *, u_char); -static void ospf_print_ls_type(u_int, const struct in_addr *, - const struct in_addr *, const char *); -static int ospf_print_lshdr(const struct lsa_hdr *); -static int ospf_print_lsa(const struct lsa *); -static int ospf_decode_v2(const struct ospfhdr *, const u_char *); - -static inline void -ospf_print_seqage(register u_int32_t seq, register time_t us) -{ - register time_t sec = us % 60; - register time_t mins = (us / 60) % 60; - register time_t hour = us / 3600; - - printf(" S %X age ", seq); - if (hour) - printf("%u:%02u:%02u", - (u_int32_t) hour, (u_int32_t) mins, (u_int32_t) sec); - else if (mins) - printf("%u:%02u", (u_int32_t) mins, (u_int32_t) sec); - else - printf("%u", (u_int32_t) sec); -} - - -static inline void -ospf_print_bits(register const struct bits *bp, register u_char options) -{ - register char sep = ' '; - - do { - if (options & bp->bit) { - printf("%c%s", sep, bp->str); - sep = '/'; - } - } while ((++bp)->bit); -} - -static void -ospf_print_ls_type(register u_int ls_type, - register const struct in_addr *ls_stateid, - register const struct in_addr *ls_router, register const char *fmt) -{ - - switch (ls_type) { - - case LS_TYPE_ROUTER: - printf(" rtr %s ", ipaddr_string(ls_router)); - break; - - case LS_TYPE_NETWORK: - printf(" net dr %s if %s", - ipaddr_string(ls_router), - ipaddr_string(ls_stateid)); - break; - - case LS_TYPE_SUM_IP: - printf(" sum %s abr %s", - ipaddr_string(ls_stateid), - ipaddr_string(ls_router)); - break; - - case LS_TYPE_SUM_ABR: - printf(" abr %s rtr %s", - ipaddr_string(ls_router), - ipaddr_string(ls_stateid)); - break; - - case LS_TYPE_ASE: - printf(" ase %s asbr %s", - ipaddr_string(ls_stateid), - ipaddr_string(ls_router)); - break; - - case LS_TYPE_GROUP: - printf(" group %s rtr %s", - ipaddr_string(ls_stateid), - ipaddr_string(ls_router)); - break; - - default: - putchar(' '); - printf(fmt, ls_type); - break; - } -} - -static int -ospf_print_lshdr(register const struct lsa_hdr *lshp) -{ - - TCHECK(lshp->ls_type); - printf(" {"); /* } (ctags) */ - - TCHECK(lshp->ls_options); - ospf_print_bits(ospf_option_bits, lshp->ls_options); - TCHECK(lshp->ls_seq); - ospf_print_seqage(ntohl(lshp->ls_seq), ntohs(lshp->ls_age)); - ospf_print_ls_type(lshp->ls_type, &lshp->ls_stateid, &lshp->ls_router, - "ls_type %d"); - - return (0); -trunc: - return (1); -} - - -/* - * Print a single link state advertisement. If truncated return 1, else 0. - */ -static int -ospf_print_lsa(register const struct lsa *lsap) -{ - register const u_char *ls_end; - register const struct rlalink *rlp; - register const struct tos_metric *tosp; - register const struct in_addr *ap; - register const struct aslametric *almp; - register const struct mcla *mcp; - register const u_int32_t *lp; - register int j, k; - - if (ospf_print_lshdr(&lsap->ls_hdr)) - return (1); - TCHECK(lsap->ls_hdr.ls_length); - ls_end = (u_char *)lsap + ntohs(lsap->ls_hdr.ls_length); - switch (lsap->ls_hdr.ls_type) { - - case LS_TYPE_ROUTER: - TCHECK(lsap->lsa_un.un_rla.rla_flags); - ospf_print_bits(ospf_rla_flag_bits, - lsap->lsa_un.un_rla.rla_flags); - - TCHECK(lsap->lsa_un.un_rla.rla_count); - j = ntohs(lsap->lsa_un.un_rla.rla_count); - TCHECK(lsap->lsa_un.un_rla.rla_link); - rlp = lsap->lsa_un.un_rla.rla_link; - while (j--) { - register struct rlalink *rln = - (struct rlalink *)((u_char *)(rlp + 1) + - ((rlp->link_toscount) * sizeof(*tosp))); - - TCHECK(*rln); - printf(" {"); /* } (ctags) */ - switch (rlp->link_type) { - - case RLA_TYPE_VIRTUAL: - printf(" virt"); - /* Fall through */ - - case RLA_TYPE_ROUTER: - printf(" nbrid %s if %s", - ipaddr_string(&rlp->link_id), - ipaddr_string(&rlp->link_data)); - break; - - case RLA_TYPE_TRANSIT: - printf(" dr %s if %s", - ipaddr_string(&rlp->link_id), - ipaddr_string(&rlp->link_data)); - break; - - case RLA_TYPE_STUB: - printf(" net %s mask %s", - ipaddr_string(&rlp->link_id), - ipaddr_string(&rlp->link_data)); - break; - - default: - /* { (ctags) */ - printf(" ??RouterLinksType %d?? }", - rlp->link_type); - return (0); - } - printf(" tos 0 metric %d", ntohs(rlp->link_tos0metric)); - tosp = (struct tos_metric *) - ((sizeof rlp->link_tos0metric) + (u_char *) rlp); - for (k = 0; k < (int) rlp->link_toscount; ++k, ++tosp) { - TCHECK(*tosp); - printf(" tos %d metric %d", - tosp->tos_type, - ntohs(tosp->tos_metric)); - } - /* { (ctags) */ - printf(" }"); - rlp = rln; - } - break; - - case LS_TYPE_NETWORK: - TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s rtrs", - ipaddr_string(&lsap->lsa_un.un_nla.nla_mask)); - ap = lsap->lsa_un.un_nla.nla_router; - while ((u_char *)ap < ls_end) { - TCHECK(*ap); - printf(" %s", ipaddr_string(ap)); - ++ap; - } - break; - - case LS_TYPE_SUM_IP: - TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s", - ipaddr_string(&lsap->lsa_un.un_sla.sla_mask)); - /* Fall through */ - - case LS_TYPE_SUM_ABR: - TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); - lp = lsap->lsa_un.un_sla.sla_tosmetric; - while ((u_char *)lp < ls_end) { - register u_int32_t ul; - - TCHECK(*lp); - ul = ntohl(*lp); - printf(" tos %d metric %d", - (ul & SLA_MASK_TOS) >> SLA_SHIFT_TOS, - ul & SLA_MASK_METRIC); - ++lp; - } - break; - - case LS_TYPE_ASE: - TCHECK(lsap->lsa_un.un_nla.nla_mask); - printf(" mask %s", - ipaddr_string(&lsap->lsa_un.un_asla.asla_mask)); - - TCHECK(lsap->lsa_un.un_sla.sla_tosmetric); - almp = lsap->lsa_un.un_asla.asla_metric; - while ((u_char *)almp < ls_end) { - register u_int32_t ul; - - TCHECK(almp->asla_tosmetric); - ul = ntohl(almp->asla_tosmetric); - printf(" type %d tos %d metric %d", - (ul & ASLA_FLAG_EXTERNAL) ? 2 : 1, - (ul & ASLA_MASK_TOS) >> ASLA_SHIFT_TOS, - (ul & ASLA_MASK_METRIC)); - TCHECK(almp->asla_forward); - if (almp->asla_forward.s_addr) { - printf(" forward %s", - ipaddr_string(&almp->asla_forward)); - } - TCHECK(almp->asla_tag); - if (almp->asla_tag.s_addr) { - printf(" tag %s", - ipaddr_string(&almp->asla_tag)); - } - ++almp; - } - break; - - case LS_TYPE_GROUP: - /* Multicast extensions as of 23 July 1991 */ - mcp = lsap->lsa_un.un_mcla; - while ((u_char *)mcp < ls_end) { - TCHECK(mcp->mcla_vid); - switch (ntohl(mcp->mcla_vtype)) { - - case MCLA_VERTEX_ROUTER: - printf(" rtr rtrid %s", - ipaddr_string(&mcp->mcla_vid)); - break; - - case MCLA_VERTEX_NETWORK: - printf(" net dr %s", - ipaddr_string(&mcp->mcla_vid)); - break; - - default: - printf(" ??VertexType %u??", - (u_int32_t)ntohl(mcp->mcla_vtype)); - break; - } - ++mcp; - } - } - - /* { (ctags) */ - fputs(" }", stdout); - return (0); -trunc: - fputs(" }", stdout); - return (1); -} - -static int -ospf_decode_v2(register const struct ospfhdr *op, - register const u_char *dataend) -{ - register const struct in_addr *ap; - register const struct lsr *lsrp; - register const struct lsa_hdr *lshp; - register const struct lsa *lsap; - register char sep; - register int i; - - switch (op->ospf_type) { - - case OSPF_TYPE_UMD: - /* - * Rob Coltun's special monitoring packets; - * do nothing - */ - break; - - case OSPF_TYPE_HELLO: - if (vflag) { - TCHECK(op->ospf_hello.hello_deadint); - ospf_print_bits(ospf_option_bits, - op->ospf_hello.hello_options); - printf(" mask %s int %d pri %d dead %u", - ipaddr_string(&op->ospf_hello.hello_mask), - ntohs(op->ospf_hello.hello_helloint), - op->ospf_hello.hello_priority, - (u_int32_t)ntohl(op->ospf_hello.hello_deadint)); - } - TCHECK(op->ospf_hello.hello_dr); - if (op->ospf_hello.hello_dr.s_addr != 0) - printf(" dr %s", - ipaddr_string(&op->ospf_hello.hello_dr)); - TCHECK(op->ospf_hello.hello_bdr); - if (op->ospf_hello.hello_bdr.s_addr != 0) - printf(" bdr %s", - ipaddr_string(&op->ospf_hello.hello_bdr)); - if (vflag) { - printf(" nbrs"); - ap = op->ospf_hello.hello_neighbor; - while ((u_char *)ap < dataend) { - TCHECK(*ap); - printf(" %s", ipaddr_string(ap)); - ++ap; - } - } - break; /* HELLO */ - - case OSPF_TYPE_DB: - TCHECK(op->ospf_db.db_options); - ospf_print_bits(ospf_option_bits, op->ospf_db.db_options); - sep = ' '; - TCHECK(op->ospf_db.db_flags); - if (op->ospf_db.db_flags & OSPF_DB_INIT) { - printf("%cI", sep); - sep = '/'; - } - if (op->ospf_db.db_flags & OSPF_DB_MORE) { - printf("%cM", sep); - sep = '/'; - } - if (op->ospf_db.db_flags & OSPF_DB_MASTER) { - printf("%cMS", sep); - sep = '/'; - } - TCHECK(op->ospf_db.db_seq); - printf(" S %X", (u_int32_t)ntohl(op->ospf_db.db_seq)); - - if (vflag) { - /* Print all the LS adv's */ - lshp = op->ospf_db.db_lshdr; - - while (!ospf_print_lshdr(lshp)) { - /* { (ctags) */ - printf(" }"); - ++lshp; - } - } - break; - - case OSPF_TYPE_LSR: - if (vflag) { - lsrp = op->ospf_lsr; - while ((u_char *)lsrp < dataend) { - TCHECK(*lsrp); - printf(" {"); /* } (ctags) */ - ospf_print_ls_type(ntohl(lsrp->ls_type), - &lsrp->ls_stateid, - &lsrp->ls_router, - "LinkStateType %d"); - /* { (ctags) */ - printf(" }"); - ++lsrp; - } - } - break; - - case OSPF_TYPE_LSU: - if (vflag) { - lsap = op->ospf_lsu.lsu_lsa; - TCHECK(op->ospf_lsu.lsu_count); - i = ntohl(op->ospf_lsu.lsu_count); - while (i--) { - if (ospf_print_lsa(lsap)) - goto trunc; - lsap = (struct lsa *)((u_char *)lsap + - ntohs(lsap->ls_hdr.ls_length)); - } - } - break; - - - case OSPF_TYPE_LSA: - if (vflag) { - lshp = op->ospf_lsa.lsa_lshdr; - - while (!ospf_print_lshdr(lshp)) { - /* { (ctags) */ - printf(" }"); - ++lshp; - } - } - break; - - default: - printf("v2 type %d", op->ospf_type); - break; - } - return (0); -trunc: - return (1); -} - -void -ospf_print(register const u_char *bp, register u_int length, - register const u_char *bp2) -{ - register const struct ospfhdr *op; - register const struct ip *ip; - register const u_char *dataend; - register const char *cp; - - op = (struct ospfhdr *)bp; - ip = (struct ip *)bp2; - /* Print the source and destination address */ - (void) printf("%s > %s:", - ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst)); - - /* If the type is valid translate it, or just print the type */ - /* value. If it's not valid, say so and return */ - TCHECK(op->ospf_type); - cp = tok2str(type2str, "type%d", op->ospf_type); - printf(" OSPFv%d-%s %d:", op->ospf_version, cp, length); - if (*cp == 't') - return; - - TCHECK(op->ospf_len); - if (length != ntohs(op->ospf_len)) { - printf(" [len %d]", ntohs(op->ospf_len)); - return; - } - dataend = bp + length; - - /* Print the routerid if it is not the same as the source */ - TCHECK(op->ospf_routerid); - if (ip->ip_src.s_addr != op->ospf_routerid.s_addr) - printf(" rtrid %s", ipaddr_string(&op->ospf_routerid)); - - TCHECK(op->ospf_areaid); - if (op->ospf_areaid.s_addr != 0) - printf(" area %s", ipaddr_string(&op->ospf_areaid)); - else - printf(" backbone"); - - if (vflag) { - /* Print authentication data (should we really do this?) */ - TCHECK2(op->ospf_authdata[0], sizeof(op->ospf_authdata)); - switch (ntohs(op->ospf_authtype)) { - - case OSPF_AUTH_NONE: - break; - - case OSPF_AUTH_SIMPLE: - printf(" auth \""); - (void)fn_printn(op->ospf_authdata, - sizeof(op->ospf_authdata), NULL); - printf("\""); - break; - - default: - printf(" ??authtype-%d??", ntohs(op->ospf_authtype)); - return; - } - } - /* Do rest according to version. */ - switch (op->ospf_version) { - - case 2: - /* ospf version 2 */ - if (ospf_decode_v2(op, dataend)) - goto trunc; - break; - - default: - printf(" ospf [version %d]", op->ospf_version); - break; - } /* end switch on version */ - - return; -trunc: - fputs(tstr, stdout); -} diff --git a/tcpdump.tproj/print-pim.c b/tcpdump.tproj/print-pim.c deleted file mode 100644 index 3fb9909..0000000 --- a/tcpdump.tproj/print-pim.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-pim.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#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/tcpdump.tproj/print-ppp.c b/tcpdump.tproj/print-ppp.c deleted file mode 100644 index 9fd2a49..0000000 --- a/tcpdump.tproj/print-ppp.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-ppp.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#ifdef PPP -#include -#include -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -/* XXX This goes somewhere else. */ -#define PPP_HDRLEN 4 - -void -ppp_if_print(u_char *user, const struct pcap_pkthdr *h, - register const u_char *p) -{ - register u_int length = h->len; - register u_int caplen = h->caplen; - const struct ip *ip; - - ts_print(&h->ts); - - if (caplen < PPP_HDRLEN) { - printf("[|ppp]"); - goto out; - } - - /* - * 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("%c %4d %02x %04x: ", p[0] ? 'O' : 'I', length, - p[1], ntohs(*(u_short *)&p[2])); - - length -= PPP_HDRLEN; - ip = (struct ip *)(p + PPP_HDRLEN); - ip_print((const u_char *)ip, length); - - if (xflag) - default_print((const u_char *)ip, caplen - PPP_HDRLEN); -out: - putchar('\n'); -} -#else -#include -#include - -#include - -#include "interface.h" -void -ppp_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - error("not configured for ppp"); - /* NOTREACHED */ -} -#endif diff --git a/tcpdump.tproj/print-rip.c b/tcpdump.tproj/print-rip.c deleted file mode 100644 index 7c87af7..0000000 --- a/tcpdump.tproj/print-rip.c +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1989, 1990, 1991, 1993, 1994, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-rip.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ - -struct rip { - u_char rip_cmd; /* request/response */ - u_char rip_vers; /* protocol version # */ - u_short rip_zero2; /* unused */ -}; -#define RIPCMD_REQUEST 1 /* want info */ -#define RIPCMD_RESPONSE 2 /* responding to request */ -#define RIPCMD_TRACEON 3 /* turn tracing on */ -#define RIPCMD_TRACEOFF 4 /* turn it off */ -#define RIPCMD_POLL 5 /* want info from everybody */ -#define RIPCMD_POLLENTRY 6 /* poll for entry */ - -struct rip_netinfo { - u_short rip_family; - u_short rip_tag; - u_int32_t rip_dest; - u_int32_t rip_dest_mask; - u_int32_t rip_router; - u_int32_t rip_metric; /* cost of route */ -}; - -static void -rip_entry_print(register int vers, register const struct rip_netinfo *ni) -{ - register u_char *cp, *ep; - - if (EXTRACT_16BITS(&ni->rip_family) != AF_INET) { - - printf(" [family %d:", EXTRACT_16BITS(&ni->rip_family)); - cp = (u_char *)&ni->rip_tag; - ep = (u_char *)&ni->rip_metric + sizeof(ni->rip_metric); - for (; cp < ep; cp += 2) - printf(" %04x", EXTRACT_16BITS(cp)); - printf("]"); - } else if (vers < 2) { - /* RFC 1058 */ - printf(" %s", ipaddr_string(&ni->rip_dest)); - } else { - /* RFC 1723 */ - printf(" {%s", ipaddr_string(&ni->rip_dest)); - if (ni->rip_dest_mask) - printf("/%s", ipaddr_string(&ni->rip_dest_mask)); - if (ni->rip_router) - printf("->%s", ipaddr_string(&ni->rip_router)); - if (ni->rip_tag) - printf(" tag %04x", EXTRACT_16BITS(&ni->rip_tag)); - printf("}"); - } - printf("(%d)", EXTRACT_32BITS(&ni->rip_metric)); -} - -void -rip_print(const u_char *dat, u_int length) -{ - register const struct rip *rp; - register const struct rip_netinfo *ni; - register int i, j, trunc; - - i = min(length, snapend - dat) - sizeof(*rp); - if (i < 0) - return; - - rp = (struct rip *)dat; - switch (rp->rip_cmd) { - - case RIPCMD_REQUEST: - printf(" rip-req %d", length); - break; - - case RIPCMD_RESPONSE: - j = length / sizeof(*ni); - if (j * sizeof(*ni) != length - 4) - printf(" rip-resp %d[%d]:", j, length); - else - printf(" rip-resp %d:", j); - trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i); - ni = (struct rip_netinfo *)(rp + 1); - for (; (i -= sizeof(*ni)) >= 0; ++ni) - rip_entry_print(rp->rip_vers, ni); - if (trunc) - printf("[|rip]"); - break; - - case RIPCMD_TRACEON: - printf(" rip-traceon %d: \"", length); - (void)fn_print((const u_char *)(rp + 1), snapend); - fputs("\"\n", stdout); - break; - - case RIPCMD_TRACEOFF: - printf(" rip-traceoff %d", length); - break; - - case RIPCMD_POLL: - printf(" rip-poll %d", length); - break; - - case RIPCMD_POLLENTRY: - printf(" rip-pollentry %d", length); - break; - - default: - printf(" rip-#%d %d", rp->rip_cmd, length); - break; - } - switch (rp->rip_vers) { - - case 1: - case 2: - break; - - default: - printf(" [vers %d]", rp->rip_vers); - break; - } -} diff --git a/tcpdump.tproj/print-skip.c b/tcpdump.tproj/print-skip.c deleted file mode 100644 index d9f5059..0000000 --- a/tcpdump.tproj/print-skip.c +++ /dev/null @@ -1,943 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: print-skip.c,v 1.2 1996/07/13 11:01:29 mickey Exp $ */ - -/* - * Copyright (c) 1995 Sun Microsystems, Inc. - * All rights reserved. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - - * IN NO EVENT SHALL SUN MICROSYSTEMS, INC. BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * SUN MICROSYSTEMS, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - - * SUN MICROSYSTEMS, INC. SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. - * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND SUN - * MICROSYSTEMS, INC. HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, - * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -*/ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -#define MAX_ALGS (256) - -int skipflag = 0; - -const int skip_max_algs = MAX_ALGS; - -char *old_skip_crypt_algs[MAX_ALGS] = { - "none", /* 0 */ - "des_cbc", /* 1 */ - "rc2_cbc", /* 2 */ - "rc4(40bit)", /* 3 */ - "rc4(128bit)", /* 4 */ - "des_ede-2", /* 5 */ - "des_ede-3", /* 6 */ - "idea", /* 7 */ - "", /* 8 */ - "", /* 9 */ - "simplecrypt" /* 10 */ - }; - - -char * -skip_alg_to_name(char *table[], int alg) -{ - if (alg > skip_max_algs) { - return (""); - } - if (alg < 0) { - return (""); - } - if (table[alg] == NULL) { - return (""); - } - if (strlen(table[alg]) == 0) { - return (""); - } - return (table[alg]); -} - -/* - * This is what an OLD skip encrypted-authenticated packet looks like: - * - * - * 0 1 2 3 - * --------------------------------- - * | | - * / Clear IP Header / - * | | IP protocol = IPSP - * --------------------------------- - * | | - * | IPSP header | - * | | - * --------------------------------- - * | | - * / Protected IPSP Payload / - * / / - * | | - * --------------------------------- - * - * - * The format of the IPSP header for encrypted-encapsulated mode is shown below. * The fields are transmitted from left to right. - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Ver. |E|A|C|S|B|R| zero | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Kij alg. | Kp alg. | reserved | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Optional boxid field | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Kp encrypted in Kij... (typically 8-16 bytes) - * +-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Message Indicator (e.g IV)... (typically 8-16 bytes) - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Protected IPSP Payload... - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * - * Field values: - * Ver.: protocol version - * E: 1 if packet is encrypted, 0 otherwise - * A: 1 if packet is authenticated, 0 otherwise - * C: 1 if packet is compressed before encryption, 0 otherwise - * S: 1 if packet is sequenced, 0 otherwise - * B: 1 if packet is tunneled (header contains boxid), 0 otherwise - * R: reserved (should be 0 until specified) - * - */ -/* - * per-algorithm encrytped key sizes... - */ -unsigned char old_skip_ekp_sizes[MAX_ALGS] = { - 8, /* plaintext */ - 8, /* DES */ - 8, /* RC2 */ - 8, /* RC4 (40 bit) */ - 16, /* RC4 (128 bit) */ - 16, /* 3DES 2 */ - 24, /* 3DES 3 */ - 16, /* IDEA */ - 0, /* */ - 0, /* */ - 8, /* simplecrypt */ - }; -/* - * per-algorithm message indicator sizes... - */ -unsigned char old_skip_mid_sizes[MAX_ALGS] = { - 8, /* plaintext */ - 8, /* DES */ - 8, /* RC2 */ - 8, /* RC4 40 bit */ - 8, /* RC4 128 bit */ - 8, /* 3DES 2 */ - 8, /* 3DES 3 */ - 8, /* IDEA */ - 0, /* */ - 0, /* */ - 8, /* simplecrypt */ - }; - -void skip_print_old(register const u_char *bp, register int length, - const u_char *bp2) -{ - struct ip *ip; - const u_char *end; - u_char *p; - unsigned char kij_alg, kp_alg, *c; - unsigned short i; - unsigned short len; - int boxid; - int node; - - ip=(struct ip *)bp2; - p=(u_char *)bp; - end=bp+length; - printf("SKIP: *** OLD SKIP ***\n"); - printf("OSKIP: %s>%s:%d",ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst),length); - if (!skipflag) - return; - printf("\nOSKIP: SAID byte 1= 0x%02x\n",*p); - printf("OSKIP: xxxx .... = version %d\n", (int) (*p & 0xf0) >> 4); - if (*p & 0x08) { - printf("OSKIP: .... 1... = encrypted\n"); - } else { - printf("OSKIP: .... 0... = not encrypted\n"); - } - - if (*p & 0x04) { - printf("OSKIP: .... .1.. = authenticated\n"); - } else { - printf("OSKIP: .... .0.. = not authenticated\n"); - } - - if (*p & 0x02) { - printf("OSKIP: .... ..1. = compressed\n"); - } else { - printf("OSKIP: .... ..0. = not compressed\n"); - } - - if (*p & 0x01) { - printf("OSKIP: .... ...1 = sequenced\n"); - } else { - printf("OSKIP: .... ...0 = not sequenced\n"); - } - - p++; - - printf("OSKIP: SAID byte 2 = 0x%02x\n", *p); - - if (*p & 0x80) { - node=1; - printf("OSKIP: 1... .... = Node ID present\n"); - } else { - node=0; - printf("OSKIP: 0... .... = no Node ID present\n"); - } - - if (*p & 0x40) { - printf("OSKIP: .1.. .... = \n"); - } else { - printf("OSKIP: .0.. .... = \n"); - } - - if (*p & 0x20) { - printf("OSKIP: ..1. .... = \n"); - } else { - printf("OSKIP: ..0. .... = \n"); - } - - if (*p & 0x10) { - printf("OSKIP: ...1 .... = \n"); - } else { - printf("OSKIP: ...0 .... = \n"); - } - p++; - printf("OSKIP: SAID byte 3 = 0x%02x\n", *p); - - p++; - printf("OSKIP: SAID byte 4 = 0x%02x\n", *p); - - p++; - - kij_alg = *p; - printf("OSKIP: Kij alg (key encryption algorithm) = 0x%02x (%s)\n", - kij_alg, skip_alg_to_name(old_skip_crypt_algs,kij_alg)); - - p++; - - kp_alg = *p; - printf("OSKIP: Kp alg (traffic encryption algorithm) = 0x%02x (%s)\n", - kp_alg, skip_alg_to_name(old_skip_crypt_algs,kp_alg)); - - p++; - - /* - * the skip reserved field - */ - printf("OSKIP: reserved byte 1 = 0x%02x\n", *p++); - printf("OSKIP: reserved byte 2 = 0x%02x\n", *p++); - - if (node) { - /* - * boxid field - */ - if ((end - p) < sizeof(boxid)) { - return; - } - c = (unsigned char *) &boxid; - *c++ = *p++; - *c++ = *p++; - *c++ = *p++; - *c++ = *p++; - - printf("OSKIP: Node ID = 0x%08x\n", ntohl(boxid)); - } - - /* - * encrypted kp (ekp) field - */ - - /* - * do this with a for-loop to avoid alignment problems and the - * overhead of calling bcopy() - */ - len = old_skip_ekp_sizes[kp_alg]; - if ((unsigned short) (end - p) < len) { - return; - } - - printf("OSKIP: encrypted Kp: "); - for (i = 0; i < len; i++) { - printf("%02x ", (unsigned char) *p++); - } - printf("\n"); - - /* - * message indicator (mid) field - */ - len = old_skip_mid_sizes[kp_alg]; - if ((unsigned short) (end - p) < len) { - return; - } - printf("OSKIP: message indicator field: "); - for (i = 0; i < len; i++) { - printf("%02x ", (unsigned char) *p++); - } - printf("\n"); -} - - - -/* - * The following part is (c) by G. Caronni -- 29.11.95 - * - * This code is in the public domain; do with it what you wish. - * - * NO WARRANTY, NO SUPPORT, NO NOTHING! - */ - - -/* - * This is what a NEW skip encrypted-authenticated packet looks like: - * - * - * 0 1 2 3 - * --------------------------------- - * | | - * / Clear IP Header / - * | | IP protocol = SKIP - * --------------------------------- - * | | - * | SKIP header | - * | | - * --------------------------------- - * | | - * | Auth Header & payload | - * | | - * --------------------------------- - * | | - * | ESP header and SPI | - * | | - * --------------------------------- - * | | - * / Protected ESP Payload / - * | | - * --------------------------------- - * - * - * The format of the SKIP header for encrypted-encapsulated mode is shown below. * The fields are transmitted from left to right. - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Ver | Rsvd | Source NSID | Dest NSID | NEXT HEADER | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Counter n | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Kij Alg | Crypt Alg | MAC Alg | Comp Alg | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Kp encrypted in Kijn... (typically 8-16 bytes) - * +-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Source Master Key-ID (If Source NSID is non-zero) - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Destination Master Key-ID (If Dest NSID is non-zero) - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - */ - - - - - -/* - * per name space key ID sizes... - */ -unsigned char skip_nsid_sizes[MAX_ALGS] = { - 0, /* 0 none */ - 4, /* 1 IP v4 Address Space */ - 4, /* 2 POSIX/XOPEN User Ids */ - 16, /* 3 IPv6 Address Space */ - 16, /* 4 MD5 of DNS Names */ - 16, /* 5 MD5 of ISO ASN.1 DN encoding */ - 16, /* 6 MD5 of US Social Security number */ - 6, /* 7 802.x MAC Address */ - 16, /* 8 MD5 of public Value */ - 16, /* 9 MD5 of RFC822 Mailbox Address */ - 16, /* 10 MD5 of Bank Account # */ - 16, /* 11 MD5 of NIS Name */ - }; - - -/* - * per Kp algorithm encrypted Kp sizes... (Kij alg does not matter for now) - */ -unsigned char skip_ekp_sizes[MAX_ALGS] = { - 0, /* 0 plaintext */ - 8, /* 1 DES_CBC */ - 24, /* 2 3 key triple DES-EDE-CBC */ - 0, /* 3 */ - 0, /* 4 */ - 0, /* 5 */ - 0, /* 6 */ - 0, /* 7 */ - 0, /* 8 */ - 0, /* 9 */ /* 10 .. 249 */ -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 8, /* 250 RC4-40 */ - 16, /* 251 RC4-128 */ - 8, /* 252 simple crypt */ - 16, /* 253 IDEA */ - 0, /* 254 */ - 0 /* 255 */ - }; - - -/* - * per-algorithm NSID names ... - */ -char *skip_nsid_names[MAX_ALGS] = { - "none", /* 0 */ - "IPv4", /* 1 */ - "Posix/Xopen UID", /* 2 */ - "IPv6", /* 3 */ - "MD5 DNS", /* 4 */ - "MD5 ASN.1 DN", /* 5 */ - "MD5 U.S. Soc. #", /* 6 */ - "802.x MAC", /* 7 */ - "MD5 DH Public Key",/* 8 */ - "MD5 RFC822 Mail", /* 9 */ - "MD5 Bank Account", /* 10 */ - "MD5 NIS Name", /* 11 */ - }; - - -/* - * per-algorithm Kij alg names ... - */ -char *skip_kij_names[MAX_ALGS] = { - "none", /* 0 */ - "DES-CBC", /* 1 */ - "3DES3-EDE-CBC", /* 2 */ - "IDEA-CBC", /* 3 */ - }; - - -/* for padding of ekp */ - -char skip_kij_sizes[MAX_ALGS] = { - 0, /* 0 none */ - 8, /* 1 des-cbc */ - 8, /* 2 3des3-ede-cbc */ - 8, /* 3 idea-cbc */ - }; - - -/* - * per-algorithm Crypt alg names ... - */ -char *skip_crypt_names[MAX_ALGS] = { - "none", /* 0 */ - "DES-CBC", /* 1 */ - "3 key DES-EDE-CBC", /* 2 */ - "", /* 3 */ - "", /* 4 */ - "", /* 5 */ - "", /* 6 */ - "", /* 7 */ - "", /* 8 */ - "", /* 9 */ /* 10 .. 249 */ -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - "RC4-40", /* 250 */ - "RC4-128", /* 251 */ - "simple crypt", /* 252 */ - "IDEA CBC", /* 253 */ - "", /* 254 */ - "" /* 255 */ - }; - - -/* - * per-algorithm Auth alg names ... - */ -char *skip_auth_names[MAX_ALGS] = { - "none", /* 0 */ - "keyed MD5", /* 1 */ - "DES-CBC MAC", /* 2 */ - "Keyed SHA", /* 3 */ - }; - - -char skip_auth_sizes[MAX_ALGS] = { - 0, /* 0 none */ - 16, /* 1 keyed MD5 */ - 8, /* 2 DES-CBC MAC */ - 20, /* 3 Keyed SHA */ - }; - - -/* - * per-algorithm Crypt alg IV sizes ... - */ -char skip_crypt_sizes[MAX_ALGS] = { - 0, /* 0 none */ - 8, /* 1 DES-CBC */ - 8, /* 2 3key DES-EDE-CBC */ - 0, /* 3 */ - 0, /* 4 */ - 0, /* 5 */ - 0, /* 6 */ - 0, /* 7 */ - 0, /* 8 */ - 0, /* 9 */ /* 10 .. 249 */ -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 8, /* 250 RC4-40 */ - 8, /* 251 RC4-128 */ - 8, /* 252 simple crypt */ - 8, /* 253 IDEA CBC */ - 0, /* 254 */ - 0 /* 255 */ - }; - - -#ifndef IPPROTO_ESP -#define IPPROTO_ESP 50 -#endif -#ifndef IPPROTO_AH -#define IPPROTO_AH 51 -#endif -#ifndef IPPROTO_SKIP -#define IPPROTO_SKIP 57 -#endif -#ifndef IPPROTO_OSKIP -#define IPPROTO_OSKIP 79 -#endif - -static int expected_auth_size=0; -static int expected_iv_size=0; - -char *skip_protocol_name(int p) -{ - switch(p) { - case IPPROTO_IP: return "IP"; - case IPPROTO_ICMP: return "ICMP"; - case IPPROTO_IGMP: return "IGMP"; - case IPPROTO_ENCAP: return "ENCAP"; - case IPPROTO_TCP: return "TCP"; - case IPPROTO_EGP: return "EGP"; - case IPPROTO_UDP: return "UDP"; - case IPPROTO_ESP: return "ESP"; - case IPPROTO_AH: return "AH"; - case IPPROTO_SKIP: return "SKIP"; - case IPPROTO_ND: return "ND"; - case IPPROTO_OSKIP: return "OLD-SKIP"; - case IPPROTO_RAW: return "RAW IP"; - default: return ""; - } -} - -void skip_print_next(u_char nxt, const u_char *p, int len, const u_char *bp2) -{ - switch(nxt) { - case IPPROTO_IP: ip_print(p,len); break; - case IPPROTO_ICMP: icmp_print(p,bp2); break; - case IPPROTO_TCP: tcp_print(p,len,bp2); break; - case IPPROTO_UDP: udp_print(p,len,bp2); break; - case IPPROTO_ESP: esp_print(p,len,bp2); break; - case IPPROTO_AH: ah_print(p,len,bp2); break; - case IPPROTO_SKIP: skip_print(p,len,bp2); break; - default: break; - } -} - -void skip_print(register const u_char *bp, register int length, - const u_char *bp2) -{ - struct ip *ip; - const u_char *end; - const u_char *p; - unsigned char kij_alg, crypt_alg, auth_alg, snsid, dnsid, nxt; - unsigned short i; - unsigned short len; - u_int n; - time_t full_n; - - ip=(struct ip *)bp2; - p=bp; - end=bp+length%s:%d SKIP",ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst),length); - if (!skipflag) - return; - - - if ((unsigned short) (end - p) < 4) { - printf("[SKIP|] (truncated)\n"); - return; - } - - printf("\nSKIP: version\t\t\t%d\n", (int) (*p & 0xf0) >> 4); - if (*p & 0xf) - printf("SKIP: version byte \t\treserved,\tis now 0x%x\n", - (int) (*p & 0xf)); - p++; - - snsid = *p; - printf("SKIP: Source NSID\t\t0x%02x\t\t%s\n", - snsid, skip_alg_to_name(skip_nsid_names,snsid)); - p++; - - dnsid = *p; - printf("SKIP: Destination NSID\t\t0x%02x\t\t%s\n", - dnsid, skip_alg_to_name(skip_nsid_names,dnsid)); - p++; - - nxt = *p; - printf("SKIP: Next Protocol Field\t0x%02x\t\t%s\n", nxt, - skip_protocol_name(nxt)); - - p++; - - if ((unsigned short) (end - p) < 4) { - printf("[SKIP|] (truncated)\n"); - return; - } - - n=*p++<<24; - n+=*p++<<16; - n+=*p++<<8; - n+=*p; - full_n=(((365*25+6)*24)+n)*3600; - printf("SKIP: Counter n Field\t\t0x%08x\t%s", n, - asctime(gmtime(&full_n))); - p++; - - if ((unsigned short) (end - p) < 4) { - printf("[SKIP|] (truncated)\n"); - return; - } - - kij_alg = *p; - printf("SKIP: Kij alg (key encryption)\t0x%02x\t\t%s\n", - kij_alg, skip_alg_to_name(skip_kij_names,kij_alg)); - p++; - - crypt_alg = *p; - expected_iv_size=skip_crypt_sizes[crypt_alg]; - printf("SKIP: Crypt Alg\t\t\t0x%02x\t\t%s\n", - crypt_alg, skip_alg_to_name(skip_crypt_names,crypt_alg)); - p++; - - auth_alg = *p; - expected_auth_size=skip_auth_sizes[auth_alg]; - printf("SKIP: Auth Alg\t\t\t0x%02x\t\t%s\n", - auth_alg, skip_alg_to_name(skip_auth_names,auth_alg)); - p++; - - if (*p) printf("SKIP: compression\t\treserved,\tis now0x%02x\n", - (int) *p++); - else p++; - - /* - * encrypted kp (ekp) field - */ - - if (kij_alg==0 && (crypt_alg || auth_alg)) { - printf("Warning: Kij Alg. undefined, but Auth. or Crypt. used!"); - printf("Warning: Assuming empty Kp\n"); - crypt_alg=auth_alg=0; - } - /* - * do this with a for-loop to avoid alignment problems and the - * overhead of calling bcopy() - */ - len = skip_ekp_sizes[crypt_alg]; - len = len>(int)skip_auth_sizes[auth_alg]?len:skip_auth_sizes[auth_alg]; - if (len && skip_kij_sizes[kij_alg] && len % skip_kij_sizes[kij_alg]) { - len += skip_kij_sizes[kij_alg] - (len%skip_kij_sizes[kij_alg]); - } - if ((unsigned short) (end - p) < len) { - printf("[SKIP|] (truncated)\n"); - return; - } - - printf("SKIP: Encrypted Kp\t\t"); - for (i = 0; i < len; i++) { - printf("%02x ", (unsigned char) *p++); - } - printf("\n"); - - - if (snsid) { - /* - * Source Master Key-ID field - */ - if ((end - p) < skip_nsid_sizes[snsid]) { - printf("[SKIP|] (truncated)\n"); - return; - } - printf("SKIP: Source Master Key-ID\t"); - if (snsid==1) { - printf("%s",ipaddr_string(p)); - p+=skip_nsid_sizes[snsid]; - } else { - for (i = 0; i < skip_nsid_sizes[snsid]; i++) { - printf("%02x ", (unsigned char) *p++); - } - } - printf("\n"); - } - - if (dnsid) { - /* - * Destination Master Key-ID field - */ - if ((end - p) < skip_nsid_sizes[dnsid]) { - printf("[SKIP|] (truncated)\n"); - return; - } - printf("SKIP: Dest. Master Key-ID\t"); - if (dnsid==1) { - printf("%s",ipaddr_string(p)); - p+=skip_nsid_sizes[dnsid]; - } else { - for (i = 0; i < skip_nsid_sizes[dnsid]; i++) { - printf("%02x ", (unsigned char) *p++); - } - } - printf("\n"); - } - if (p%s:%d",ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst),length); - if (!skipflag) - return; - - if (end-p <4) { - printf("[SKIP-AH|]\n"); - return; - } - - nxt = *p; - printf("\nSKIP-AH: Next Protocol Field\t0x%02x\t\t%s\n", nxt, - skip_protocol_name(nxt)); - p++; - - len= 4 * (int) *p; - printf("SKIP-AH: length\t\t\t%d\n", len); - - p++; - - if (*p) printf("SKIP-AH: byte 3\t\t\treserved,\tis now0x%02x\n", - (int) *p++); - else p++; - if (*p) printf("SKIP-AH: byte 4\t\t\treserved,\tis now0x%02x\n", - (int) *p++); - else p++; - - if (end-p <4) { - printf("[SKIP-AH|]\n"); - return; - } - - spi=*p++<<24; - spi+=*p++<<16; - spi+=*p++<<8; - spi+=*p; - printf("SKIP-AH: SPI\t\t\t0x%08x\t", spi ); - if (spi==0) { - printf("NO association\n"); - } else if (spi==1) { - printf("SKIP association\n"); - if (expected_auth_size) { - if (expected_auth_size != len) { - printf("Warning: Length does not match SKIP Auth Alg!\n"); - } - expected_auth_size=0; - } - } else if (spi<256) { - printf("UNKNOWN association\n"); - } else { - printf("DYNAMIC association\n"); - } - - p++; - - - /* - * authentication data - */ - - if ((unsigned short) (end - p) < len) { - printf("[SKIP-AH|] (truncated)\n"); - return; - } - - printf("SKIP-AH: Authentication Data\t"); - for (i = 0; i < len; i++) { - printf("%02x ", (unsigned char) *p++); - if (i%s:%d",ipaddr_string(&ip->ip_src), - ipaddr_string(&ip->ip_dst),length); - if (!skipflag) - return; - - if (end-p <4) { - printf("[SKIP-ESP|]\n"); - } - - spi=*p++<<24; - spi+=*p++<<16; - spi+=*p++<<8; - spi+=*p; - printf("\nSKIP-ESP: SPI\t\t\t0x%08x\t", spi ); - if (spi==0) { - printf("NO association\n"); - len=0; - } else if (spi==1) { - printf("SKIP association\n"); - len=expected_iv_size; - if (!expected_iv_size) { - printf("Warning: IV size not defined by SKIP Crypt Alg!\n"); - } else expected_iv_size=0; - } else if (spi<256) { - printf("UNKNOWN association\n"); - len=0; - } else { - printf("DYNAMIC association\n"); - len=0; - } - - p++; - - /* - * IV data - */ - - if ((unsigned short) (end - p) < len) { - printf("[SKIP-ESP|] (truncated)\n"); - return; - } - - printf("SKIP-ESP: Initalization Vector\t"); - if (len) { - for (i = 0; i < len; i++) { - printf("%02x ", (unsigned char) *p++); - if (i -#include -#include -#include -#include -#include -#include - -#if __STDC__ -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ - -static u_int lastlen[2][256]; -static u_int lastconn = 255; - -static void sliplink_print(const u_char *, const struct ip *, u_int); -static void compressed_sl_print(const u_char *, const struct ip *, u_int, int); - -/* XXX BSD/OS 2.1 compatibility */ -#if !defined(SLIP_HDRLEN) && defined(SLC_BPFHDR) -#define SLIP_HDRLEN SLC_BPFHDR -#define SLX_DIR 0 -#define SLX_CHDR (SLC_BPFHDRLEN - 1) -#define CHDR_LEN (SLC_BPFHDR - SLC_BPFHDRLEN) -#endif - -void -sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - register u_int caplen = h->caplen; - register u_int length = h->len; - register const struct ip *ip; - - ts_print(&h->ts); - - if (caplen < SLIP_HDRLEN) { - printf("[|slip]"); - goto out; - } - /* - * 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; - - length -= SLIP_HDRLEN; - - ip = (struct ip *)(p + SLIP_HDRLEN); - - if (eflag) - sliplink_print(p, ip, length); - - ip_print((u_char *)ip, length); - - if (xflag) - default_print((u_char *)ip, caplen - SLIP_HDRLEN); - out: - putchar('\n'); -} - -static void -sliplink_print(register const u_char *p, register const struct ip *ip, - register u_int length) -{ - int dir; - u_int hlen; - - dir = p[SLX_DIR]; - putchar(dir == SLIPDIR_IN ? 'I' : 'O'); - putchar(' '); - - if (nflag) { - /* XXX just dump the header */ - register int i; - - for (i = SLX_CHDR; i < SLX_CHDR + CHDR_LEN - 1; ++i) - printf("%02x.", p[i]); - printf("%02x: ", p[SLX_CHDR + CHDR_LEN - 1]); - return; - } - switch (p[SLX_CHDR] & 0xf0) { - - case TYPE_IP: - printf("ip %d: ", length + SLIP_HDRLEN); - break; - - case TYPE_UNCOMPRESSED_TCP: - /* - * The connection id is stored in the IP protocol field. - * Get it from the link layer since sl_uncompress_tcp() - * has restored the IP header copy to IPPROTO_TCP. - */ - lastconn = ((struct ip *)&p[SLX_CHDR])->ip_p; - hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; - lastlen[dir][lastconn] = length - (hlen << 2); - printf("utcp %d: ", lastconn); - break; - - default: - if (p[SLX_CHDR] & TYPE_COMPRESSED_TCP) { - compressed_sl_print(&p[SLX_CHDR], ip, - length, dir); - printf(": "); - } else - printf("slip-%d!: ", p[SLX_CHDR]); - } -} - -static const u_char * -print_sl_change(const char *str, register const u_char *cp) -{ - register u_int i; - - if ((i = *cp++) == 0) { - i = EXTRACT_16BITS(cp); - cp += 2; - } - printf(" %s%d", str, i); - return (cp); -} - -static const u_char * -print_sl_winchange(register const u_char *cp) -{ - register short i; - - if ((i = *cp++) == 0) { - i = EXTRACT_16BITS(cp); - cp += 2; - } - if (i >= 0) - printf(" W+%d", i); - else - printf(" W%d", i); - return (cp); -} - -static void -compressed_sl_print(const u_char *chdr, const struct ip *ip, - u_int length, int dir) -{ - register const u_char *cp = chdr; - register u_int flags, hlen; - - flags = *cp++; - if (flags & NEW_C) { - lastconn = *cp++; - printf("ctcp %d", lastconn); - } else - printf("ctcp *"); - - /* skip tcp checksum */ - cp += 2; - - switch (flags & SPECIALS_MASK) { - case SPECIAL_I: - printf(" *SA+%d", lastlen[dir][lastconn]); - break; - - case SPECIAL_D: - printf(" *S+%d", lastlen[dir][lastconn]); - break; - - default: - if (flags & NEW_U) - cp = print_sl_change("U=", cp); - if (flags & NEW_W) - cp = print_sl_winchange(cp); - if (flags & NEW_A) - cp = print_sl_change("A+", cp); - if (flags & NEW_S) - cp = print_sl_change("S+", cp); - break; - } - if (flags & NEW_I) - cp = print_sl_change("I+", cp); - - /* - * 'hlen' is the length of the uncompressed TCP/IP header (in words). - * 'cp - chdr' is the length of the compressed header. - * 'length - hlen' is the amount of data in the packet. - */ - hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int32_t *)ip)[hlen])->th_off; - lastlen[dir][lastconn] = length - (hlen << 2); - printf(" %d (%d)", lastlen[dir][lastconn], cp - chdr); -} -#else -#include -#include - -#include -#include - -#include "interface.h" -void -sl_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p) -{ - - error("not configured for slip"); - /* NOTREACHED */ -} -#endif diff --git a/tcpdump.tproj/print-snmp.c b/tcpdump.tproj/print-snmp.c deleted file mode 100644 index 860be8a..0000000 --- a/tcpdump.tproj/print-snmp.c +++ /dev/null @@ -1,1063 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1993, 1994, 1995, 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 John Robert LoVerso. - * 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. - * - * This implementation has been influenced by the CMU SNMP release, - * by Steve Waldbusser. However, this shares no code with that system. - * Additional ASN.1 insight gained from Marshall T. Rose's _The_Open_Book_. - * Earlier forms of this implementation were derived and/or inspired by an - * awk script originally written by C. Philip Wood of LANL (but later - * heavily modified by John Robert LoVerso). The copyright notice for - * that work is preserved below, even though it may not rightly apply - * to this file. - * - * This started out as a very simple program, but the incremental decoding - * (into the BE structure) complicated things. - * - # Los Alamos National Laboratory - # - # Copyright, 1990. The Regents of the University of California. - # This software was produced under a U.S. Government contract - # (W-7405-ENG-36) by Los Alamos National Laboratory, which is - # operated by the University of California for the U.S. Department - # of Energy. The U.S. Government is licensed to use, reproduce, - # and distribute this software. Permission is granted to the - # public to copy and use this software without charge, provided - # that this Notice and any statement of authorship are reproduced - # on all copies. Neither the Government nor the University makes - # any warranty, express or implied, or assumes any liability or - # responsibility for the use of this software. - # @(#)snmp.awk.x 1.1 (LANL) 1/15/90 - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-snmp.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -/* - * Universal ASN.1 types - * (we only care about the tag values for those allowed in the Internet SMI) - */ -char *Universal[] = { - "U-0", - "Boolean", - "Integer", -#define INTEGER 2 - "Bitstring", - "String", -#define STRING 4 - "Null", -#define ASN_NULL 5 - "ObjID", -#define OBJECTID 6 - "ObjectDes", - "U-8","U-9","U-10","U-11", /* 8-11 */ - "U-12","U-13","U-14","U-15", /* 12-15 */ - "Sequence", -#define SEQUENCE 16 - "Set" -}; - -/* - * Application-wide ASN.1 types from the Internet SMI and their tags - */ -char *Application[] = { - "IpAddress", -#define IPADDR 0 - "Counter", -#define COUNTER 1 - "Gauge", -#define GAUGE 2 - "TimeTicks", -#define TIMETICKS 3 - "Opaque" -}; - -/* - * Context-specific ASN.1 types for the SNMP PDUs and their tags - */ -char *Context[] = { - "GetRequest", -#define GETREQ 0 - "GetNextRequest", -#define GETNEXTREQ 1 - "GetResponse", -#define GETRESP 2 - "SetRequest", -#define SETREQ 3 - "Trap" -#define TRAP 4 -}; - -/* - * Private ASN.1 types - * The Internet SMI does not specify any - */ -char *Private[] = { - "P-0" -}; - -/* - * error-status values for any SNMP PDU - */ -char *ErrorStatus[] = { - "noError", - "tooBig", - "noSuchName", - "badValue", - "readOnly", - "genErr" -}; -#define DECODE_ErrorStatus(e) \ - ( e >= 0 && e <= sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \ - ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf)) - -/* - * generic-trap values in the SNMP Trap-PDU - */ -char *GenericTrap[] = { - "coldStart", - "warmStart", - "linkDown", - "linkUp", - "authenticationFailure", - "egpNeighborLoss", - "enterpriseSpecific" -#define GT_ENTERPRISE 7 -}; -#define DECODE_GenericTrap(t) \ - ( t >= 0 && t <= sizeof(GenericTrap)/sizeof(GenericTrap[0]) \ - ? GenericTrap[t] : (sprintf(buf, "gt=%d", t), buf)) - -/* - * ASN.1 type class table - * Ties together the preceding Universal, Application, Context, and Private - * type definitions. - */ -#define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */ -struct { - char *name; - char **Id; - int numIDs; - } Class[] = { - defineCLASS(Universal), -#define UNIVERSAL 0 - defineCLASS(Application), -#define APPLICATION 1 - defineCLASS(Context), -#define CONTEXT 2 - defineCLASS(Private), -#define PRIVATE 3 -}; - -/* - * defined forms for ASN.1 types - */ -char *Form[] = { - "Primitive", -#define PRIMITIVE 0 - "Constructed", -#define CONSTRUCTED 1 -}; - -/* - * A structure for the OID tree for the compiled-in MIB. - * This is stored as a general-order tree. - */ -struct obj { - char *desc; /* name of object */ - u_char oid; /* sub-id following parent */ - u_char type; /* object type (unused) */ - struct obj *child, *next; /* child and next sibling pointers */ -} *objp = NULL; - -/* - * Include the compiled in SNMP MIB. "mib.h" is produced by feeding - * RFC-1156 format files into "makemib". "mib.h" MUST define at least - * a value for `mibroot'. - * - * In particular, this is gross, as this is including initialized structures, - * and by right shouldn't be an "include" file. - */ -#include "mib.h" - -/* - * This defines a list of OIDs which will be abbreviated on output. - * Currently, this includes the prefixes for the Internet MIB, the - * private enterprises tree, and the experimental tree. - */ -struct obj_abrev { - char *prefix; /* prefix for this abrev */ - struct obj *node; /* pointer into object table */ - char *oid; /* ASN.1 encoded OID */ -} obj_abrev_list[] = { -#ifndef NO_ABREV_MIB - /* .iso.org.dod.internet.mgmt.mib */ - { "", &_mib_obj, "\53\6\1\2\1" }, -#endif -#ifndef NO_ABREV_ENTER - /* .iso.org.dod.internet.private.enterprises */ - { "E:", &_enterprises_obj, "\53\6\1\4\1" }, -#endif -#ifndef NO_ABREV_EXPERI - /* .iso.org.dod.internet.experimental */ - { "X:", &_experimental_obj, "\53\6\1\3" }, -#endif - { 0,0,0 } -}; - -/* - * This is used in the OID print routine to walk down the object tree - * rooted at `mibroot'. - */ -#define OBJ_PRINT(o, suppressdot) \ -{ \ - if (objp) { \ - do { \ - if ((o) == objp->oid) \ - break; \ - } while ((objp = objp->next) != NULL); \ - } \ - if (objp) { \ - printf(suppressdot?"%s":".%s", objp->desc); \ - objp = objp->child; \ - } else \ - printf(suppressdot?"%u":".%u", (o)); \ -} - -/* - * This is the definition for the Any-Data-Type storage used purely for - * temporary internal representation while decoding an ASN.1 data stream. - */ -struct be { - u_int32_t asnlen; - union { - caddr_t raw; - int32_t integer; - u_int32_t uns; - const u_char *str; - } data; - u_short id; - u_char form, class; /* tag info */ - u_char type; -#define BE_ANY 255 -#define BE_NONE 0 -#define BE_NULL 1 -#define BE_OCTET 2 -#define BE_OID 3 -#define BE_INT 4 -#define BE_UNS 5 -#define BE_STR 6 -#define BE_SEQ 7 -#define BE_INETADDR 8 -#define BE_PDU 9 -}; - -/* - * Defaults for SNMP PDU components - */ -#define DEF_COMMUNITY "public" -#define DEF_VERSION 0 - -/* - * constants for ASN.1 decoding - */ -#define OIDMUX 40 -#define ASNLEN_INETADDR 4 -#define ASN_SHIFT7 7 -#define ASN_SHIFT8 8 -#define ASN_BIT8 0x80 -#define ASN_LONGLEN 0x80 - -#define ASN_ID_BITS 0x1f -#define ASN_FORM_BITS 0x20 -#define ASN_FORM_SHIFT 5 -#define ASN_CLASS_BITS 0xc0 -#define ASN_CLASS_SHIFT 6 - -#define ASN_ID_EXT 0x1f /* extension ID in tag field */ - -/* - * truncated==1 means the packet was complete, but we don't have all of - * it to decode. - */ -static int truncated; -#define ifNotTruncated if (truncated) fputs("[|snmp]", stdout); else - -/* - * This decodes the next ASN.1 object in the stream pointed to by "p" - * (and of real-length "len") and stores the intermediate data in the - * provided BE object. - * - * This returns -l if it fails (i.e., the ASN.1 stream is not valid). - * O/w, this returns the number of bytes parsed from "p". - */ -static int -asn1_parse(register const u_char *p, u_int len, struct be *elem) -{ - u_char form, class, id; - int i, hdr; - - elem->asnlen = 0; - elem->type = BE_ANY; - if (len < 1) { - ifNotTruncated puts("[nothing to parse], stdout"); - return -1; - } - - /* - * it would be nice to use a bit field, but you can't depend on them. - * +---+---+---+---+---+---+---+---+ - * + class |frm| id | - * +---+---+---+---+---+---+---+---+ - * 7 6 5 4 3 2 1 0 - */ - id = *p & ASN_ID_BITS; /* lower 5 bits, range 00-1f */ -#ifdef notdef - form = (*p & 0xe0) >> 5; /* move upper 3 bits to lower 3 */ - class = form >> 1; /* bits 7&6 -> bits 1&0, range 0-3 */ - form &= 0x1; /* bit 5 -> bit 0, range 0-1 */ -#else - form = (u_char)(*p & ASN_FORM_BITS) >> ASN_FORM_SHIFT; - class = (u_char)(*p & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT; -#endif - elem->form = form; - elem->class = class; - elem->id = id; - if (vflag) - printf("|%.2x", *p); - p++; len--; hdr = 1; - /* extended tag field */ - if (id == ASN_ID_EXT) { - for (id = 0; *p & ASN_BIT8 && len > 0; len--, hdr++, p++) { - if (vflag) - printf("|%.2x", *p); - id = (id << 7) | (*p & ~ASN_BIT8); - } - if (len == 0 && *p & ASN_BIT8) { - ifNotTruncated fputs("[Xtagfield?]", stdout); - return -1; - } - elem->id = id = (id << 7) | *p; - --len; - ++hdr; - ++p; - } - if (len < 1) { - ifNotTruncated fputs("[no asnlen]", stdout); - return -1; - } - elem->asnlen = *p; - if (vflag) - printf("|%.2x", *p); - p++; len--; hdr++; - if (elem->asnlen & ASN_BIT8) { - int noct = elem->asnlen % ASN_BIT8; - elem->asnlen = 0; - if (len < noct) { - ifNotTruncated printf("[asnlen? %d<%d]", len, noct); - return -1; - } - for (; noct-- > 0; len--, hdr++) { - if (vflag) - printf("|%.2x", *p); - elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++; - } - } - if (len < elem->asnlen) { - if (!truncated) { - printf("[len%dasnlen); - return -1; - } - /* maybe should check at least 4? */ - elem->asnlen = len; - } - if (form >= sizeof(Form)/sizeof(Form[0])) { - ifNotTruncated printf("[form?%d]", form); - return -1; - } - if (class >= sizeof(Class)/sizeof(Class[0])) { - ifNotTruncated printf("[class?%c/%d]", *Form[form], class); - return -1; - } - if ((int)id >= Class[class].numIDs) { - ifNotTruncated printf("[id?%c/%s/%d]", *Form[form], - Class[class].name, id); - return -1; - } - - switch (form) { - case PRIMITIVE: - switch (class) { - case UNIVERSAL: - switch (id) { - case STRING: - elem->type = BE_STR; - elem->data.str = p; - break; - - case INTEGER: { - register int32_t data; - elem->type = BE_INT; - data = 0; - - if (*p & ASN_BIT8) /* negative */ - data = -1; - for (i = elem->asnlen; i-- > 0; p++) - data = (data << ASN_SHIFT8) | *p; - elem->data.integer = data; - break; - } - - case OBJECTID: - elem->type = BE_OID; - elem->data.raw = (caddr_t)p; - break; - - case ASN_NULL: - elem->type = BE_NULL; - elem->data.raw = NULL; - break; - - default: - elem->type = BE_OCTET; - elem->data.raw = (caddr_t)p; - printf("[P/U/%s]", - Class[class].Id[id]); - break; - } - break; - - case APPLICATION: - switch (id) { - case IPADDR: - elem->type = BE_INETADDR; - elem->data.raw = (caddr_t)p; - break; - - case COUNTER: - case GAUGE: - case TIMETICKS: { - register u_int32_t data; - elem->type = BE_UNS; - data = 0; - for (i = elem->asnlen; i-- > 0; p++) - data = (data << 8) + *p; - elem->data.uns = data; - break; - } - - default: - elem->type = BE_OCTET; - elem->data.raw = (caddr_t)p; - printf("[P/A/%s]", - Class[class].Id[id]); - break; - } - break; - - default: - elem->type = BE_OCTET; - elem->data.raw = (caddr_t)p; - printf("[P/%s/%s]", - Class[class].name, Class[class].Id[id]); - break; - } - break; - - case CONSTRUCTED: - switch (class) { - case UNIVERSAL: - switch (id) { - case SEQUENCE: - elem->type = BE_SEQ; - elem->data.raw = (caddr_t)p; - break; - - default: - elem->type = BE_OCTET; - elem->data.raw = (caddr_t)p; - printf("C/U/%s", Class[class].Id[id]); - break; - } - break; - - case CONTEXT: - elem->type = BE_PDU; - elem->data.raw = (caddr_t)p; - break; - - default: - elem->type = BE_OCTET; - elem->data.raw = (caddr_t)p; - printf("C/%s/%s", - Class[class].name, Class[class].Id[id]); - break; - } - break; - } - p += elem->asnlen; - len -= elem->asnlen; - return elem->asnlen + hdr; -} - -/* - * Display the ASN.1 object represented by the BE object. - * This used to be an integral part of asn1_parse() before the intermediate - * BE form was added. - */ -static void -asn1_print(struct be *elem) -{ - u_char *p = (u_char *)elem->data.raw; - u_int32_t asnlen = elem->asnlen; - int i; - - switch (elem->type) { - - case BE_OCTET: - for (i = asnlen; i-- > 0; p++); - printf("_%.2x", *p); - break; - - case BE_NULL: - break; - - case BE_OID: { - int o = 0, first = -1, i = asnlen; - - if (!nflag && asnlen > 2) { - struct obj_abrev *a = &obj_abrev_list[0]; - for (; a->node; a++) { - if (!memcmp(a->oid, (char *)p, - strlen(a->oid))) { - objp = a->node->child; - i -= strlen(a->oid); - p += strlen(a->oid); - fputs(a->prefix, stdout); - first = 1; - break; - } - } - } - for (; i-- > 0; p++) { - o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8); - if (*p & ASN_LONGLEN) - continue; - - /* - * first subitem encodes two items with 1st*OIDMUX+2nd - */ - if (first < 0) { - if (!nflag) - objp = mibroot; - first = 0; - OBJ_PRINT(o/OIDMUX, first); - o %= OIDMUX; - } - OBJ_PRINT(o, first); - if (--first < 0) - first = 0; - o = 0; - } - break; - } - - case BE_INT: - printf("%d", elem->data.integer); - break; - - case BE_UNS: - printf("%d", elem->data.uns); - break; - - case BE_STR: { - register int printable = 1, first = 1; - const u_char *p = elem->data.str; - for (i = asnlen; printable && i-- > 0; p++) - printable = isprint(*p) || isspace(*p); - p = elem->data.str; - if (printable) { - putchar('"'); - (void)fn_print(p, p + asnlen); - putchar('"'); - } else - for (i = asnlen; i-- > 0; p++) { - printf(first ? "%.2x" : "_%.2x", *p); - first = 0; - } - break; - } - - case BE_SEQ: - printf("Seq(%u)", elem->asnlen); - break; - - case BE_INETADDR: { - char sep; - if (asnlen != ASNLEN_INETADDR) - printf("[inetaddr len!=%d]", ASNLEN_INETADDR); - sep='['; - for (i = asnlen; i-- > 0; p++) { - printf("%c%u", sep, *p); - sep='.'; - } - putchar(']'); - break; - } - - case BE_PDU: - printf("%s(%u)", - Class[CONTEXT].Id[elem->id], elem->asnlen); - break; - - case BE_ANY: - fputs("[BE_ANY!?]", stdout); - break; - - default: - fputs("[be!?]", stdout); - break; - } -} - -#ifdef notdef -/* - * This is a brute force ASN.1 printer: recurses to dump an entire structure. - * This will work for any ASN.1 stream, not just an SNMP PDU. - * - * By adding newlines and spaces at the correct places, this would print in - * Rose-Normal-Form. - * - * This is not currently used. - */ -static void -asn1_decode(u_char *p, u_int length) -{ - struct be elem; - int i = 0; - - while (i >= 0 && length > 0) { - i = asn1_parse(p, length, &elem); - if (i >= 0) { - fputs(" ", stdout); - asn1_print(&elem); - if (elem.type == BE_SEQ || elem.type == BE_PDU) { - fputs(" {", stdout); - asn1_decode(elem.data.raw, elem.asnlen); - fputs(" }", stdout); - } - length -= i; - p += i; - } - } -} -#endif - -/* - * General SNMP header - * SEQUENCE { - * version INTEGER {version-1(0)}, - * community OCTET STRING, - * data ANY -- PDUs - * } - * PDUs for all but Trap: (see rfc1157 from page 15 on) - * SEQUENCE { - * request-id INTEGER, - * error-status INTEGER, - * error-index INTEGER, - * varbindlist SEQUENCE OF - * SEQUENCE { - * name ObjectName, - * value ObjectValue - * } - * } - * PDU for Trap: - * SEQUENCE { - * enterprise OBJECT IDENTIFIER, - * agent-addr NetworkAddress, - * generic-trap INTEGER, - * specific-trap INTEGER, - * time-stamp TimeTicks, - * varbindlist SEQUENCE OF - * SEQUENCE { - * name ObjectName, - * value ObjectValue - * } - * } - */ - -/* - * Decode SNMP varBind - */ -static void -varbind_print(u_char pduid, const u_char *np, u_int length, int error) -{ - struct be elem; - int count = 0, ind; - - /* Sequence of varBind */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_SEQ) { - fputs("[!SEQ of varbind]", stdout); - asn1_print(&elem); - return; - } - if (count < length) - printf("[%d extra after SEQ of varbind]", length - count); - /* descend */ - length = elem.asnlen; - np = (u_char *)elem.data.raw; - - for (ind = 1; length > 0; ind++) { - const u_char *vbend; - u_int vblength; - - if (!error || ind == error) - fputs(" ", stdout); - - /* Sequence */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_SEQ) { - fputs("[!varbind]", stdout); - asn1_print(&elem); - return; - } - vbend = np + count; - vblength = length - count; - /* descend */ - length = elem.asnlen; - np = (u_char *)elem.data.raw; - - /* objName (OID) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_OID) { - fputs("[objName!=OID]", stdout); - asn1_print(&elem); - return; - } - if (!error || ind == error) - asn1_print(&elem); - length -= count; - np += count; - - if (pduid != GETREQ && pduid != GETNEXTREQ && !error) - fputs("=", stdout); - - /* objVal (ANY) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (pduid == GETREQ || pduid == GETNEXTREQ) { - if (elem.type != BE_NULL) { - fputs("[objVal!=NULL]", stdout); - asn1_print(&elem); - } - } else - if (error && ind == error && elem.type != BE_NULL) - fputs("[err objVal!=NULL]", stdout); - if (!error || ind == error) - asn1_print(&elem); - - length = vblength; - np = vbend; - } -} - -/* - * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, and SetRequest - */ -static void -snmppdu_print(u_char pduid, const u_char *np, u_int length) -{ - struct be elem; - int count = 0, error; - - /* reqId (Integer) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INT) { - fputs("[reqId!=INT]", stdout); - asn1_print(&elem); - return; - } - /* ignore the reqId */ - length -= count; - np += count; - - /* errorStatus (Integer) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INT) { - fputs("[errorStatus!=INT]", stdout); - asn1_print(&elem); - return; - } - error = 0; - if ((pduid == GETREQ || pduid == GETNEXTREQ) - && elem.data.integer != 0) { - char errbuf[10]; - printf("[errorStatus(%s)!=0]", - DECODE_ErrorStatus(elem.data.integer)); - } else if (elem.data.integer != 0) { - char errbuf[10]; - printf(" %s", DECODE_ErrorStatus(elem.data.integer)); - error = elem.data.integer; - } - length -= count; - np += count; - - /* errorIndex (Integer) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INT) { - fputs("[errorIndex!=INT]", stdout); - asn1_print(&elem); - return; - } - if ((pduid == GETREQ || pduid == GETNEXTREQ) - && elem.data.integer != 0) - printf("[errorIndex(%d)!=0]", elem.data.integer); - else if (elem.data.integer != 0) { - if (!error) - printf("[errorIndex(%d) w/o errorStatus]", - elem.data.integer); - else { - printf("@%d", elem.data.integer); - error = elem.data.integer; - } - } else if (error) { - fputs("[errorIndex==0]", stdout); - error = 0; - } - length -= count; - np += count; - - varbind_print(pduid, np, length, error); - return; -} - -/* - * Decode SNMP Trap PDU - */ -static void -trap_print(const u_char *np, u_int length) -{ - struct be elem; - int count = 0, generic; - - putchar(' '); - - /* enterprise (oid) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_OID) { - fputs("[enterprise!=OID]", stdout); - asn1_print(&elem); - return; - } - asn1_print(&elem); - length -= count; - np += count; - - putchar(' '); - - /* agent-addr (inetaddr) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INETADDR) { - fputs("[agent-addr!=INETADDR]", stdout); - asn1_print(&elem); - return; - } - asn1_print(&elem); - length -= count; - np += count; - - /* generic-trap (Integer) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INT) { - fputs("[generic-trap!=INT]", stdout); - asn1_print(&elem); - return; - } - generic = elem.data.integer; - { - char buf[10]; - printf(" %s", DECODE_GenericTrap(generic)); - } - length -= count; - np += count; - - /* specific-trap (Integer) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INT) { - fputs("[specific-trap!=INT]", stdout); - asn1_print(&elem); - return; - } - if (generic != GT_ENTERPRISE) { - if (elem.data.integer != 0) - printf("[specific-trap(%d)!=0]", elem.data.integer); - } else - printf(" s=%d", elem.data.integer); - length -= count; - np += count; - - putchar(' '); - - /* time-stamp (TimeTicks) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_UNS) { /* XXX */ - fputs("[time-stamp!=TIMETICKS]", stdout); - asn1_print(&elem); - return; - } - asn1_print(&elem); - length -= count; - np += count; - - varbind_print (TRAP, np, length, 0); - return; -} - -/* - * Decode SNMP header and pass on to PDU printing routines - */ -void -snmp_print(const u_char *np, u_int length) -{ - struct be elem, pdu; - int count = 0; - - truncated = 0; - - /* truncated packet? */ - if (np + length > snapend) { - truncated = 1; - length = snapend - np; - } - - putchar(' '); - - /* initial Sequence */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_SEQ) { - fputs("[!init SEQ]", stdout); - asn1_print(&elem); - return; - } - if (count < length) - printf("[%d extra after iSEQ]", length - count); - /* descend */ - length = elem.asnlen; - np = (u_char *)elem.data.raw; - /* Version (Integer) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_INT) { - fputs("[version!=INT]", stdout); - asn1_print(&elem); - return; - } - /* only handle version==0 */ - if (elem.data.integer != DEF_VERSION) { - printf("[version(%d)!=0]", elem.data.integer); - return; - } - length -= count; - np += count; - - /* Community (String) */ - if ((count = asn1_parse(np, length, &elem)) < 0) - return; - if (elem.type != BE_STR) { - fputs("[comm!=STR]", stdout); - asn1_print(&elem); - return; - } - /* default community */ - if (strncmp((char *)elem.data.str, DEF_COMMUNITY, - sizeof(DEF_COMMUNITY) - 1)) - /* ! "public" */ - printf("C=%.*s ", (int)elem.asnlen, elem.data.str); - length -= count; - np += count; - - /* PDU (Context) */ - if ((count = asn1_parse(np, length, &pdu)) < 0) - return; - if (pdu.type != BE_PDU) { - fputs("[no PDU]", stdout); - return; - } - if (count < length) - printf("[%d extra after PDU]", length - count); - asn1_print(&pdu); - /* descend into PDU */ - length = pdu.asnlen; - np = (u_char *)pdu.data.raw; - - switch (pdu.id) { - case TRAP: - trap_print(np, length); - break; - case GETREQ: - case GETNEXTREQ: - case GETRESP: - case SETREQ: - snmppdu_print(pdu.id, np, length); - break; - } - return; -} diff --git a/tcpdump.tproj/print-sunrpc.c b/tcpdump.tproj/print-sunrpc.c deleted file mode 100644 index 0c9f696..0000000 --- a/tcpdump.tproj/print-sunrpc.c +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-sunrpc.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#if __STDC__ -struct mbuf; -struct rtentry; -#endif -#include - -#include -#include -#include -#include -#include - -#include -#ifdef HAVE_RPC_RPCENT_H -#include -#endif -#include - -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -static struct tok proc2str[] = { - { PMAPPROC_NULL, "null" }, - { PMAPPROC_SET, "set" }, - { PMAPPROC_UNSET, "unset" }, - { PMAPPROC_GETPORT, "getport" }, - { PMAPPROC_DUMP, "dump" }, - { PMAPPROC_CALLIT, "call" }, - { 0, NULL } -}; - -/* Forwards */ -static char *progstr(u_int32_t); - -void -sunrpcrequest_print(register const u_char *bp, register u_int length, - register const u_char *bp2) -{ - register const struct rpc_msg *rp; - register const struct ip *ip; - u_int32_t x; - - rp = (struct rpc_msg *)bp; - ip = (struct ip *)bp2; - - if (!nflag) - (void)printf("%s.%x > %s.sunrpc: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - length); - else - (void)printf("%s.%x > %s.%x: %d", - ipaddr_string(&ip->ip_src), - (u_int32_t)ntohl(rp->rm_xid), - ipaddr_string(&ip->ip_dst), - PMAPPORT, - length); - printf(" %s", tok2str(proc2str, " proc #%u", - (u_int32_t)ntohl(rp->rm_call.cb_proc))); - x = ntohl(rp->rm_call.cb_rpcvers); - if (x != 2) - printf(" [rpcver %u]", x); - - switch (ntohl(rp->rm_call.cb_proc)) { - - case PMAPPROC_SET: - case PMAPPROC_UNSET: - case PMAPPROC_GETPORT: - case PMAPPROC_CALLIT: - x = ntohl(rp->rm_call.cb_prog); - if (!nflag) - printf(" %s", progstr(x)); - else - printf(" %u", x); - printf(".%u", (u_int32_t)ntohl(rp->rm_call.cb_vers)); - break; - } -} - -static char * -progstr(prog) - u_int32_t prog; -{ - register struct rpcent *rp; - static char buf[32]; - static lastprog = 0; - - if (lastprog != 0 && prog == lastprog) - return (buf); - rp = getrpcbynumber(prog); - if (rp == NULL) - (void) sprintf(buf, "#%u", prog); - else - strcpy(buf, rp->r_name); - return (buf); -} diff --git a/tcpdump.tproj/print-tcp.c b/tcpdump.tproj/print-tcp.c deleted file mode 100644 index 2c0d1e3..0000000 --- a/tcpdump.tproj/print-tcp.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-tcp.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "extract.h" - -/* Compatibility */ -#ifndef TCPOPT_WSCALE -#define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */ -#endif -#ifndef TCPOPT_SACKOK -#define TCPOPT_SACKOK 4 /* selective ack ok (rfc1072) */ -#endif -#ifndef TCPOPT_SACK -#define TCPOPT_SACK 5 /* selective ack (rfc1072) */ -#endif -#ifndef TCPOPT_ECHO -#define TCPOPT_ECHO 6 /* echo (rfc1072) */ -#endif -#ifndef TCPOPT_ECHOREPLY -#define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */ -#endif -#ifndef TCPOPT_TIMESTAMP -#define TCPOPT_TIMESTAMP 8 /* timestamps (rfc1323) */ -#endif -#ifndef TCPOPT_CC -#define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */ -#endif -#ifndef TCPOPT_CCNEW -#define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */ -#endif -#ifndef TCPOPT_CCECHO -#define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */ -#endif - -struct tha { - struct in_addr src; - struct in_addr dst; - u_int port; -}; - -struct tcp_seq_hash { - struct tcp_seq_hash *nxt; - struct tha addr; - tcp_seq seq; - tcp_seq ack; -}; - -#define TSEQ_HASHSIZE 919 - -/* These tcp optinos do not have the size octet */ -#define ZEROLENOPT(o) ((o) == TCPOPT_EOL || (o) == TCPOPT_NOP) - -static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; - - -void -tcp_print(register const u_char *bp, register u_int length, - register const u_char *bp2) -{ - register const struct tcphdr *tp; - register const struct ip *ip; - register u_char flags; - register int hlen; - register char ch; - u_short sport, dport, win, urp; - u_int32_t seq, ack; - - tp = (struct tcphdr *)bp; - ip = (struct ip *)bp2; - ch = '\0'; - TCHECK(*tp); - if (length < sizeof(*tp)) { - (void)printf("truncated-tcp %d", length); - return; - } - - sport = ntohs(tp->th_sport); - dport = ntohs(tp->th_dport); - seq = ntohl(tp->th_seq); - ack = ntohl(tp->th_ack); - win = ntohs(tp->th_win); - urp = ntohs(tp->th_urp); - - (void)printf("%s.%s > %s.%s: ", - ipaddr_string(&ip->ip_src), tcpport_string(sport), - ipaddr_string(&ip->ip_dst), tcpport_string(dport)); - - if (qflag) { - (void)printf("tcp %d", length - tp->th_off * 4); - return; - } - if ((flags = tp->th_flags) & (TH_SYN|TH_FIN|TH_RST|TH_PUSH)) { - if (flags & TH_SYN) - putchar('S'); - if (flags & TH_FIN) - putchar('F'); - if (flags & TH_RST) - putchar('R'); - if (flags & TH_PUSH) - putchar('P'); - } else - putchar('.'); - - if (!Sflag && (flags & TH_ACK)) { - register struct tcp_seq_hash *th; - register int rev; - struct tha tha; - /* - * Find (or record) the initial sequence numbers for - * this conversation. (we pick an arbitrary - * collating order so there's only one entry for - * both directions). - */ - if (sport < dport || - (sport == dport && - ip->ip_src.s_addr < ip->ip_dst.s_addr)) { - tha.src = ip->ip_src, tha.dst = ip->ip_dst; - tha.port = sport << 16 | dport; - rev = 0; - } else { - tha.src = ip->ip_dst, tha.dst = ip->ip_src; - tha.port = dport << 16 | sport; - rev = 1; - } - - for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; - th->nxt; th = th->nxt) - if (!memcmp((char *)&tha, (char *)&th->addr, - sizeof(th->addr))) - break; - - if (!th->nxt || flags & TH_SYN) { - /* didn't find it or new conversation */ - if (th->nxt == NULL) { - th->nxt = (struct tcp_seq_hash *) - calloc(1, sizeof(*th)); - if (th->nxt == NULL) - error("tcp_print: calloc"); - } - th->addr = tha; - if (rev) - th->ack = seq, th->seq = ack - 1; - else - th->seq = seq, th->ack = ack - 1; - } else { - if (rev) - seq -= th->ack, ack -= th->seq; - else - seq -= th->seq, ack -= th->ack; - } - } - hlen = tp->th_off * 4; - if (hlen > length) { - (void)printf(" [bad hdr length]"); - return; - } - length -= hlen; - if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST)) - (void)printf(" %u:%u(%d)", seq, seq + length, length); - if (flags & TH_ACK) - (void)printf(" ack %u", ack); - - (void)printf(" win %d", win); - - if (flags & TH_URG) - (void)printf(" urg %d", urp); - /* - * Handle any options. - */ - if ((hlen -= sizeof(*tp)) > 0) { - register const u_char *cp; - register int i, opt, len, datalen; - - cp = (const u_char *)tp + sizeof(*tp); - putchar(' '); - ch = '<'; - while (hlen > 0) { - putchar(ch); - TCHECK(*cp); - opt = *cp++; - if (ZEROLENOPT(opt)) - len = 1; - else { - TCHECK(*cp); - len = *cp++; /* total including type, len */ - if (len < 2 || len > hlen) - goto bad; - --hlen; /* account for length byte */ - } - --hlen; /* account for type byte */ - datalen = 0; - -/* Bail if "l" bytes of data are not left or were not captured */ -#define LENCHECK(l) { if ((l) > hlen) goto bad; TCHECK2(*cp, l); } - - switch (opt) { - - case TCPOPT_MAXSEG: - (void)printf("mss"); - datalen = 2; - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_16BITS(cp)); - - break; - - case TCPOPT_EOL: - (void)printf("eol"); - break; - - case TCPOPT_NOP: - (void)printf("nop"); - break; - - case TCPOPT_WSCALE: - (void)printf("wscale"); - datalen = 1; - LENCHECK(datalen); - (void)printf(" %u", *cp); - break; - - case TCPOPT_SACKOK: - (void)printf("sackOK"); - break; - - case TCPOPT_SACK: - (void)printf("sack"); - datalen = len - 2; - for (i = 0; i < datalen; i += 4) { - LENCHECK(i + 4); - /* block-size@relative-origin */ - (void)printf(" %u@%u", - EXTRACT_16BITS(cp + i + 2), - EXTRACT_16BITS(cp + i)); - } - if (datalen % 4) - (void)printf("[len %d]", len); - break; - - case TCPOPT_ECHO: - (void)printf("echo"); - datalen = 4; - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_32BITS(cp)); - break; - - case TCPOPT_ECHOREPLY: - (void)printf("echoreply"); - datalen = 4; - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_32BITS(cp)); - break; - - case TCPOPT_TIMESTAMP: - (void)printf("timestamp"); - datalen = 8; - LENCHECK(4); - (void)printf(" %u", EXTRACT_32BITS(cp)); - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_32BITS(cp + 4)); - break; - - case TCPOPT_CC: - (void)printf("cc"); - datalen = 4; - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_32BITS(cp)); - break; - - case TCPOPT_CCNEW: - (void)printf("ccnew"); - datalen = 4; - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_32BITS(cp)); - break; - - case TCPOPT_CCECHO: - (void)printf("ccecho"); - datalen = 4; - LENCHECK(datalen); - (void)printf(" %u", EXTRACT_32BITS(cp)); - break; - - default: - (void)printf("opt-%d:", opt); - datalen = len - 2; - for (i = 0; i < datalen; ++i) { - LENCHECK(i); - (void)printf("%02x", cp[i]); - } - break; - } - - /* Account for data printed */ - cp += datalen; - hlen -= datalen; - - /* Check specification against observed length */ - ++datalen; /* option octet */ - if (!ZEROLENOPT(opt)) - ++datalen; /* size octet */ - if (datalen != len) - (void)printf("[len %d]", len); - ch = ','; - if (opt == TCPOPT_EOL) - break; - } - putchar('>'); - } - return; -bad: - fputs("[bad opt]", stdout); - if (ch != '\0') - putchar('>'); - return; -trunc: - fputs("[|tcp]", stdout); - if (ch != '\0') - putchar('>'); -} - diff --git a/tcpdump.tproj/print-tftp.c b/tcpdump.tproj/print-tftp.c deleted file mode 100644 index 9db5775..0000000 --- a/tcpdump.tproj/print-tftp.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1993, 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 trivial file transfer protocol packets. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-tftp.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include - -#include - -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" - -/* op code to string mapping */ -static struct tok op2str[] = { - { RRQ, "RRQ" }, /* read request */ - { WRQ, "WRQ" }, /* write request */ - { DATA, "DATA" }, /* data packet */ - { ACK, "ACK" }, /* acknowledgement */ - { ERROR, "ERROR" }, /* error code */ - { 0, NULL } -}; - -/* error code to string mapping */ -static struct tok err2str[] = { - { EUNDEF, "EUNDEF" }, /* not defined */ - { ENOTFOUND, "ENOTFOUND" }, /* file not found */ - { EACCESS, "EACCESS" }, /* access violation */ - { ENOSPACE, "ENOSPACE" }, /* disk full or allocation exceeded */ - { EBADOP, "EBADOP" }, /* illegal TFTP operation */ - { EBADID, "EBADID" }, /* unknown transfer ID */ - { EEXISTS, "EEXISTS" }, /* file already exists */ - { ENOUSER, "ENOUSER" }, /* no such user */ - { 0, NULL } -}; - -/* - * Print trivial file transfer program requests - */ -void -tftp_print(register const u_char *bp, u_int length) -{ - register const struct tftphdr *tp; - register const char *cp; - register const u_char *p; - register int opcode, i; - static char tstr[] = " [|tftp]"; - - tp = (const struct tftphdr *)bp; - - /* Print length */ - printf(" %d", length); - - /* Print tftp request type */ - TCHECK(tp->th_opcode); - opcode = ntohs(tp->th_opcode); - cp = tok2str(op2str, "tftp-#%d", opcode); - printf(" %s", cp); - /* Bail if bogus opcode */ - if (*cp == 't') - return; - - switch (opcode) { - - case RRQ: - case WRQ: - /* - * XXX Not all arpa/tftp.h's specify th_stuff as any - * array; use address of th_block instead - */ -#ifdef notdef - p = (u_char *)tp->th_stuff; -#else - p = (u_char *)&tp->th_block; -#endif - fputs(" \"", stdout); - i = fn_print(p, snapend); - putchar('"'); - if (i) - goto trunc; - break; - - case ACK: - case DATA: - TCHECK(tp->th_block); - printf(" block %d", ntohs(tp->th_block)); - break; - - case ERROR: - /* Print error code string */ - TCHECK(tp->th_code); - printf(" %s ", tok2str(err2str, "tftp-err-#%d \"", - ntohs(tp->th_code))); - /* Print error message string */ - i = fn_print((const u_char *)tp->th_data, snapend); - putchar('"'); - if (i) - goto trunc; - break; - - default: - /* We shouldn't get here */ - printf("(unknown #%d)", opcode); - break; - } - return; -trunc: - fputs(tstr, stdout); - return; -} diff --git a/tcpdump.tproj/print-udp.c b/tcpdump.tproj/print-udp.c deleted file mode 100644 index f8e4366..0000000 --- a/tcpdump.tproj/print-udp.c +++ /dev/null @@ -1,464 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-udp.c,v 1.1.1.1 1999/05/02 03:58:35 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#undef NOERROR /* Solaris sucks */ -#undef T_UNSPEC /* SINIX does too */ -#include -#include - -#include - -#include - -#include "interface.h" -#include "addrtoname.h" -#include "appletalk.h" - -#include "nfsv2.h" -#include "bootp.h" - -struct rtcphdr { - u_short rh_flags; /* T:2 P:1 CNT:5 PT:8 */ - u_short rh_len; /* length of message (in words) */ - u_int rh_ssrc; /* synchronization src id */ -}; - -typedef struct { - u_int upper; /* more significant 32 bits */ - u_int lower; /* less significant 32 bits */ -} ntp64; - -/* - * Sender report. - */ -struct rtcp_sr { - ntp64 sr_ntp; /* 64-bit ntp timestamp */ - u_int sr_ts; /* reference media timestamp */ - u_int sr_np; /* no. packets sent */ - u_int sr_nb; /* no. bytes sent */ -}; - -/* - * Receiver report. - * Time stamps are middle 32-bits of ntp timestamp. - */ -struct rtcp_rr { - u_int rr_srcid; /* sender being reported */ - u_int rr_nl; /* no. packets lost */ - u_int rr_ls; /* extended last seq number received */ - u_int rr_dv; /* jitter (delay variance) */ - u_int rr_lsr; /* orig. ts from last rr from this src */ - u_int rr_dlsr; /* time from recpt of last rr to xmit time */ -}; - -/*XXX*/ -#define RTCP_PT_SR 200 -#define RTCP_PT_RR 201 -#define RTCP_PT_SDES 202 -#define RTCP_SDES_CNAME 1 -#define RTCP_SDES_NAME 2 -#define RTCP_SDES_EMAIL 3 -#define RTCP_SDES_PHONE 4 -#define RTCP_SDES_LOC 5 -#define RTCP_SDES_TOOL 6 -#define RTCP_SDES_NOTE 7 -#define RTCP_SDES_PRIV 8 -#define RTCP_PT_BYE 203 -#define RTCP_PT_APP 204 - -static void -vat_print(const void *hdr, u_int len, register const struct udphdr *up) -{ - /* vat/vt audio */ - u_int ts = *(u_short *)hdr; - if ((ts & 0xf060) != 0) { - /* probably vt */ - (void)printf(" udp/vt %u %d / %d", - (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up)), - ts & 0x3ff, ts >> 10); - } else { - /* probably vat */ - u_int i0 = ntohl(((u_int *)hdr)[0]); - u_int i1 = ntohl(((u_int *)hdr)[1]); - printf(" udp/vat %u c%d %u%s", - (u_int32_t)(ntohs(up->uh_ulen) - sizeof(*up) - 8), - i0 & 0xffff, - i1, i0 & 0x800000? "*" : ""); - /* audio format */ - if (i0 & 0x1f0000) - printf(" f%d", (i0 >> 16) & 0x1f); - if (i0 & 0x3f000000) - printf(" s%d", (i0 >> 24) & 0x3f); - } -} - -static void -rtp_print(const void *hdr, u_int len, register const struct udphdr *up) -{ - /* rtp v1 or v2 */ - u_int *ip = (u_int *)hdr; - u_int hasopt, hasext, contype, hasmarker; - u_int i0 = ntohl(((u_int *)hdr)[0]); - u_int i1 = ntohl(((u_int *)hdr)[1]); - u_int dlen = ntohs(up->uh_ulen) - sizeof(*up) - 8; - const char * ptype; - - ip += 2; - len >>= 2; - len -= 2; - hasopt = 0; - hasext = 0; - if ((i0 >> 30) == 1) { - /* rtp v1 */ - hasopt = i0 & 0x800000; - contype = (i0 >> 16) & 0x3f; - hasmarker = i0 & 0x400000; - ptype = "rtpv1"; - } else { - /* rtp v2 */ - hasext = i0 & 0x10000000; - contype = (i0 >> 16) & 0x7f; - hasmarker = i0 & 0x800000; - dlen -= 4; - ptype = "rtp"; - ip += 1; - len -= 1; - } - printf(" udp/%s %d c%d %s%s %d %u", - ptype, - dlen, - contype, - (hasopt || hasext)? "+" : "", - hasmarker? "*" : "", - i0 & 0xffff, - i1); - if (vflag) { - printf(" %u", i1); - if (hasopt) { - u_int i2, optlen; - do { - i2 = ip[0]; - optlen = (i2 >> 16) & 0xff; - if (optlen == 0 || optlen > len) { - printf(" !opt"); - return; - } - ip += optlen; - len -= optlen; - } while ((int)i2 >= 0); - } - if (hasext) { - u_int i2, extlen; - i2 = ip[0]; - extlen = (i2 & 0xffff) + 1; - if (extlen > len) { - printf(" !ext"); - return; - } - ip += extlen; - } - if (contype == 0x1f) /*XXX H.261 */ - printf(" 0x%04x", ip[0] >> 16); - } -} - -static const u_char * -rtcp_print(const u_char *hdr, const u_char *ep) -{ - /* rtp v2 control (rtcp) */ - struct rtcp_rr *rr = 0; - struct rtcp_sr *sr; - struct rtcphdr *rh = (struct rtcphdr *)hdr; - u_int len; - u_short flags; - int cnt; - double ts, dts; - if ((u_char *)(rh + 1) > ep) { - printf(" [|rtcp]"); - return (ep); - } - len = (ntohs(rh->rh_len) + 1) * 4; - flags = ntohs(rh->rh_flags); - cnt = (flags >> 8) & 0x1f; - switch (flags & 0xff) { - case RTCP_PT_SR: - sr = (struct rtcp_sr *)(rh + 1); - printf(" sr"); - if (len != cnt * sizeof(*rr) + sizeof(*sr) + sizeof(*rh)) - printf(" [%d]", len); - if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); - if ((u_char *)(sr + 1) > ep) { - printf(" [|rtcp]"); - return (ep); - } - ts = (double)((u_int32_t)ntohl(sr->sr_ntp.upper)) + - ((double)((u_int32_t)ntohl(sr->sr_ntp.lower)) / - 4294967296.0); - printf(" @%.2f %u %up %ub", ts, (u_int32_t)ntohl(sr->sr_ts), - (u_int32_t)ntohl(sr->sr_np), (u_int32_t)ntohl(sr->sr_nb)); - rr = (struct rtcp_rr *)(sr + 1); - break; - case RTCP_PT_RR: - printf(" rr"); - if (len != cnt * sizeof(*rr) + sizeof(*rh)) - printf(" [%d]", len); - rr = (struct rtcp_rr *)(rh + 1); - if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); - break; - case RTCP_PT_SDES: - printf(" sdes %d", len); - if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); - cnt = 0; - break; - case RTCP_PT_BYE: - printf(" bye %d", len); - if (vflag) - printf(" %u", (u_int32_t)ntohl(rh->rh_ssrc)); - cnt = 0; - break; - default: - printf(" type-0x%x %d", flags & 0xff, len); - cnt = 0; - break; - } - if (cnt > 1) - printf(" c%d", cnt); - while (--cnt >= 0) { - if ((u_char *)(rr + 1) > ep) { - printf(" [|rtcp]"); - return (ep); - } - if (vflag) - printf(" %u", (u_int32_t)ntohl(rr->rr_srcid)); - ts = (double)((u_int32_t)ntohl(rr->rr_lsr)) / 65536.; - dts = (double)((u_int32_t)ntohl(rr->rr_dlsr)) / 65536.; - printf(" %ul %us %uj @%.2f+%.2f", - (u_int32_t)ntohl(rr->rr_nl) & 0x00ffffff, - (u_int32_t)ntohl(rr->rr_ls), - (u_int32_t)ntohl(rr->rr_dv), ts, dts); - } - return (hdr + len); -} - -/* XXX probably should use getservbyname() and cache answers */ -#define TFTP_PORT 69 /*XXX*/ -#define KERBEROS_PORT 88 /*XXX*/ -#define SUNRPC_PORT 111 /*XXX*/ -#define SNMP_PORT 161 /*XXX*/ -#define NTP_PORT 123 /*XXX*/ -#define SNMPTRAP_PORT 162 /*XXX*/ -#define RIP_PORT 520 /*XXX*/ -#define KERBEROS_SEC_PORT 750 /*XXX*/ - -void -udp_print(register const u_char *bp, u_int length, register const u_char *bp2) -{ - register const struct udphdr *up; - register const struct ip *ip; - register const u_char *cp; - register const u_char *ep = bp + length; - u_short sport, dport, ulen; - - if (ep > snapend) - ep = snapend; - up = (struct udphdr *)bp; - ip = (struct ip *)bp2; - cp = (u_char *)(up + 1); - if (cp > snapend) { - printf("[|udp]"); - return; - } - if (length < sizeof(struct udphdr)) { - (void)printf(" truncated-udp %d", length); - return; - } - length -= sizeof(struct udphdr); - - sport = ntohs(up->uh_sport); - dport = ntohs(up->uh_dport); - ulen = ntohs(up->uh_ulen); - if (packettype) { - register struct rpc_msg *rp; - enum msg_type direction; - - switch (packettype) { - - case PT_VAT: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); - vat_print((void *)(up + 1), length, up); - break; - - case PT_WB: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); - wb_print((void *)(up + 1), length); - break; - - case PT_RPC: - rp = (struct rpc_msg *)(up + 1); - direction = (enum msg_type)ntohl(rp->rm_direction); - if (direction == CALL) - sunrpcrequest_print((u_char *)rp, length, - (u_char *)ip); - else - nfsreply_print((u_char *)rp, length, - (u_char *)ip); /*XXX*/ - break; - - case PT_RTP: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); - rtp_print((void *)(up + 1), length, up); - break; - - case PT_RTCP: - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), - udpport_string(sport), - ipaddr_string(&ip->ip_dst), - udpport_string(dport)); - while (cp < ep) - cp = rtcp_print(cp, ep); - break; - } - return; - } - - if (!qflag) { - register struct rpc_msg *rp; - enum msg_type direction; - - rp = (struct rpc_msg *)(up + 1); - if (TTEST(rp->rm_direction)) { - direction = (enum msg_type)ntohl(rp->rm_direction); - if (dport == NFS_PORT && direction == CALL) { - nfsreq_print((u_char *)rp, length, - (u_char *)ip); - return; - } - if (sport == NFS_PORT && direction == REPLY) { - nfsreply_print((u_char *)rp, length, - (u_char *)ip); - return; - } -#ifdef notdef - if (dport == SUNRPC_PORT && direction == CALL) { - sunrpcrequest_print((u_char *)rp, length, (u_char *)ip); - return; - } -#endif - } - if (TTEST(((struct LAP *)cp)->type) && - ((struct LAP *)cp)->type == lapDDP && - (atalk_port(sport) || atalk_port(dport))) { - if (vflag) - fputs("kip ", stdout); - atalk_print(cp, length); - return; - } - } - (void)printf("%s.%s > %s.%s:", - ipaddr_string(&ip->ip_src), udpport_string(sport), - ipaddr_string(&ip->ip_dst), udpport_string(dport)); - - if (!qflag) { -#define ISPORT(p) (dport == (p) || sport == (p)) - if (ISPORT(NAMESERVER_PORT)) - ns_print((const u_char *)(up + 1), length); - else if (ISPORT(TFTP_PORT)) - tftp_print((const u_char *)(up + 1), length); - else if (ISPORT(IPPORT_BOOTPC) || ISPORT(IPPORT_BOOTPS)) - bootp_print((const u_char *)(up + 1), length, - sport, dport); - else if (ISPORT(RIP_PORT)) - rip_print((const u_char *)(up + 1), length); - else if (ISPORT(SNMP_PORT) || ISPORT(SNMPTRAP_PORT)) - snmp_print((const u_char *)(up + 1), length); - else if (ISPORT(NTP_PORT)) - ntp_print((const u_char *)(up + 1), length); - else if (ISPORT(KERBEROS_PORT) || ISPORT(KERBEROS_SEC_PORT)) - krb_print((const void *)(up + 1), length); - else if (dport == 3456) - vat_print((const void *)(up + 1), length, up); - /* - * Kludge in test for whiteboard packets. - */ - else if (dport == 4567) - wb_print((const void *)(up + 1), length); - else - (void)printf(" udp %u", - (u_int32_t)(ulen - sizeof(*up))); -#undef ISPORT - } else - (void)printf(" udp %u", (u_int32_t)(ulen - sizeof(*up))); -} diff --git a/tcpdump.tproj/print-wb.c b/tcpdump.tproj/print-wb.c deleted file mode 100644 index 3b0c160..0000000 --- a/tcpdump.tproj/print-wb.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/print-wb.c,v 1.1.1.1 1999/05/02 03:58:35 wsanchez Exp $ (LBL)"; -#endif - -#include -#include - -#include - -#include - -#include "interface.h" -#include "addrtoname.h" - -/* XXX need to add byte-swapping macros! */ - -/* - * Largest packet size. Everything should fit within this space. - * For instance, multiline objects are sent piecewise. - */ -#define MAXFRAMESIZE 1024 - -/* - * Multiple drawing ops can be sent in one packet. Each one starts on a - * an even multiple of DOP_ALIGN bytes, which must be a power of two. - */ -#define DOP_ALIGN 4 -#define DOP_ROUNDUP(x) ((((int)(x)) + (DOP_ALIGN - 1)) & ~(DOP_ALIGN - 1)) -#define DOP_NEXT(d)\ - ((struct dophdr *)((u_char *)(d) + \ - DOP_ROUNDUP(ntohs((d)->dh_len) + sizeof(*(d))))) - -/* - * Format of the whiteboard packet header. - * The transport level header. - */ -struct pkt_hdr { - u_int32_t ph_src; /* site id of source */ - u_int32_t ph_ts; /* time stamp (for skew computation) */ - u_short ph_version; /* version number */ - u_char ph_type; /* message type */ - u_char ph_flags; /* message flags */ -}; - -/* Packet types */ -#define PT_DRAWOP 0 /* drawing operation */ -#define PT_ID 1 /* announcement packet */ -#define PT_RREQ 2 /* repair request */ -#define PT_RREP 3 /* repair reply */ -#define PT_KILL 4 /* terminate participation */ -#define PT_PREQ 5 /* page vector request */ -#define PT_PREP 7 /* page vector reply */ - -/* flags */ -#define PF_USER 0x01 /* hint that packet has interactive data */ -#define PF_VIS 0x02 /* only visible ops wanted */ - -struct PageID { - u_int32_t p_sid; /* session id of initiator */ - u_int32_t p_uid; /* page number */ -}; - -struct dophdr { - u_int32_t dh_ts; /* sender's timestamp */ - u_short dh_len; /* body length */ - u_char dh_flags; - u_char dh_type; /* body type */ - /* body follows */ -}; -/* - * Drawing op sub-types. - */ -#define DT_RECT 2 -#define DT_LINE 3 -#define DT_ML 4 -#define DT_DEL 5 -#define DT_XFORM 6 -#define DT_ELL 7 -#define DT_CHAR 8 -#define DT_STR 9 -#define DT_NOP 10 -#define DT_PSCODE 11 -#define DT_PSCOMP 12 -#define DT_REF 13 -#define DT_SKIP 14 -#define DT_HOLE 15 -#define DT_MAXTYPE 15 - -/* - * A drawing operation. - */ -struct pkt_dop { - struct PageID pd_page; /* page that operations apply to */ - u_int32_t pd_sseq; /* start sequence number */ - u_int32_t pd_eseq; /* end sequence number */ - /* drawing ops follow */ -}; - -/* - * A repair request. - */ -struct pkt_rreq { - u_int32_t pr_id; /* source id of drawops to be repaired */ - struct PageID pr_page; /* page of drawops */ - u_int32_t pr_sseq; /* start seqno */ - u_int32_t pr_eseq; /* end seqno */ -}; - -/* - * A repair reply. - */ -struct pkt_rrep { - u_int32_t pr_id; /* original site id of ops */ - struct pkt_dop pr_dop; - /* drawing ops follow */ -}; - -struct id_off { - u_int32_t id; - u_int32_t off; -}; - -struct pgstate { - u_int32_t slot; - struct PageID page; - u_short nid; - u_short rsvd; - /* seqptr's */ -}; - -/* - * An announcement packet. - */ -struct pkt_id { - u_int32_t pi_mslot; - struct PageID pi_mpage; /* current page */ - struct pgstate pi_ps; - /* seqptr's */ - /* null-terminated site name */ -}; - -struct pkt_preq { - struct PageID pp_page; - u_int32_t pp_low; - u_int32_t pp_high; -}; - -struct pkt_prep { - u_int32_t pp_n; /* size of pageid array */ - /* pgstate's follow */ -}; - -static int -wb_id(const struct pkt_id *id, u_int len) -{ - int i; - const char *cp; - const struct id_off *io; - char c; - int nid; - - printf(" wb-id:"); - len -= sizeof(*id); - if (len < 0 || (u_char *)(id + 1) > snapend) - return (-1); - - printf(" %u/%s:%u (max %u/%s:%u) ", - (u_int32_t)ntohl(id->pi_ps.slot), - ipaddr_string(&id->pi_ps.page.p_sid), - (u_int32_t)ntohl(id->pi_ps.page.p_uid), - (u_int32_t)ntohl(id->pi_mslot), - ipaddr_string(&id->pi_mpage.p_sid), - (u_int32_t)ntohl(id->pi_mpage.p_uid)); - - nid = ntohs(id->pi_ps.nid); - len -= sizeof(*io) * nid; - io = (struct id_off *)(id + 1); - cp = (char *)(io + nid); - if ((u_char *)cp + len <= snapend) { - putchar('"'); - (void)fn_print((u_char *)cp, (u_char *)cp + len); - putchar('"'); - } - - c = '<'; - for (i = 0; i < nid && (u_char *)io < snapend; ++io, ++i) { - printf("%c%s:%u", - c, ipaddr_string(&io->id), (u_int32_t)ntohl(io->off)); - c = ','; - } - if (i >= nid) { - printf(">"); - return (0); - } - return (-1); -} - -static int -wb_rreq(const struct pkt_rreq *rreq, u_int len) -{ - printf(" wb-rreq:"); - if (len < sizeof(*rreq) || (u_char *)(rreq + 1) > snapend) - return (-1); - - printf(" please repair %s %s:%u<%u:%u>", - ipaddr_string(&rreq->pr_id), - ipaddr_string(&rreq->pr_page.p_sid), - (u_int32_t)ntohl(rreq->pr_page.p_uid), - (u_int32_t)ntohl(rreq->pr_sseq), - (u_int32_t)ntohl(rreq->pr_eseq)); - return (0); -} - -static int -wb_preq(const struct pkt_preq *preq, u_int len) -{ - printf(" wb-preq:"); - if (len < sizeof(*preq) || (u_char *)(preq + 1) > snapend) - return (-1); - - printf(" need %u/%s:%u", - (u_int32_t)ntohl(preq->pp_low), - ipaddr_string(&preq->pp_page.p_sid), - (u_int32_t)ntohl(preq->pp_page.p_uid)); - return (0); -} - -static int -wb_prep(const struct pkt_prep *prep, u_int len) -{ - int n; - const struct pgstate *ps; - const u_char *ep = snapend; - - printf(" wb-prep:"); - if (len < sizeof(*prep)) { - return (-1); - } - n = ntohl(prep->pp_n); - ps = (const struct pgstate *)(prep + 1); - while (--n >= 0 && (u_char *)ps < ep) { - const struct id_off *io, *ie; - char c = '<'; - - printf(" %u/%s:%u", - (u_int32_t)ntohl(ps->slot), - ipaddr_string(&ps->page.p_sid), - (u_int32_t)ntohl(ps->page.p_uid)); - io = (struct id_off *)(ps + 1); - for (ie = io + ps->nid; io < ie && (u_char *)io < ep; ++io) { - printf("%c%s:%u", c, ipaddr_string(&io->id), - (u_int32_t)ntohl(io->off)); - c = ','; - } - printf(">"); - ps = (struct pgstate *)io; - } - return ((u_char *)ps <= ep? 0 : -1); -} - - -char *dopstr[] = { - "dop-0!", - "dop-1!", - "RECT", - "LINE", - "ML", - "DEL", - "XFORM", - "ELL", - "CHAR", - "STR", - "NOP", - "PSCODE", - "PSCOMP", - "REF", - "SKIP", - "HOLE", -}; - -static int -wb_dops(const struct dophdr *dh, u_int32_t ss, u_int32_t es) -{ - printf(" <"); - for ( ; ss <= es; ++ss) { - register int t = dh->dh_type; - - if (t > DT_MAXTYPE) - printf(" dop-%d!", t); - else { - printf(" %s", dopstr[t]); - if (t == DT_SKIP || t == DT_HOLE) { - int ts = ntohl(dh->dh_ts); - printf("%d", ts - ss + 1); - if (ss > ts || ts > es) { - printf("[|]"); - if (ts < ss) - return (0); - } - ss = ts; - } - } - dh = DOP_NEXT(dh); - if ((u_char *)dh > snapend) { - printf("[|wb]"); - break; - } - } - printf(" >"); - return (0); -} - -static int -wb_rrep(const struct pkt_rrep *rrep, u_int len) -{ - const struct pkt_dop *dop = &rrep->pr_dop; - - printf(" wb-rrep:"); - len -= sizeof(*rrep); - if (len < 0 || (u_char *)(rrep + 1) > snapend) - return (-1); - - printf(" for %s %s:%u<%u:%u>", - ipaddr_string(&rrep->pr_id), - ipaddr_string(&dop->pd_page.p_sid), - (u_int32_t)ntohl(dop->pd_page.p_uid), - (u_int32_t)ntohl(dop->pd_sseq), - (u_int32_t)ntohl(dop->pd_eseq)); - - if (vflag) - return (wb_dops((const struct dophdr *)(dop + 1), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); - return (0); -} - -static int -wb_drawop(const struct pkt_dop *dop, u_int len) -{ - printf(" wb-dop:"); - len -= sizeof(*dop); - if (len < 0 || (u_char *)(dop + 1) > snapend) - return (-1); - - printf(" %s:%u<%u:%u>", - ipaddr_string(&dop->pd_page.p_sid), - (u_int32_t)ntohl(dop->pd_page.p_uid), - (u_int32_t)ntohl(dop->pd_sseq), - (u_int32_t)ntohl(dop->pd_eseq)); - - if (vflag) - return (wb_dops((const struct dophdr *)(dop + 1), - ntohl(dop->pd_sseq), ntohl(dop->pd_eseq))); - return (0); -} - -/* - * Print whiteboard multicast packets. - */ -void -wb_print(register const void *hdr, register u_int len) -{ - register const struct pkt_hdr *ph; - - ph = (const struct pkt_hdr *)hdr; - len -= sizeof(*ph); - if (len < 0 || (u_char *)(ph + 1) <= snapend) { - if (ph->ph_flags) - printf("*"); - switch (ph->ph_type) { - - case PT_KILL: - printf(" wb-kill"); - return; - - case PT_ID: - if (wb_id((struct pkt_id *)(ph + 1), len) >= 0) - return; - break; - - case PT_RREQ: - if (wb_rreq((struct pkt_rreq *)(ph + 1), len) >= 0) - return; - break; - - case PT_RREP: - if (wb_rrep((struct pkt_rrep *)(ph + 1), len) >= 0) - return; - break; - - case PT_DRAWOP: - if (wb_drawop((struct pkt_dop *)(ph + 1), len) >= 0) - return; - break; - - case PT_PREQ: - if (wb_preq((struct pkt_preq *)(ph + 1), len) >= 0) - return; - break; - - case PT_PREP: - if (wb_prep((struct pkt_prep *)(ph + 1), len) >= 0) - return; - break; - - default: - printf(" wb-%d!", ph->ph_type); - return; - } - } - printf("[|wb]"); -} diff --git a/tcpdump.tproj/strcasecmp.c b/tcpdump.tproj/strcasecmp.c deleted file mode 100644 index edb886a..0000000 --- a/tcpdump.tproj/strcasecmp.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1987 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms are permitted - * provided that this notice is preserved and that due credit is given - * to the University of California at Berkeley. The name of the University - * may not be used to endorse or promote products derived from this - * software without specific written prior permission. This software - * is provided ``as is'' without express or implied warranty. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static const char sccsid[] = "@(#)strcasecmp.c 5.5 (Berkeley) 11/24/87"; -#endif /* LIBC_SCCS and not lint */ - -#include - -#include "interface.h" - -/* - * This array is designed for mapping upper and lower case letter - * together for a case independent comparison. The mappings are - * based upon ascii character sequences. - */ -static u_char charmap[] = { - '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', - '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', - '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', - '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', - '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', - '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', - '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', - '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', - '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', - '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', - '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', - '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', - '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', - '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', - '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', - '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', - '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', - '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', - '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', - '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', - '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', - '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', - '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', - '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', - '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', - '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', - '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', - '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', - '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', - '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', -}; - -__private_extern__ -int -strcasecmp(s1, s2) - const char *s1, *s2; -{ - register u_char *cm = charmap, - *us1 = (u_char *)s1, - *us2 = (u_char *)s2; - - while (cm[*us1] == cm[*us2++]) - if (*us1++ == '\0') - return(0); - return(cm[*us1] - cm[*--us2]); -} - -int -strncasecmp(s1, s2, n) - const char *s1, *s2; - register int n; -{ - register u_char *cm = charmap, - *us1 = (u_char *)s1, - *us2 = (u_char *)s2; - - while (--n >= 0 && cm[*us1] == cm[*us2++]) - if (*us1++ == '\0') - return(0); - return(n < 0 ? 0 : cm[*us1] - cm[*--us2]); -} diff --git a/tcpdump.tproj/tcpdump.c b/tcpdump.tproj/tcpdump.c deleted file mode 100644 index 5ad2561..0000000 --- a/tcpdump.tproj/tcpdump.c +++ /dev/null @@ -1,451 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 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. - */ - -#ifndef lint -static const char copyright[] = - "@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996\n\ -The Regents of the University of California. All rights reserved.\n"; -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/tcpdump.c,v 1.1.1.1 1999/05/02 03:58:35 wsanchez Exp $ (LBL)"; -#endif - -/* - * tcpdump - monitor tcp/ip traffic on an ethernet. - * - * First written in 1987 by Van Jacobson, Lawrence Berkeley Laboratory. - * Mercilessly hacked and occasionally improved since then via the - * combined efforts of Van, Steve McCanne and Craig Leres of LBL. - */ - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include "interface.h" -#include "addrtoname.h" -#include "machdep.h" - -int fflag; /* don't translate "foreign" IP address */ -int nflag; /* leave addresses as numbers */ -int Nflag; /* remove domains from printed host names */ -int pflag; /* don't go promiscuous */ -int qflag; /* quick (shorter) output */ -int tflag = 1; /* print packet arrival time */ -int eflag; /* print ethernet header */ -int vflag; /* verbose */ -int xflag; /* print packet in hex */ -int Oflag = 1; /* run filter code optimizer */ -int Sflag; /* print raw TCP sequence numbers */ -int packettype; - -int dflag; /* print filter code */ - -char *program_name; - -int32_t thiszone; /* seconds offset from gmt to local time */ - -/* Externs */ -extern void bpf_dump(struct bpf_program *, int); - -/* Forwards */ -RETSIGTYPE cleanup(int); -extern __dead void usage(void) __attribute__((volatile)); - -/* Length of saved portion of packet. */ -int snaplen = DEFAULT_SNAPLEN; - -struct printer { - pcap_handler f; - int type; -}; - -/* XXX needed if using old bpf.h */ -#ifndef DLT_ATM_RFC1483 -#define DLT_ATM_RFC1483 11 -#endif - -static struct printer printers[] = { - { ether_if_print, DLT_EN10MB }, - { ether_if_print, DLT_IEEE802 }, - { sl_if_print, DLT_SLIP }, - { ppp_if_print, DLT_PPP }, - { fddi_if_print, DLT_FDDI }, - { null_if_print, DLT_NULL }, - { atm_if_print, DLT_ATM_RFC1483 }, - { NULL, 0 }, -}; - -static pcap_handler -lookup_printer(int type) -{ - struct printer *p; - - for (p = printers; p->f; ++p) - if (type == p->type) - return p->f; - - error("unknown data link type 0x%x", type); - /* NOTREACHED */ -} - -static pcap_t *pd; - -extern int optind; -extern int opterr; -extern char *optarg; - -int -main(int argc, char **argv) -{ - register int cnt, op, i; - bpf_u_int32 localnet, netmask; - register char *cp, *infile, *cmdbuf, *device, *RFileName, *WFileName; - pcap_handler printer; - struct bpf_program fcode; - u_char *pcap_userdata; - char ebuf[PCAP_ERRBUF_SIZE]; - - cnt = -1; - device = NULL; - infile = NULL; - RFileName = NULL; - WFileName = NULL; - if ((cp = strrchr(argv[0], '/')) != NULL) - program_name = cp + 1; - else - program_name = argv[0]; - - if (abort_on_misalignment(ebuf) < 0) - error("%s", ebuf); - - opterr = 0; - while ((op = getopt(argc, argv, "c:defF:i:lnNOpqr:s:StT:vw:xY")) != -1) - switch (op) { - case 'c': - cnt = atoi(optarg); - if (cnt <= 0) - error("invalid packet count %s", optarg); - break; - - case 'd': - ++dflag; - break; - - case 'e': - ++eflag; - break; - - case 'f': - ++fflag; - break; - - case 'F': - infile = optarg; - break; - - case 'i': - device = optarg; - break; - - case 'l': -#ifdef HAVE_SETLINEBUF - setlinebuf(stdout); -#else - setvbuf(stdout, NULL, _IOLBF, 0); -#endif - break; - - case 'n': - ++nflag; - break; - - case 'N': - ++Nflag; - break; - - case 'O': - Oflag = 0; - break; - - case 'p': - ++pflag; - break; - - case 'q': - ++qflag; - break; - - case 'r': - RFileName = optarg; - break; - - case 's': - snaplen = atoi(optarg); - if (snaplen <= 0) - error("invalid snaplen %s", optarg); - break; - - case 'S': - ++Sflag; - break; - - case 't': - --tflag; - break; - - case 'T': - if (strcasecmp(optarg, "vat") == 0) - packettype = PT_VAT; - else if (strcasecmp(optarg, "wb") == 0) - packettype = PT_WB; - else if (strcasecmp(optarg, "rpc") == 0) - packettype = PT_RPC; - else if (strcasecmp(optarg, "rtp") == 0) - packettype = PT_RTP; - else if (strcasecmp(optarg, "rtcp") == 0) - packettype = PT_RTCP; - else - error("unknown packet type `%s'", optarg); - break; - - case 'v': - ++vflag; - break; - - case 'w': - WFileName = optarg; - break; -#ifdef YYDEBUG - case 'Y': - { - /* Undocumented flag */ - extern int yydebug; - yydebug = 1; - } - break; -#endif - case 'x': - ++xflag; - break; - - default: - usage(); - /* NOTREACHED */ - } - - if (tflag > 0) - thiszone = gmt2local(); - - if (RFileName != NULL) { - /* - * We don't need network access, so set it back to the user id. - * Also, this prevents the user from reading anyone's - * trace file. - */ - setuid(getuid()); - - pd = pcap_open_offline(RFileName, ebuf); - if (pd == NULL) - error("%s", ebuf); - localnet = 0; - netmask = 0; - if (fflag != 0) - error("-f and -r options are incompatible"); - } else { - if (device == NULL) { - device = pcap_lookupdev(ebuf); - if (device == NULL) - error("%s", ebuf); - } - pd = pcap_open_live(device, snaplen, !pflag, 1000, ebuf); - if (pd == NULL) - error("%s", ebuf); - i = pcap_snapshot(pd); - if (snaplen < i) { - warning("snaplen raised from %d to %d", snaplen, i); - snaplen = i; - } - if (pcap_lookupnet(device, &localnet, &netmask, ebuf) < 0) - error("%s", ebuf); - /* - * Let user own process after socket has been opened. - */ - setuid(getuid()); - } - if (infile) - cmdbuf = read_infile(infile); - else - cmdbuf = copy_argv(&argv[optind]); - - if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) - error("%s", pcap_geterr(pd)); - if (dflag) { - bpf_dump(&fcode, dflag); - exit(0); - } - init_addrtoname(fflag, localnet, netmask); - - (void)signal(SIGTERM, cleanup); - (void)signal(SIGINT, cleanup); - (void)signal(SIGHUP, cleanup); - - if (pcap_setfilter(pd, &fcode) < 0) - error("%s", pcap_geterr(pd)); - if (WFileName) { - pcap_dumper_t *p = pcap_dump_open(pd, WFileName); - if (p == NULL) - error("%s", pcap_geterr(pd)); - printer = pcap_dump; - pcap_userdata = (u_char *)p; - } else { - printer = lookup_printer(pcap_datalink(pd)); - pcap_userdata = 0; - } - if (RFileName == NULL) { - (void)fprintf(stderr, "%s: listening on %s\n", - program_name, device); - (void)fflush(stderr); - } - if (pcap_loop(pd, cnt, printer, pcap_userdata) < 0) { - (void)fprintf(stderr, "%s: pcap_loop: %s\n", - program_name, pcap_geterr(pd)); - exit(1); - } - pcap_close(pd); - exit(0); -} - -/* make a clean exit on interrupts */ -RETSIGTYPE -cleanup(int signo) -{ - struct pcap_stat stat; - - /* Can't print the summary if reading from a savefile */ - if (pd != NULL && pcap_file(pd) == NULL) { - (void)fflush(stdout); - putc('\n', stderr); - if (pcap_stats(pd, &stat) < 0) - (void)fprintf(stderr, "pcap_stats: %s\n", - pcap_geterr(pd)); - else { - (void)fprintf(stderr, "%d packets received by filter\n", - stat.ps_recv); - (void)fprintf(stderr, "%d packets dropped by kernel\n", - stat.ps_drop); - } - } - exit(0); -} - -/* Like default_print() but data need not be aligned */ -void -default_print_unaligned(register const u_char *cp, register u_int length) -{ - register u_int i, s; - register int nshorts; - - nshorts = (u_int) length / sizeof(u_short); - i = 0; - while (--nshorts >= 0) { - if ((i++ % 8) == 0) - (void)printf("\n\t\t\t"); - s = *cp++; - (void)printf(" %02x%02x", s, *cp++); - } - if (length & 1) { - if ((i % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %02x", *cp); - } -} - -void -default_print(register const u_char *bp, register u_int length) -{ - register const u_short *sp; - register u_int i; - register int nshorts; - - if ((long)bp & 1) { - default_print_unaligned(bp, length); - return; - } - sp = (u_short *)bp; - nshorts = (u_int) length / sizeof(u_short); - i = 0; - while (--nshorts >= 0) { - if ((i++ % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %04x", ntohs(*sp++)); - } - if (length & 1) { - if ((i % 8) == 0) - (void)printf("\n\t\t\t"); - (void)printf(" %02x", *(u_char *)sp); - } -} - -__dead void -usage(void) -{ - extern char version[]; - - (void)fprintf(stderr, "Version %s\n", version); - (void)fprintf(stderr, -"Usage: tcpdump [-deflnNOpqStvx] [-c count] [ -F file ]\n"); - (void)fprintf(stderr, -"\t\t[ -i interface ] [ -r file ] [ -s snaplen ]\n"); - (void)fprintf(stderr, -"\t\t[ -T type ] [ -w file ] [ expression ]\n"); - exit(-1); -} diff --git a/tcpdump.tproj/util.c b/tcpdump.tproj/util.c deleted file mode 100644 index 6df0352..0000000 --- a/tcpdump.tproj/util.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1990, 1991, 1993, 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/util.c,v 1.1.1.1 1999/05/02 03:58:34 wsanchez Exp $ (LBL)"; -#endif - -#include -#include -#include -#include - -#include -#include -#ifdef HAVE_FCNTL_H -#include -#endif -#include -#include -#if __STDC__ -#include -#else -#include -#endif -#include -#include -#ifdef TIME_WITH_SYS_TIME -#include -#endif -#include - -#include "interface.h" - -/* - * Print out a filename (or other ascii string). - * If ep is NULL, assume no truncation check is needed. - * Return true if truncated. - */ -int -fn_print(register const u_char *s, register const u_char *ep) -{ - register int ret; - register u_char c; - - ret = 1; /* assume truncated */ - while (ep == NULL || s < ep) { - c = *s++; - if (c == '\0') { - ret = 0; - break; - } - if (!isascii(c)) { - c = toascii(c); - putchar('M'); - putchar('-'); - } - if (!isprint(c)) { - c ^= 0x40; /* DEL to ?, others to alpha */ - putchar('^'); - } - putchar(c); - } - return(ret); -} - -/* - * Print out a counted filename (or other ascii string). - * If ep is NULL, assume no truncation check is needed. - * Return true if truncated. - */ -int -fn_printn(register const u_char *s, register u_int n, - register const u_char *ep) -{ - register int ret; - register u_char c; - - ret = 1; /* assume truncated */ - while (ep == NULL || s < ep) { - if (n-- <= 0) { - ret = 0; - break; - } - c = *s++; - if (!isascii(c)) { - c = toascii(c); - putchar('M'); - putchar('-'); - } - if (!isprint(c)) { - c ^= 0x40; /* DEL to ?, others to alpha */ - putchar('^'); - } - putchar(c); - } - return(ret); -} - -/* - * Print the timestamp - */ -void -ts_print(register const struct timeval *tvp) -{ - register int s; - - if (tflag > 0) { - /* Default */ - s = (tvp->tv_sec + thiszone) % 86400; - (void)printf("%02d:%02d:%02d.%06u ", - s / 3600, (s % 3600) / 60, s % 60, (u_int32_t)tvp->tv_usec); - } else if (tflag < 0) { - /* Unix timeval style */ - (void)printf("%u.%06u ", - (u_int32_t)tvp->tv_sec, (u_int32_t)tvp->tv_usec); - } -} - -/* - * Convert a token value to a string; use "fmt" if not found. - */ -const char * -tok2str(register const struct tok *lp, register const char *fmt, - register int v) -{ - static char buf[128]; - - while (lp->s != NULL) { - if (lp->v == v) - return (lp->s); - ++lp; - } - if (fmt == NULL) - fmt = "#%d"; - (void)sprintf(buf, fmt, v); - return (buf); -} - - -/* VARARGS */ -__dead void -#if __STDC__ -error(const char *fmt, ...) -#else -error(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ - va_list ap; - - (void)fprintf(stderr, "%s: ", program_name); -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - if (*fmt) { - fmt += strlen(fmt); - if (fmt[-1] != '\n') - (void)fputc('\n', stderr); - } - exit(1); - /* NOTREACHED */ -} - -/* VARARGS */ -void -#if __STDC__ -warning(const char *fmt, ...) -#else -warning(fmt, va_alist) - const char *fmt; - va_dcl -#endif -{ - va_list ap; - - (void)fprintf(stderr, "%s: WARNING: ", program_name); -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - if (*fmt) { - fmt += strlen(fmt); - if (fmt[-1] != '\n') - (void)fputc('\n', stderr); - } -} - -/* - * Copy arg vector into a new buffer, concatenating arguments with spaces. - */ -char * -copy_argv(register char **argv) -{ - register char **p; - register u_int len = 0; - char *buf; - char *src, *dst; - - p = argv; - if (*p == 0) - return 0; - - while (*p) - len += strlen(*p++) + 1; - - buf = (char *)malloc(len); - if (buf == NULL) - error("copy_argv: malloc"); - - p = argv; - dst = buf; - while ((src = *p++) != NULL) { - while ((*dst++ = *src++) != '\0') - ; - dst[-1] = ' '; - } - dst[-1] = '\0'; - - return buf; -} - -/* 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) - error("savestr: malloc"); - } - (void)strcpy(strptr, str); - p = strptr; - strptr += size; - strsize -= size; - return (p); -} - -char * -read_infile(char *fname) -{ - register int fd, cc; - register char *cp; - struct stat buf; - - fd = open(fname, O_RDONLY); - if (fd < 0) - error("can't open %s: %s", fname, pcap_strerror(errno)); - - if (fstat(fd, &buf) < 0) - error("can't stat %s: %s", fname, pcap_strerror(errno)); - - cp = malloc((u_int)buf.st_size + 1); - cc = read(fd, cp, (int)buf.st_size); - if (cc < 0) - error("read %s: %s", fname, pcap_strerror(errno)); - if (cc != buf.st_size) - error("short read %s (%d != %d)", fname, cc, (int)buf.st_size); - cp[(int)buf.st_size] = '\0'; - - return (cp); -} - -/* - * Returns the difference between gmt and local time in seconds. - * Use gmtime() and localtime() to keep things simple. - */ -int32_t -gmt2local(void) -{ - register int dt, dir; - register struct tm *gmt, *loc; - time_t t; - struct tm sgmt; - - 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/tcpdump.tproj/version.c b/tcpdump.tproj/version.c deleted file mode 100644 index 2ee34ff..0000000 --- a/tcpdump.tproj/version.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* $OpenBSD: version.c,v 1.4 1996/07/13 11:01:35 mickey Exp $ */ -/* $NetBSD: version.c,v 1.3 1996/05/20 00:41:20 fvdl Exp $ */ - -char version[] = "3.2.0"; diff --git a/tcpdump.tproj/vfprintf.c b/tcpdump.tproj/vfprintf.c deleted file mode 100644 index 3d5e80c..0000000 --- a/tcpdump.tproj/vfprintf.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright (c) 1995 - * 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. - */ - -#ifndef lint -static const char rcsid[] = - "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/vfprintf.c,v 1.1.1.1 1999/05/02 03:58:35 wsanchez Exp $ (LBL)"; -#endif - -#include - -#include -#if __STDC__ -#include -#else -#include -#endif -#include -#include - -#include "interface.h" - -#if 0 - -/* - * Stock 4.3 doesn't have vfprintf. - * This routine is due to Chris Torek. - */ -vfprintf(f, fmt, args) - FILE *f; - char *fmt; - va_list args; -{ - int ret; - - if ((f->_flag & _IOWRT) == 0) { - if (f->_flag & _IORW) - f->_flag |= _IOWRT; - else - return EOF; - } - ret = _doprnt(fmt, args, f); - return ferror(f) ? EOF : ret; -} -#endif /* 0 */ \ No newline at end of file diff --git a/telnetd.tproj/Makefile b/telnetd.tproj/Makefile index 63a671f..e825ded 100644 --- a/telnetd.tproj/Makefile +++ b/telnetd.tproj/Makefile @@ -14,8 +14,8 @@ PROJECT_TYPE = Tool HFILES = defs.h ext.h pathnames.h telnetd.h -CFILES = authenc.c global.c slc.c state.c sys_term.c telnetd.c\ - termstat.c utility.c +CFILES = global.c slc.c state.c sys_term.c telnetd.c\ + termstat.c utility.c vasprintf.c strlcpy.c OTHERSRCS = Makefile.preamble Makefile Makefile.postamble telnetd.8 diff --git a/telnetd.tproj/authenc.c b/telnetd.tproj/authenc.c deleted file mode 100644 index 7891835..0000000 --- a/telnetd.tproj/authenc.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ -/*- - * Copyright (c) 1991, 1993 - * 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 the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static char sccsid[] = "@(#)authenc.c 8.2 (Berkeley) 5/30/95"; -#endif /* not lint */ - -#if defined(AUTHENTICATION) || defined(ENCRYPTION) -#include "telnetd.h" -#include - - int -net_write(str, len) - unsigned char *str; - int len; -{ - if (nfrontp + len < netobuf + BUFSIZ) { - memmove((void *)nfrontp, (void *)str, len); - nfrontp += len; - return(len); - } - return(0); -} - - void -net_encrypt() -{ -#ifdef ENCRYPTION - char *s = (nclearto > nbackp) ? nclearto : nbackp; - if (s < nfrontp && encrypt_output) { - (*encrypt_output)((unsigned char *)s, nfrontp - s); - } - nclearto = nfrontp; -#endif /* ENCRYPTION */ -} - - int -telnet_spin() -{ - ttloop(); - return(0); -} - - char * -telnet_getenv(val) - char *val; -{ - extern char *getenv(); - return(getenv(val)); -} - - char * -telnet_gets(prompt, result, length, echo) - char *prompt; - char *result; - int length; - int echo; -{ - return((char *)0); -} -#endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */ diff --git a/telnetd.tproj/defs.h b/telnetd.tproj/defs.h index 1224895..a73d4a6 100644 --- a/telnetd.tproj/defs.h +++ b/telnetd.tproj/defs.h @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -138,11 +115,7 @@ # ifdef SYSV_TERMIO # include # else -# ifdef __APPLE__ -# include -# else -# include -# endif +# include # endif #endif #if !defined(USE_TERMIO) || defined(NO_CC_T) diff --git a/telnetd.tproj/ext.h b/telnetd.tproj/ext.h index 18ab636..499f7f8 100644 --- a/telnetd.tproj/ext.h +++ b/telnetd.tproj/ext.h @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -54,6 +31,7 @@ * SUCH DAMAGE. * * @(#)ext.h 8.2 (Berkeley) 12/15/93 + * $FreeBSD: src/libexec/telnetd/ext.h,v 1.9 2001/07/20 15:14:03 ru Exp $ */ /* @@ -98,7 +76,7 @@ extern char ptyobuf[BUFSIZ+NETSLOP], *pfrontp, *pbackp; extern char netibuf[BUFSIZ], *netip; -extern char netobuf[BUFSIZ+NETSLOP], *nfrontp, *nbackp; +extern char netobuf[BUFSIZ], *nfrontp, *nbackp; extern char *neturg; /* one past last bye of urgent data */ extern int pcc, ncc; @@ -109,11 +87,7 @@ extern char *unptyip; /* pointer to remaining characters in buffer */ #endif extern int pty, net; -#ifdef __APPLE__ extern char line[16]; -#else -extern char *line; -#endif /* !NeXT */ extern int SYNCHing; /* we are in TELNET SYNCH mode */ #ifndef P @@ -215,14 +189,11 @@ extern void tty_setsofttab P((int)), tty_tspeed P((int)), willoption P((int)), - wontoption P((int)), - writenet P((unsigned char *, int)); + wontoption P((int)); + +int output_data __P((const char *, ...)); +void output_datalen __P((const char *, int)); -#ifdef ENCRYPTION -extern void (*encrypt_output) P((unsigned char *, int)); -extern int (*decrypt_input) P((int)); -extern char *nclearto; -#endif /* ENCRYPTION */ /* @@ -260,7 +231,7 @@ extern int needtermstat; # ifdef ultrix # define DEFAULT_IM "\r\n\r\nULTRIX (%h) (%t)\r\n\r\r\n\r" # else -# define DEFAULT_IM "\r\n\r\n4.4 BSD (%h) (%t)\r\n\r\r\n\r" +# define DEFAULT_IM "\r\n\r\nFreeBSD (%h) (%t)\r\n\r\r\n\r" # endif # endif # endif diff --git a/telnetd.tproj/global.c b/telnetd.tproj/global.c index ebed4ed..cedf203 100644 --- a/telnetd.tproj/global.c +++ b/telnetd.tproj/global.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,7 +32,11 @@ */ #ifndef lint +#if 0 static char sccsid[] = "@(#)global.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/global.c,v 1.3 1999/08/28 00:10:23 peter Exp $"; #endif /* not lint */ /* diff --git a/telnetd.tproj/pathnames.h b/telnetd.tproj/pathnames.h index c9ac41f..5942f38 100644 --- a/telnetd.tproj/pathnames.h +++ b/telnetd.tproj/pathnames.h @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -54,6 +31,7 @@ * SUCH DAMAGE. * * @(#)pathnames.h 8.1 (Berkeley) 6/4/93 + * $FreeBSD: src/libexec/telnetd/pathnames.h,v 1.6 1999/08/28 00:10:23 peter Exp $ */ #if BSD > 43 @@ -65,7 +43,7 @@ # endif #else - + # define _PATH_TTY "/dev/tty" # ifndef _PATH_LOGIN # define _PATH_LOGIN "/bin/login" diff --git a/telnetd.tproj/slc.c b/telnetd.tproj/slc.c index a7b280d..b7c892a 100644 --- a/telnetd.tproj/slc.c +++ b/telnetd.tproj/slc.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,14 +32,18 @@ */ #ifndef lint -static char sccsid[] = "@(#)slc.c 8.2 (Berkeley) 5/30/95"; +#if 0 +static char sccsid[] = "@(#)slc.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/slc.c,v 1.10 2001/07/20 15:14:03 ru Exp $"; #endif /* not lint */ #include "telnetd.h" #ifdef LINEMODE /* - * local varibles + * local variables */ static unsigned char *def_slcbuf = (unsigned char *)0; static int def_slclen = 0; @@ -195,7 +176,6 @@ end_slc(bufp) register unsigned char **bufp; { register int len; - void netflush(); /* * If a change has occured, store the new terminal control @@ -223,7 +203,7 @@ end_slc(bufp) (void) sprintf((char *)slcptr, "%c%c", IAC, SE); slcptr += 2; len = slcptr - slcbuf; - writenet(slcbuf, len); + output_datalen(slcbuf, len); netflush(); /* force it out immediately */ DIAG(TD_OPTIONS, printsub('>', slcbuf+2, len-2);); } @@ -311,15 +291,15 @@ change_slc(func, flag, val) register int hislevel, mylevel; hislevel = flag & SLC_LEVELBITS; - mylevel = slctab[func].defset.flag & SLC_LEVELBITS; + mylevel = slctab[(int)func].defset.flag & SLC_LEVELBITS; /* * If client is setting a function to NOSUPPORT * or DEFAULT, then we can easily and directly * accomodate the request. */ if (hislevel == SLC_NOSUPPORT) { - slctab[func].current.flag = flag; - slctab[func].current.val = (cc_t)_POSIX_VDISABLE; + slctab[(int)func].current.flag = flag; + slctab[(int)func].current.val = (cc_t)_POSIX_VDISABLE; flag |= SLC_ACK; add_slc(func, flag, val); return; @@ -332,13 +312,13 @@ change_slc(func, flag, val) * default level of DEFAULT. */ if (mylevel == SLC_DEFAULT) { - slctab[func].current.flag = SLC_NOSUPPORT; + slctab[(int)func].current.flag = SLC_NOSUPPORT; } else { - slctab[func].current.flag = slctab[func].defset.flag; + slctab[(int)func].current.flag = slctab[(int)func].defset.flag; } - slctab[func].current.val = slctab[func].defset.val; - add_slc(func, slctab[func].current.flag, - slctab[func].current.val); + slctab[(int)func].current.val = slctab[(int)func].defset.val; + add_slc(func, slctab[(int)func].current.flag, + slctab[(int)func].current.val); return; } @@ -352,13 +332,13 @@ change_slc(func, flag, val) * the place to put the new value, so change it, * otherwise, continue the negotiation. */ - if (slctab[func].sptr) { + if (slctab[(int)func].sptr) { /* * We can change this one. */ - slctab[func].current.val = val; - *(slctab[func].sptr) = val; - slctab[func].current.flag = flag; + slctab[(int)func].current.val = val; + *(slctab[(int)func].sptr) = val; + slctab[(int)func].current.flag = flag; flag |= SLC_ACK; slcchange = 1; add_slc(func, flag, val); @@ -378,22 +358,22 @@ change_slc(func, flag, val) * our value as well. */ if (mylevel == SLC_DEFAULT) { - slctab[func].current.flag = flag; - slctab[func].current.val = val; + slctab[(int)func].current.flag = flag; + slctab[(int)func].current.val = val; flag |= SLC_ACK; } else if (hislevel == SLC_CANTCHANGE && mylevel == SLC_CANTCHANGE) { flag &= ~SLC_LEVELBITS; flag |= SLC_NOSUPPORT; - slctab[func].current.flag = flag; + slctab[(int)func].current.flag = flag; } else { flag &= ~SLC_LEVELBITS; flag |= mylevel; - slctab[func].current.flag = flag; + slctab[(int)func].current.flag = flag; if (mylevel == SLC_CANTCHANGE) { - slctab[func].current.val = - slctab[func].defset.val; - val = slctab[func].current.val; + slctab[(int)func].current.val = + slctab[(int)func].defset.val; + val = slctab[(int)func].current.val; } } add_slc(func, flag, val); diff --git a/telnetd.tproj/state.c b/telnetd.tproj/state.c index 60de854..4785306 100644 --- a/telnetd.tproj/state.c +++ b/telnetd.tproj/state.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,9 +32,14 @@ */ #ifndef lint -static char sccsid[] = "@(#)state.c 8.5 (Berkeley) 5/30/95"; +#if 0 +static const char sccsid[] = "@(#)state.c 8.2 (Berkeley) 12/15/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/state.c,v 1.13 2001/07/20 15:14:03 ru Exp $"; #endif /* not lint */ +#include #include "telnetd.h" #if defined(AUTHENTICATION) #include @@ -117,10 +99,6 @@ telrcv() if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) break; c = *netip++ & 0377, ncc--; -#ifdef ENCRYPTION - if (decrypt_input) - c = (*decrypt_input)(c); -#endif /* ENCRYPTION */ switch (state) { case TS_CR: @@ -149,10 +127,6 @@ telrcv() */ if ((c == '\r') && his_state_is_wont(TELOPT_BINARY)) { int nc = *netip; -#ifdef ENCRYPTION - if (decrypt_input) - nc = (*decrypt_input)(nc & 0xff); -#endif /* ENCRYPTION */ #ifdef LINEMODE /* * If we are operating in linemode, @@ -165,10 +139,6 @@ telrcv() } else #endif { -#ifdef ENCRYPTION - if (decrypt_input) - (void)(*decrypt_input)(-1); -#endif /* ENCRYPTION */ state = TS_CR; } } @@ -221,8 +191,7 @@ gotiac: switch (c) { } netclear(); /* clear buffer back */ - *nfrontp++ = IAC; - *nfrontp++ = DM; + output_data("%c%c", IAC, DM); neturg = nfrontp-1; /* off by one XXX */ DIAG(TD_OPTIONS, printoption("td: send IAC", DM)); @@ -378,7 +347,7 @@ gotiac: switch (c) { continue; default: - syslog(LOG_ERR, "telnetd: panic state=%d\n", state); + syslog(LOG_ERR, "panic state=%d", state); printf("telnetd: panic state=%d\n", state); exit(1); } @@ -475,8 +444,7 @@ send_do(option, init) set_his_want_state_will(option); do_dont_resp[option]++; } - (void) sprintf(nfrontp, (char *)doopt, option); - nfrontp += sizeof (dont) - 2; + output_data((const char *)doopt, option); DIAG(TD_OPTIONS, printoption("td: send do", option)); } @@ -487,9 +455,6 @@ extern void auth_request(); #ifdef LINEMODE extern void doclientstat(); #endif -#ifdef ENCRYPTION -extern void encrypt_send_support(); -#endif /* ENCRYPTION */ void willoption(option) @@ -603,12 +568,6 @@ willoption(option) break; #endif -#ifdef ENCRYPTION - case TELOPT_ENCRYPT: - func = encrypt_send_support; - changeok++; - break; -#endif /* ENCRYPTION */ default: break; @@ -668,11 +627,6 @@ willoption(option) break; #endif -#ifdef ENCRYPTION - case TELOPT_ENCRYPT: - func = encrypt_send_support; - break; -#endif /* ENCRYPTION */ case TELOPT_LFLOW: func = flowstat; break; @@ -695,8 +649,7 @@ send_dont(option, init) set_his_want_state_wont(option); do_dont_resp[option]++; } - (void) sprintf(nfrontp, (char *)dont, option); - nfrontp += sizeof (doopt) - 2; + output_data((const char *)dont, option); DIAG(TD_OPTIONS, printoption("td: send dont", option)); } @@ -739,6 +692,7 @@ wontoption(option) */ if (lmodetype != REAL_LINEMODE) break; + lmodetype = KLUDGE_LINEMODE; # endif /* KLUDGELINEMODE */ clientstat(TELOPT_LINEMODE, WONT, 0); break; @@ -844,8 +798,7 @@ send_will(option, init) set_my_want_state_will(option); will_wont_resp[option]++; } - (void) sprintf(nfrontp, (char *)will, option); - nfrontp += sizeof (doopt) - 2; + output_data((const char *)will, option); DIAG(TD_OPTIONS, printoption("td: send will", option)); } @@ -962,11 +915,6 @@ dooption(option) /* NOT REACHED */ break; -#ifdef ENCRYPTION - case TELOPT_ENCRYPT: - changeok++; - break; -#endif /* ENCRYPTION */ case TELOPT_LINEMODE: case TELOPT_TTYPE: case TELOPT_NAWS: @@ -1003,8 +951,7 @@ send_wont(option, init) set_my_want_state_wont(option); will_wont_resp[option]++; } - (void) sprintf(nfrontp, (char *)wont, option); - nfrontp += sizeof (wont) - 2; + output_data((const char *)wont, option); DIAG(TD_OPTIONS, printoption("td: send wont", option)); } @@ -1216,7 +1163,7 @@ suboption() if (SB_EOF()) break; /* another garbage check */ - if (request == LM_SLC) { /* SLC is not preceeded by WILL or WONT */ + if (request == LM_SLC) { /* SLC is not preceded by WILL or WONT */ /* * Process suboption buffer of slc's */ @@ -1400,9 +1347,8 @@ suboption() env_ovar_wrong: env_ovar = OLD_ENV_VALUE; env_ovalue = OLD_ENV_VAR; - DIAG(TD_OPTIONS, {sprintf(nfrontp, - "ENVIRON VALUE and VAR are reversed!\r\n"); - nfrontp += strlen(nfrontp);}); + DIAG(TD_OPTIONS, + output_data("ENVIRON VALUE and VAR are reversed!\r\n")); } } @@ -1486,49 +1432,6 @@ suboption() } break; #endif -#ifdef ENCRYPTION - case TELOPT_ENCRYPT: - if (SB_EOF()) - break; - switch(SB_GET()) { - case ENCRYPT_SUPPORT: - encrypt_support(subpointer, SB_LEN()); - break; - case ENCRYPT_IS: - encrypt_is(subpointer, SB_LEN()); - break; - case ENCRYPT_REPLY: - encrypt_reply(subpointer, SB_LEN()); - break; - case ENCRYPT_START: - encrypt_start(subpointer, SB_LEN()); - break; - case ENCRYPT_END: - encrypt_end(); - break; - case ENCRYPT_REQSTART: - encrypt_request_start(subpointer, SB_LEN()); - break; - case ENCRYPT_REQEND: - /* - * We can always send an REQEND so that we cannot - * get stuck encrypting. We should only get this - * if we have been able to get in the correct mode - * anyhow. - */ - encrypt_request_end(); - break; - case ENCRYPT_ENC_KEYID: - encrypt_enc_keyid(subpointer, SB_LEN()); - break; - case ENCRYPT_DEC_KEYID: - encrypt_dec_keyid(subpointer, SB_LEN()); - break; - default: - break; - } - break; -#endif /* ENCRYPTION */ default: break; @@ -1543,7 +1446,7 @@ doclientstat() } #define ADD(c) *ncp++ = c -#define ADD_DATA(c) { *ncp++ = c; if (c == SE || c == IAC) *ncp++ = c; } +#define ADD_DATA(c) { *ncp++ = c; if (c == SE) *ncp++ = c; } void send_status() { @@ -1572,10 +1475,14 @@ send_status() if (my_want_state_is_will(i)) { ADD(WILL); ADD_DATA(i); + if (i == IAC) + ADD(IAC); } if (his_want_state_is_will(i)) { ADD(DO); ADD_DATA(i); + if (i == IAC) + ADD(IAC); } } @@ -1598,6 +1505,7 @@ send_status() ADD(LFLOW_RESTART_XON); } ADD(SE); + ADD(SB); } } @@ -1610,6 +1518,8 @@ send_status() ADD(TELOPT_LINEMODE); ADD(LM_MODE); ADD_DATA(editmode); + if (editmode == IAC) + ADD(IAC); ADD(SE); ADD(SB); @@ -1627,9 +1537,55 @@ send_status() ADD(IAC); ADD(SE); - writenet(statusbuf, ncp - statusbuf); + output_datalen(statusbuf, ncp - statusbuf); netflush(); /* Send it on its way */ DIAG(TD_OPTIONS, {printsub('>', statusbuf, ncp - statusbuf); netflush();}); } + +/* + * This function appends data to nfrontp and advances nfrontp. + * Returns the number of characters written altogether (the + * buffer may have been flushed in the process). + */ + +int +output_data(const char *format, ...) +{ + va_list args; + int len; + char *buf; + + va_start(args, format); + if ((len = vasprintf(&buf, format, args)) == -1) + return -1; + output_datalen(buf, len); + va_end(args); + free(buf); + return (len); +} + +void +output_datalen(const char *buf, int len) +{ + int remaining, copied; + + remaining = BUFSIZ - (nfrontp - netobuf); + while (len > 0) { + /* Free up enough space if the room is too low*/ + if ((len > BUFSIZ ? BUFSIZ : len) > remaining) { + netflush(); + remaining = BUFSIZ - (nfrontp - netobuf); + } + + /* Copy out as much as will fit */ + copied = remaining > len ? len : remaining; + memmove(nfrontp, buf, copied); + nfrontp += copied; + len -= copied; + remaining -= copied; + buf += copied; + } + return; +} diff --git a/telnetd.tproj/strlcpy.c b/telnetd.tproj/strlcpy.c new file mode 100644 index 0000000..9b39b41 --- /dev/null +++ b/telnetd.tproj/strlcpy.c @@ -0,0 +1,74 @@ +/* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author 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 ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; +#endif +#endif /* LIBC_SCCS and not lint */ +#ifndef lint +static const char rcsid[] = + "$FreeBSD: src/lib/libc/string/strlcpy.c,v 1.3 2001/05/24 08:47:41 obrien Exp $"; +#endif + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/telnetd.tproj/sys_term.c b/telnetd.tproj/sys_term.c index 61d116e..25b1fe8 100644 --- a/telnetd.tproj/sys_term.c +++ b/telnetd.tproj/sys_term.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,9 +32,14 @@ */ #ifndef lint -static char sccsid[] = "@(#)sys_term.c 8.4 (Berkeley) 5/30/95"; +#if 0 +static const char sccsid[] = "@(#)sys_term.c 8.2 (Berkeley) 12/15/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/sys_term.c,v 1.31 2001/07/09 09:23:42 brian Exp $"; #endif /* not lint */ +#include #include "telnetd.h" #include "pathnames.h" @@ -65,13 +47,14 @@ static char sccsid[] = "@(#)sys_term.c 8.4 (Berkeley) 5/30/95"; #include #endif +extern char *altlogin; + #if defined(CRAY) || defined(__hpux) # define PARENT_DOES_UTMP #endif #ifdef NEWINIT #include -int utmp_len = MAXHOSTNAMELEN; /* sizeof(init_request.host) */ #else /* NEWINIT*/ # ifdef UTMPX # include @@ -81,10 +64,17 @@ struct utmpx wtmp; struct utmp wtmp; # endif /* UTMPX */ -int utmp_len = sizeof(wtmp.ut_host); # ifndef PARENT_DOES_UTMP +#ifdef _PATH_WTMP +char wtmpf[] = _PATH_WTMP; +#else char wtmpf[] = "/usr/adm/wtmp"; -char utmpf[] = "/var/run/utmp"; +#endif +#ifdef _PATH_UTMP +char utmpf[] = _PATH_UTMP; +#else +char utmpf[] = "/etc/utmp"; +#endif # else /* PARENT_DOES_UTMP */ char wtmpf[] = "/etc/wtmp"; # endif /* PARENT_DOES_UTMP */ @@ -92,16 +82,21 @@ char wtmpf[] = "/etc/wtmp"; # ifdef CRAY #include #include -# if (UNICOS_LVL == '7.0') || (UNICOS_LVL == '7.1') -# define UNICOS7x +# if defined(_SC_CRAY_SECURE_SYS) && !defined(SCM_SECURITY) + /* + * UNICOS 6.0/6.1 do not have SCM_SECURITY defined, so we can + * use it to tell us to turn off all the socket security code, + * since that is only used in UNICOS 7.0 and later. + */ +# undef _SC_CRAY_SECURE_SYS # endif -# ifdef UNICOS7x +# if defined(_SC_CRAY_SECURE_SYS) #include #include extern int secflag; extern struct sysv sysv; -# endif /* UNICOS7x */ +# endif /* _SC_CRAY_SECURE_SYS */ # endif /* CRAY */ #endif /* NEWINIT */ @@ -194,6 +189,12 @@ int ttyfd = -1; # endif #endif /* USE_TERMIO */ +#include +#include + +int cleanopen __P((char *)); +void scrub_env __P((void)); + /* * init_termbuf() * copy_termbuf(cp) @@ -245,19 +246,17 @@ set_termbuf() * Only make the necessary changes. */ #ifndef USE_TERMIO - if (memcmp((char *)&termbuf.sg, (char *)&termbuf2.sg, - sizeof(termbuf.sg))) + if (bcmp((char *)&termbuf.sg, (char *)&termbuf2.sg, sizeof(termbuf.sg))) (void) ioctl(pty, TIOCSETN, (char *)&termbuf.sg); - if (memcmp((char *)&termbuf.tc, (char *)&termbuf2.tc, - sizeof(termbuf.tc))) + if (bcmp((char *)&termbuf.tc, (char *)&termbuf2.tc, sizeof(termbuf.tc))) (void) ioctl(pty, TIOCSETC, (char *)&termbuf.tc); - if (memcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc, + if (bcmp((char *)&termbuf.ltc, (char *)&termbuf2.ltc, sizeof(termbuf.ltc))) (void) ioctl(pty, TIOCSLTC, (char *)&termbuf.ltc); if (termbuf.lflags != termbuf2.lflags) (void) ioctl(pty, TIOCLSET, (char *)&termbuf.lflags); #else /* USE_TERMIO */ - if (memcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf))) + if (bcmp((char *)&termbuf, (char *)&termbuf2, sizeof(termbuf))) # ifdef STREAMSPTY (void) tcsetattr(ttyfd, TCSANOW, &termbuf); # else @@ -482,17 +481,13 @@ getnpty() * * Returns the file descriptor of the opened pty. */ -#ifndef __APPLE__ -#ifndef __GNUC__ -char *line = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; -#else -static char Xline[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; -char *line = Xline; -#endif #ifdef CRAY -char *myline = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; +char myline[16]; +#else +/* +char line[16]; +*/ #endif /* CRAY */ -#endif /* !NeXT */ int getpty(ptynum) @@ -520,16 +515,17 @@ int *ptynum; #endif #ifndef __hpux - (void) sprintf(line, "/dev/ptyXX"); + (void) strcpy(line, _PATH_DEV); + (void) strcat(line, "ptyXX"); p1 = &line[8]; p2 = &line[9]; #else - (void) sprintf(line, "/dev/ptym/ptyXX"); + (void) strcpy(line, "/dev/ptym/ptyXX"); p1 = &line[13]; p2 = &line[14]; #endif - for (cp = "pqrstuvwxyzPQRST"; *cp; cp++) { + for (cp = "pqrsPQRS"; *cp; cp++) { struct stat stb; *p1 = *cp; @@ -541,8 +537,8 @@ int *ptynum; */ if (stat(line, &stb) < 0) break; - for (i = 0; i < 16; i++) { - *p2 = "0123456789abcdef"[i]; + for (i = 0; i < 32; i++) { + *p2 = "0123456789abcdefghijklmnopqrstuv"[i]; p = open(line, 2); if (p > 0) { #ifndef __hpux @@ -571,7 +567,7 @@ int *ptynum; struct stat sb; for (*ptynum = lowpty; *ptynum <= highpty; (*ptynum)++) { - (void) sprintf(myline, "/dev/pty/%03d", *ptynum); + (void) sprintf(myline, "%spty/%03d", _PATH_DEV, *ptynum); p = open(myline, 2); if (p < 0) continue; @@ -972,7 +968,6 @@ tty_iscrnl() #endif #ifdef DECODE_BAUD - /* * A table of available terminal speeds */ @@ -980,39 +975,14 @@ struct termspeeds { int speed; int value; } termspeeds[] = { - { 0, B0 }, { 50, B50 }, { 75, B75 }, - { 110, B110 }, { 134, B134 }, { 150, B150 }, - { 200, B200 }, { 300, B300 }, { 600, B600 }, - { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, - { 4800, B4800 }, -#ifdef B7200 - { 7200, B7200 }, -#endif - { 9600, B9600 }, -#ifdef B14400 - { 14400, B14400 }, -#endif -#ifdef B19200 - { 19200, B19200 }, -#endif -#ifdef B28800 - { 28800, B28800 }, -#endif -#ifdef B38400 - { 38400, B38400 }, -#endif -#ifdef B57600 - { 57600, B57600 }, -#endif -#ifdef B115200 - { 115200, B115200 }, -#endif -#ifdef B230400 - { 230400, B230400 }, -#endif - { -1, 0 } + { 0, B0 }, { 50, B50 }, { 75, B75 }, + { 110, B110 }, { 134, B134 }, { 150, B150 }, + { 200, B200 }, { 300, B300 }, { 600, B600 }, + { 1200, B1200 }, { 1800, B1800 }, { 2400, B2400 }, + { 4800, B4800 }, { 9600, B9600 }, { 19200, B9600 }, + { 38400, B9600 }, { -1, B9600 } }; -#endif /* DECODE_BUAD */ +#endif /* DECODE_BAUD */ void tty_tspeed(val) @@ -1023,12 +993,10 @@ tty_tspeed(val) for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++) ; - if (tp->speed == -1) /* back up to last valid value */ - --tp; cfsetospeed(&termbuf, tp->value); -#else /* DECODE_BUAD */ +#else /* DECODE_BAUD */ cfsetospeed(&termbuf, val); -#endif /* DECODE_BUAD */ +#endif /* DECODE_BAUD */ } void @@ -1040,8 +1008,6 @@ tty_rspeed(val) for (tp = termspeeds; (tp->speed != -1) && (val > tp->speed); tp++) ; - if (tp->speed == -1) /* back up to last valid value */ - --tp; cfsetispeed(&termbuf, tp->value); #else /* DECODE_BAUD */ cfsetispeed(&termbuf, val); @@ -1087,13 +1053,13 @@ extern void utmp_sig_notify P((int)); * getptyslave() * * Open the slave side of the pty, and do any initialization - * that is necessary. The return value is a file descriptor - * for the slave side. + * that is necessary. */ - int + void getptyslave() { register int t = -1; + char erase; #if !defined(CRAY) || !defined(NEWINIT) # ifdef LINEMODE @@ -1110,12 +1076,13 @@ getptyslave() * if linemode was turned on * terminal window size * terminal speed + * erase character * so that we can re-set them if we need to. */ # ifdef LINEMODE waslm = tty_linemode(); # endif - + erase = termbuf.c_cc[VERASE]; /* * Make sure that we don't have a controlling tty, and @@ -1161,7 +1128,7 @@ getptyslave() init_termbuf(); # ifdef TIOCGWINSZ if (def_row || def_col) { - memset((char *)&ws, 0, sizeof(ws)); + bzero((char *)&ws, sizeof(ws)); ws.ws_col = def_col; ws.ws_row = def_row; (void)ioctl(t, TIOCSWINSZ, (char *)&ws); @@ -1201,6 +1168,8 @@ getptyslave() # endif /* defined(USE_TERMIO) && !defined(CRAY) && (BSD <= 43) */ tty_rspeed((def_rspeed > 0) ? def_rspeed : 9600); tty_tspeed((def_tspeed > 0) ? def_tspeed : 9600); + if (erase) + termbuf.c_cc[VERASE] = erase; # ifdef LINEMODE if (waslm) tty_setlinemode(1); @@ -1241,9 +1210,9 @@ cleanopen(line) char *line; { register int t; -#ifdef UNICOS7x +#if defined(_SC_CRAY_SECURE_SYS) struct secstat secbuf; -#endif /* UNICOS7x */ +#endif /* _SC_CRAY_SECURE_SYS */ #ifndef STREAMSPTY /* @@ -1257,7 +1226,7 @@ cleanopen(line) # if !defined(CRAY) && (BSD > 43) (void) revoke(line); # endif -#ifdef UNICOS7x +#if defined(_SC_CRAY_SECURE_SYS) if (secflag) { if (secstat(line, &secbuf) < 0) return(-1); @@ -1266,18 +1235,18 @@ cleanopen(line) if (setucmp(secbuf.st_compart) < 0) return(-1); } -#endif /* UNICOS7x */ +#endif /* _SC_CRAY_SECURE_SYS */ t = open(line, O_RDWR|O_NOCTTY); -#ifdef UNICOS7x +#if defined(_SC_CRAY_SECURE_SYS) if (secflag) { if (setulvl(sysv.sy_minlvl) < 0) return(-1); if (setucmp(0) < 0) return(-1); } -#endif /* UNICOS7x */ +#endif /* _SC_CRAY_SECURE_SYS */ if (t < 0) return(-1); @@ -1300,8 +1269,9 @@ cleanopen(line) (void) signal(SIGHUP, SIG_IGN); (void) ioctl(t, TCVHUP, (char *)0); (void) signal(SIGHUP, SIG_DFL); + setpgrp(); -#ifdef UNICOS7x +#if defined(_SC_CRAY_SECURE_SYS) if (secflag) { if (secstat(line, &secbuf) < 0) return(-1); @@ -1310,18 +1280,18 @@ cleanopen(line) if (setucmp(secbuf.st_compart) < 0) return(-1); } -#endif /* UNICOS7x */ +#endif /* _SC_CRAY_SECURE_SYS */ i = open(line, O_RDWR); -#ifdef UNICOS7x +#if defined(_SC_CRAY_SECURE_SYS) if (secflag) { if (setulvl(sysv.sy_minlvl) < 0) return(-1); if (setucmp(0) < 0) return(-1); } -#endif /* UNICOS7x */ +#endif /* _SC_CRAY_SECURE_SYS */ if (i < 0) return(-1); @@ -1359,7 +1329,7 @@ login_tty(t) * the indirect /dev/tty interface. */ close(t); - if ((t = open("/dev/tty", O_RDWR)) < 0) + if ((t = open(_PATH_TTY, O_RDWR)) < 0) fatalperror(net, "open(/dev/tty)"); # endif # else @@ -1370,11 +1340,7 @@ login_tty(t) * setsid() call above may have set our pgrp, so clear * it out before opening the tty... */ -# ifndef SOLARIS (void) setpgrp(0, 0); -# else - (void) setpgrp(); -# endif close(open(line, O_RDWR)); # endif if (t != 0) @@ -1408,8 +1374,6 @@ startslave(host, autologin, autoname) char *autoname; { register int i; - long time(); - char name[256]; #ifdef NEWINIT extern char *ptyip; struct init_request request; @@ -1454,7 +1418,7 @@ startslave(host, autologin, autoname) wtmp.ut_pid = pid; SCPYN(wtmp.ut_user, "LOGIN"); SCPYN(wtmp.ut_host, host); - SCPYN(wtmp.ut_line, line + sizeof("/dev/") - 1); + SCPYN(wtmp.ut_line, line + sizeof(_PATH_DEV) - 1); #ifndef __hpux SCPYN(wtmp.ut_id, wtmp.ut_line+3); #else @@ -1484,7 +1448,7 @@ startslave(host, autologin, autoname) */ if ((i = open(INIT_FIFO, O_WRONLY)) < 0) { char tbuf[128]; - (void) sprintf(tbuf, "Can't open %s\n", INIT_FIFO); + (void) snprintf(tbuf, sizeof(tbuf), "Can't open %s\n", INIT_FIFO); fatalperror(net, tbuf); } memset((char *)&request, 0, sizeof(request)); @@ -1507,7 +1471,7 @@ startslave(host, autologin, autoname) #endif /* BFTPDAEMON */ if (write(i, (char *)&request, sizeof(request)) < 0) { char tbuf[128]; - (void) sprintf(tbuf, "Can't write to %s\n", INIT_FIFO); + (void) snprintf(tbuf, sizeof(tbuf), "Can't write to %s\n", INIT_FIFO); fatalperror(net, tbuf); } (void) close(i); @@ -1519,7 +1483,7 @@ startslave(host, autologin, autoname) if (i == 3 || n >= 0 || !gotalarm) break; gotalarm = 0; - sprintf(tbuf, "telnetd: waiting for /etc/init to start login process on %s\r\n", line); + snprintf(tbuf, sizeof(tbuf), "telnetd: waiting for /etc/init to start login process on %s\r\n", line); (void) write(net, tbuf, strlen(tbuf)); } if (n < 0 && gotalarm) @@ -1542,7 +1506,7 @@ init_env() char **envp; envp = envinit; - if (*envp = getenv("TZ")) + if ((*envp = getenv("TZ"))) *envp++ -= 3; #if defined(CRAY) || defined(__hpux) else @@ -1567,7 +1531,6 @@ start_login(host, autologin, name) int autologin; char *name; { - register char *cp; register char **argv; char **addarg(); extern char *getenv(); @@ -1585,9 +1548,9 @@ start_login(host, autologin, name) * Create utmp entry for child */ - memset(&utmpx, 0, sizeof(utmpx)); + bzero(&utmpx, sizeof(utmpx)); SCPYN(utmpx.ut_user, ".telnet"); - SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1); + SCPYN(utmpx.ut_line, line + sizeof(_PATH_DEV) - 1); utmpx.ut_pid = pid; utmpx.ut_id[0] = 't'; utmpx.ut_id[1] = 'n'; @@ -1595,10 +1558,12 @@ start_login(host, autologin, name) utmpx.ut_id[3] = SC_WILDC; utmpx.ut_type = LOGIN_PROCESS; (void) time(&utmpx.ut_tv.tv_sec); - if (pututxline(&utmpx) == NULL) - fatal(net, "pututxline failed"); + if (makeutx(&utmpx) == NULL) + fatal(net, "makeutx failed"); #endif + scrub_env(); + /* * -h : pass on name of host. * WARNING: -h is accepted by login if and only if @@ -1640,19 +1605,6 @@ start_login(host, autologin, name) #if !defined(NO_LOGIN_P) argv = addarg(argv, "-p"); #endif -#ifdef LINEMODE - /* - * Set the environment variable "LINEMODE" to either - * "real" or "kludge" if we are operating in either - * real or kludge linemode. - */ - if (lmodetype == REAL_LINEMODE) - setenv("LINEMODE", "real", 1); -# ifdef KLUDGELINEMODE - else if (lmodetype == KLUDGE_LINEMODE || lmodetype == KLUDGE_OK) - setenv("LINEMODE", "kludge", 1); -# endif -#endif #ifdef BFTPDAEMON /* * Are we working as the bftp daemon? If so, then ask login @@ -1675,6 +1627,7 @@ start_login(host, autologin, name) if (auth_level >= 0 && autologin == AUTH_VALID) { # if !defined(NO_LOGIN_F) argv = addarg(argv, "-f"); + argv = addarg(argv, "--"); argv = addarg(argv, name); # else # if defined(LOGIN_R) @@ -1725,7 +1678,8 @@ start_login(host, autologin, name) len = strlen(name)+1; write(xpty, name, len); write(xpty, name, len); - sprintf(speed, "%s/%d", (cp = getenv("TERM")) ? cp : "", + snprintf(speed, sizeof(speed), + "%s/%d", (cp = getenv("TERM")) ? cp : "", (def_rspeed > 0) ? def_rspeed : 9600); len = strlen(speed)+1; write(xpty, speed, len); @@ -1747,12 +1701,14 @@ start_login(host, autologin, name) pty = xpty; } # else + argv = addarg(argv, "--"); argv = addarg(argv, name); # endif # endif } else #endif if (getenv("USER")) { + argv = addarg(argv, "--"); argv = addarg(argv, getenv("USER")); #if defined(LOGIN_ARGS) && defined(NO_LOGIN_P) { @@ -1773,31 +1729,19 @@ start_login(host, autologin, name) */ unsetenv("USER"); } -#ifdef SOLARIS - else { - char **p; - - argv = addarg(argv, ""); /* no login name */ - for (p = environ; *p; p++) { - argv = addarg(argv, *p); - } - } -#endif /* SOLARIS */ #if defined(AUTHENTICATION) && defined(NO_LOGIN_F) && defined(LOGIN_R) if (pty > 2) close(pty); #endif closelog(); - /* - * This sleep(1) is in here so that telnetd can - * finish up with the tty. There's a race condition - * the login banner message gets lost... - */ - sleep(1); - execv(_PATH_LOGIN, argv); - syslog(LOG_ERR, "%s: %m\n", _PATH_LOGIN); - fatalperror(net, _PATH_LOGIN); + if (altlogin == NULL) { + altlogin = _PATH_LOGIN; + } + execv(altlogin, argv); + + syslog(LOG_ERR, "%s: %m", altlogin); + fatalperror(net, altlogin); /*NOTREACHED*/ } @@ -1820,14 +1764,14 @@ addarg(argv, val) } for (cpp = argv; *cpp; cpp++) ; - if (cpp == &argv[(int)argv[-1]]) { + if (cpp == &argv[(long)argv[-1]]) { --argv; - *argv = (char *)((int)(*argv) + 10); - argv = (char **)realloc(argv, sizeof(*argv)*((int)(*argv) + 2)); + *argv = (char *)((long)(*argv) + 10); + argv = (char **)realloc(argv, sizeof(*argv) * ((long)(*argv) + 2)); if (argv == NULL) return(NULL); argv++; - cpp = &argv[(int)argv[-1] - 10]; + cpp = &argv[(long)argv[-1] - 10]; } *cpp++ = val; *cpp = 0; @@ -1835,6 +1779,53 @@ addarg(argv, val) } #endif /* NEWINIT */ +/* + * scrub_env() + * + * We only accept the environment variables listed below. + */ + void +scrub_env() +{ + static const char *reject[] = { + "TERMCAP=/", + NULL + }; + + static const char *accept[] = { + "XAUTH=", "XAUTHORITY=", "DISPLAY=", + "TERM=", + "EDITOR=", + "PAGER=", + "LOGNAME=", + "POSIXLY_CORRECT=", + "PRINTER=", + NULL + }; + + char **cpp, **cpp2; + const char **p; + + for (cpp2 = cpp = environ; *cpp; cpp++) { + int reject_it = 0; + + for(p = reject; *p; p++) + if(strncmp(*cpp, *p, strlen(*p)) == 0) { + reject_it = 1; + break; + } + if (reject_it) + continue; + + for(p = accept; *p; p++) + if(strncmp(*cpp, *p, strlen(*p)) == 0) + break; + if(*p != NULL) + *cpp2++ = *cpp; + } + *cpp2 = NULL; +} + /* * cleanup() * @@ -1850,7 +1841,7 @@ cleanup(sig) # if (BSD > 43) || defined(convex) char *p; - p = line + sizeof("/dev/") - 1; + p = line + sizeof(_PATH_DEV) - 1; if (logout(p)) logwtmp(p, "", ""); (void)chmod(line, 0666); @@ -1876,8 +1867,6 @@ cleanup(sig) # ifdef CRAY static int incleanup = 0; register int t; - int child_status; /* status of child process as returned by waitpid */ - int flags = WNOHANG|WUNTRACED; /* * 1: Pick up the zombie, if we are being called @@ -1888,17 +1877,9 @@ cleanup(sig) * 5: Close down the network and pty connections. * 6: Finish up the TMPDIR cleanup, if needed. */ - if (sig == SIGCHLD) { - while (waitpid(-1, &child_status, flags) > 0) + if (sig == SIGCHLD) + while (waitpid(-1, 0, WNOHANG) > 0) ; /* VOID */ - /* Check if the child process was stopped - * rather than exited. We want cleanup only if - * the child has died. - */ - if (WIFSTOPPED(child_status)) { - return; - } - } t = sigblock(sigmask(SIGCHLD)); if (incleanup) { sigsetmask(t); @@ -1906,7 +1887,6 @@ cleanup(sig) } incleanup = 1; sigsetmask(t); -#ifdef UNICOS7x if (secflag) { /* * We need to set ourselves back to a null @@ -1916,7 +1896,6 @@ cleanup(sig) setulvl(sysv.sy_minlvl); setucmp((long)0); } -#endif /* UNICOS7x */ t = cleantmp(&wtmp); setutent(); /* just to make sure */ @@ -2016,28 +1995,6 @@ sigjob(sig) } } -/* - * jid_getutid: - * called by jobend() before calling cleantmp() - * to find the correct $TMPDIR to cleanup. - */ - - struct utmp * -jid_getutid(jid) - int jid; -{ - struct utmp *cur = NULL; - - setutent(); /* just to make sure */ - while (cur = getutent()) { - if ( (cur->ut_type != NULL) && (jid == cur->ut_jid) ) { - return(cur); - } - } - - return(0); -} - /* * Clean up the TMPDIR that login created. * The first time this is called we pick up the info @@ -2069,7 +2026,7 @@ cleantmp(wtp) utp = getutid(wtp); if (utp == 0) { - syslog(LOG_ERR, "Can't get /var/run/utmp entry to clean TMPDIR"); + syslog(LOG_ERR, "can't get /etc/utmp entry to clean TMPDIR"); return(-1); } /* @@ -2094,27 +2051,9 @@ jobend(jid, path, user) register char *user; { static int saved_jid = 0; - static int pty_saved_jid = 0; static char saved_path[sizeof(wtmp.ut_tpath)+1]; static char saved_user[sizeof(wtmp.ut_user)+1]; - /* - * this little piece of code comes into play - * only when ptyreconnect is used to reconnect - * to an previous session. - * - * this is the only time when the - * "saved_jid != jid" code is executed. - */ - - if ( saved_jid && saved_jid != jid ) { - if (!path) { /* called from signal handler */ - pty_saved_jid = jid; - } else { - pty_saved_jid = saved_jid; - } - } - if (path) { strncpy(saved_path, path, sizeof(wtmp.ut_tpath)); strncpy(saved_user, user, sizeof(wtmp.ut_user)); @@ -2125,24 +2064,6 @@ jobend(jid, path, user) saved_jid = jid; return(0); } - - /* if the jid has changed, get the correct entry from the utmp file */ - - if ( saved_jid != jid ) { - struct utmp *utp = NULL; - struct utmp *jid_getutid(); - - utp = jid_getutid(pty_saved_jid); - - if (utp == 0) { - syslog(LOG_ERR, "Can't get /var/run/utmp entry to clean TMPDIR"); - return(-1); - } - - cleantmpdir(jid, utp->ut_tpath, utp->ut_user); - return(1); - } - cleantmpdir(jid, saved_path, saved_user); return(1); } @@ -2157,12 +2078,12 @@ cleantmpdir(jid, tpath, user) { switch(fork()) { case -1: - syslog(LOG_ERR, "TMPDIR cleanup(%s): fork() failed: %m\n", + syslog(LOG_ERR, "TMPDIR cleanup(%s): fork() failed: %m", tpath); break; case 0: - execl(CLEANTMPCMD, CLEANTMPCMD, user, tpath, 0); - syslog(LOG_ERR, "TMPDIR cleanup(%s): execl(%s) failed: %m\n", + execl(CLEANTMPCMD, CLEANTMPCMD, user, tpath, (char *)0); + syslog(LOG_ERR, "TMPDIR cleanup(%s): execl(%s) failed: %m", tpath, CLEANTMPCMD); exit(1); default: @@ -2199,7 +2120,7 @@ rmut() * This updates the utmpx and utmp entries and make a wtmp/x entry */ - SCPYN(utmpx.ut_line, line + sizeof("/dev/") - 1); + SCPYN(utmpx.ut_line, line + sizeof(_PATH_DEV) - 1); utxp = getutxline(&utmpx); if (utxp) { utxp->ut_type = DEAD_PROCESS; @@ -2260,7 +2181,7 @@ rmut() } (void) chmod(line, 0666); (void) chown(line, 0, 0); - line[strlen("/dev/")] = 'p'; + line[strlen(_PATH_DEV)] = 'p'; (void) chmod(line, 0666); (void) chown(line, 0, 0); } /* end of rmut */ diff --git a/telnetd.tproj/telnetd.8 b/telnetd.tproj/telnetd.8 index f618385..90b448a 100644 --- a/telnetd.tproj/telnetd.8 +++ b/telnetd.tproj/telnetd.8 @@ -29,11 +29,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)telnetd.8 8.4 (Berkeley) 6/1/94 +.\" @(#)telnetd.8 8.3 (Berkeley) 3/1/94 +.\" $FreeBSD: src/libexec/telnetd/telnetd.8,v 1.23 2001/07/15 07:53:42 dd Exp $ .\" -.Dd June 1, 1994 +.Dd March 1, 1994 .Dt TELNETD 8 -.Os BSD 4.2 +.Os .Sh NAME .Nm telnetd .Nd DARPA @@ -41,19 +42,20 @@ protocol server .Sh SYNOPSIS .Nm /usr/libexec/telnetd -.Op Fl BUhlkns +.Op Fl Uhlkns .Op Fl D Ar debugmode .Op Fl I Ns Ar initid .Op Fl S Ar tos .Op Fl X Ar authtype .Op Fl a Ar authmode .Op Fl edebug +.Op Fl p Ar loginprog .Op Fl r Ns Ar lowpty-highpty .Op Fl u Ar len .Op Fl debug Op Ar port .Sh DESCRIPTION The -.Nm telnetd +.Nm command is a server which supports the .Tn DARPA standard @@ -71,41 +73,41 @@ file (see The .Fl debug option may be used to start up -.Nm telnetd +.Nm manually, instead of through .Xr inetd 8 . -If started up this way, +If started up this way, .Ar port may be specified to run -.Nm telnetd +.Nm on an alternate .Tn TCP port number. .Pp The -.Nm telnetd +.Nm command accepts the following options: -.Bl -tag -width "-a authmode" +.Bl -tag -width indent .It Fl a Ar authmode This option may be used for specifying what mode should be used for authentication. Note that this option is only useful if -.Nm telnetd +.Nm has been compiled with support for the .Dv AUTHENTICATION option. There are several valid values for -.Ar authmode: +.Ar authmode : .Bl -tag -width debug -.It debug -Turns on authentication debugging code. -.It user +.It Cm debug +Turn on authentication debugging code. +.It Cm user Only allow connections when the remote user can provide valid authentication information to identify the remote user, and is allowed access to the specified account without providing a password. -.It valid +.It Cm valid Only allow connections when the remote user can provide valid authentication information to identify the remote user. @@ -114,14 +116,14 @@ The command will provide any additional user verification needed if the remote user is not allowed automatic access to the specified account. -.It other +.It Cm other Only allow connections that supply some authentication information. This option is currently not supported by any of the existing authentication mechanisms, and is thus the same as specifying .Fl a .Cm valid . -.It none +.It Cm none This is the default state. Authentication information is not required. If no or insufficient authentication information @@ -129,66 +131,60 @@ is provided, then the .Xr login 1 program will provide the necessary user verification. -.It off -This disables the authentication code. +.It Cm off +Disable the authentication code. All user verification will happen through the .Xr login 1 program. .El -.It Fl B -Specifies bftp server mode. In this mode, -.Nm telnetd -causes login to start a -.Xr bftp 1 -session rather than the user's -normal shell. In bftp daemon mode normal -logins are not supported, and it must be used -on a port other than the normal -.Tn TELNET -port. .It Fl D Ar debugmode This option may be used for debugging purposes. This allows -.Nm telnetd +.Nm to print out debugging information to the connection, allowing the user to see what -.Nm telnetd +.Nm is doing. -There are several possible values for -.Ar debugmode: +There are several possible values for +.Ar debugmode : .Bl -tag -width exercise .It Cm options -Prints information about the negotiation of +Print information about the negotiation of .Tn TELNET options. .It Cm report -Prints the +Print the .Cm options information, plus some additional information about what processing is going on. .It Cm netdata -Displays the data stream received by -.Nm telnetd. +Display the data stream received by +.Nm . .It Cm ptydata -Displays data written to the pty. +Display data written to the pty. .It Cm exercise Has not been implemented yet. .El .It Fl debug -Enables debugging on each socket created by -.Nm telnetd +Enable debugging on each socket created by +.Nm (see .Dv SO_DEBUG in .Xr socket 2 ) . .It Fl edebug If -.Nm telnetd +.Nm has been compiled with support for data encryption, then the .Fl edebug option may be used to enable encryption debugging code. +.It Fl p Ar loginprog +Specify an alternate +.Xr login 1 +command to run to complete the login. The alternate command must +understand the same command arguments as the standard login. .It Fl h -Disables the printing of host-specific information before +Disable the printing of host-specific information before login has been completed. .It Fl I Ar initid This option is only applicable to @@ -201,10 +197,10 @@ from to use when init starts login sessions. The default .Dv ID is -.Dv fe. +.Dv fe . .It Fl k This option is only useful if -.Nm telnetd +.Nm has been compiled with both linemode and kludge linemode support. If the .Fl k @@ -212,12 +208,12 @@ option is specified, then if the remote client does not support the .Dv LINEMODE option, then -.Nm telnetd +.Nm will operate in character at a time mode. It will still support kludge linemode, but will only go into kludge linemode if the remote client requests it. -(This is done by by the client sending +(This is done by the client sending .Dv DONT SUPPRESS-GO-AHEAD and .Dv DONT ECHO . ) @@ -228,10 +224,10 @@ that do not support kludge linemode, but pass the heuristic (if they respond with .Dv WILL TIMING-MARK in response to a -.Dv DO TIMING-MARK) +.Dv DO TIMING-MARK ) for kludge linemode support. .It Fl l -Specifies line mode. Tries to force clients to use line- +Specify line mode. Try to force clients to use line- at-a-time mode. If the .Dv LINEMODE @@ -241,7 +237,7 @@ into kludge linemode. Disable .Dv TCP keep-alives. Normally -.Nm telnetd +.Nm enables the .Tn TCP keep-alive mechanism to probe connections that @@ -251,14 +247,14 @@ from machines that have crashed or can no longer be reached may be cleaned up. .It Fl r Ar lowpty-highpty This option is only enabled when -.Nm telnetd +.Nm is compiled for -.Dv UNICOS. +.Dv UNICOS . It specifies an inclusive range of pseudo-terminal devices to use. If the system has sysconf variable .Dv _SC_CRAY_NPTY configured, the default pty search range is 0 to -.Dv _SC_CRAY_NPTY; +.Dv _SC_CRAY_NPTY ; otherwise, the default range is 0 to 128. Either .Ar lowpty or @@ -267,14 +263,14 @@ may be omitted to allow changing either end of the search range. If .Ar lowpty is omitted, the - character is still required so that -.Nm telnetd +.Nm can differentiate .Ar highpty from .Ar lowpty . .It Fl s This option is only enabled if -.Nm telnetd +.Nm is compiled with support for .Tn SecurID cards. @@ -308,10 +304,9 @@ indicates that only dotted decimal addresses should be put into the .Pa utmp file. -.ne 1i .It Fl U This option causes -.Nm telnetd +.Nm to refuse connections from addresses that cannot be mapped back into a symbolic name via the @@ -319,21 +314,21 @@ via the routine. .It Fl X Ar authtype This option is only valid if -.Nm telnetd +.Nm has been built with support for the authentication option. It disables the use of .Ar authtype authentication, and can be used to temporarily disable a specific authentication type without having to recompile -.Nm telnetd . +.Nm . .El .Pp .Nm Telnetd operates by allocating a pseudo-terminal device (see .Xr pty 4 ) for a client, then creating a login process which has -the slave side of the pseudo-terminal as +the slave side of the pseudo-terminal as .Dv stdin , .Dv stdout and @@ -347,8 +342,8 @@ between the remote client and the login process. .Pp When a .Tn TELNET -session is started up, -.Nm telnetd +session is started up, +.Nm sends .Tn TELNET options to the client side indicating @@ -374,7 +369,9 @@ DO TIMING-MARK .Ed .Pp The pseudo-terminal allocated to the client is configured -to operate in \*(lqcooked\*(rq mode, and with +to operate in +.Dq cooked +mode, and with .Dv XTABS and .Dv CRMOD enabled (see @@ -397,25 +394,25 @@ current state of terminal echoing. When terminal echo is not desired, a .Dv WILL ECHO is sent to indicate that -.Tn telnetd +.Nm will take care of echoing any data that needs to be echoed to the terminal, and then nothing is echoed. When terminal echo is desired, a .Dv WONT ECHO is sent to indicate that -.Tn telnetd +.Nm will not be doing any terminal echoing, so the client should do any terminal echoing that is needed. .It "WILL BINARY" -Indicates that the client is willing to send a +Indicate that the client is willing to send a 8 bits of data, rather than the normal 7 bits of the Network Virtual Terminal. .It "WILL SGA" -Indicates that it will not be sending -.Dv IAC GA, +Indicate that it will not be sending +.Dv IAC GA , go ahead, commands. .It "WILL STATUS" -Indicates a willingness to send the client, upon +Indicate a willingness to send the client, upon request, of the current status of all .Tn TELNET options. @@ -424,8 +421,7 @@ Whenever a .Dv DO TIMING-MARK command is received, it is always responded to with a -.Dv WILL TIMING-MARK -.ne 1i +.Dv WILL TIMING-MARK . .It "WILL LOGOUT" When a .Dv DO LOGOUT @@ -436,7 +432,7 @@ is sent in response, and the session is shut down. .It "WILL ENCRYPT" Only sent if -.Nm telnetd +.Nm is compiled with support for data encryption, and indicates a willingness to decrypt the data stream. @@ -449,7 +445,7 @@ options: .Bl -tag -width "DO AUTHENTICATION" .It "DO BINARY" Sent to indicate that -.Tn telnetd +.Nm is willing to receive an 8 bit data stream. .It "DO LFLOW" Requests that the client handle flow control @@ -458,50 +454,50 @@ characters remotely. This is not really supported, but is sent to identify a 4.2BSD .Xr telnet 1 client, which will improperly respond with -.Dv WILL ECHO. +.Dv WILL ECHO . If a .Dv WILL ECHO is received, a .Dv DONT ECHO will be sent in response. .It "DO TERMINAL-TYPE" -Indicates a desire to be able to request the +Indicate a desire to be able to request the name of the type of terminal that is attached to the client side of the connection. .It "DO SGA" -Indicates that it does not need to receive -.Dv IAC GA, +Indicate that it does not need to receive +.Dv IAC GA , the go ahead command. .It "DO NAWS" Requests that the client inform the server when the window (display) size changes. .It "DO TERMINAL-SPEED" -Indicates a desire to be able to request information +Indicate a desire to be able to request information about the speed of the serial line to which the client is attached. .It "DO XDISPLOC" -Indicates a desire to be able to request the name -of the X windows display that is associated with +Indicate a desire to be able to request the name +of the X Window System display that is associated with the telnet client. .It "DO NEW-ENVIRON" -Indicates a desire to be able to request environment +Indicate a desire to be able to request environment variable information, as described in RFC 1572. .It "DO ENVIRON" -Indicates a desire to be able to request environment +Indicate a desire to be able to request environment variable information, as described in RFC 1408. .It "DO LINEMODE" Only sent if -.Nm telnetd +.Nm is compiled with support for linemode, and requests that the client do line by line processing. .It "DO TIMING-MARK" Only sent if -.Nm telnetd +.Nm is compiled with support for both linemode and kludge linemode, and the client responded with -.Dv WONT LINEMODE. +.Dv WONT LINEMODE . If the client responds with -.Dv WILL TM, +.Dv WILL TM , the it is assumed that the client supports kludge linemode. Note that the @@ -509,32 +505,57 @@ Note that the option can be used to disable this. .It "DO AUTHENTICATION" Only sent if -.Nm telnetd +.Nm is compiled with support for authentication, and indicates a willingness to receive authentication information for automatic login. .It "DO ENCRYPT" Only sent if -.Nm telnetd +.Nm is compiled with support for data encryption, and indicates a willingness to decrypt the data stream. -.Sh ENVIRONMENT +.El +.Sh NOTES +By default +.Nm +will read the +.Em \&he , +.Em \&hn , +and +.Em \&im +capabilities from +.Pa /etc/gettytab +and use that information (if present) to determine +what to display before the login: prompt. You can +also use a System V style +.Pa /etc/issue +file by using the +.Em \&if +capability, which will override +.Em \&im . +The information specified in either +.Em \&im +or +.Em \&if +will be displayed to both console and remote logins. +.\" .Sh ENVIRONMENT .Sh FILES -.Pa /etc/services -.br -.Pa /etc/inittab +.Bl -tag -width /usr/ucb/bftp -compact +.It Pa /etc/services +.It Pa /etc/gettytab +.It Pa /etc/inittab (UNICOS systems only) -.br -.Pa /etc/iptos +.It Pa /etc/iptos (if supported) -.br -.Pa /usr/ucb/bftp +.It Pa /usr/ucb/bftp (if supported) +.El .Sh "SEE ALSO" -.Xr telnet 1 , +.Xr bftp 1 , .Xr login 1 , -.Xr bftp 1 +.Xr gettytab 5 , +.Xr telnet 1 (if supported) .Sh STANDARDS .Bl -tag -compact -width RFC-1572 @@ -581,6 +602,7 @@ Telnet Authentication: SPX Telnet Environment Option Interoperability Issues .It Cm RFC-1572 Telnet Environment Option +.El .Sh BUGS Some .Tn TELNET @@ -588,7 +610,7 @@ commands are only partially implemented. .Pp Because of bugs in the original 4.2 BSD .Xr telnet 1 , -.Nm telnetd +.Nm performs some dubious protocol exchanges to try to discover if the remote client is, in fact, a 4.2 BSD .Xr telnet 1 . @@ -605,3 +627,5 @@ never sends .Tn TELNET .Dv IAC GA (go ahead) commands. +.Sh HISTORY +IPv6 support was added by WIDE/KAME project. diff --git a/telnetd.tproj/telnetd.c b/telnetd.tproj/telnetd.c index 01943a4..6f7777f 100644 --- a/telnetd.tproj/telnetd.c +++ b/telnetd.tproj/telnetd.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; +#if 0 +static char sccsid[] = "@(#)telnetd.c 8.2 (Berkeley) 12/15/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/telnetd.c,v 1.28 2001/07/20 15:14:03 ru Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -76,6 +57,14 @@ static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; # undef _SC_CRAY_SECURE_SYS #endif +#include +#include +#include +#include +#include +#include +#include + #if defined(_SC_CRAY_SECURE_SYS) #include #include @@ -83,6 +72,12 @@ static char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95"; #include #include # endif /* SO_SEC_MULTI */ + +/* wrapper for KAME-special getnameinfo() */ +#ifndef NI_WITHSCOPEID +#define NI_WITHSCOPEID 0 +#endif + int secflag; char tty_dev[16]; struct secdev dv; @@ -102,7 +97,8 @@ int auth_level = 0; int require_SecurID = 0; #endif -extern int utmp_len; +char remote_hostname[MAXHOSTNAMELEN]; +int utmp_len = sizeof(remote_hostname) - 1; int registerd_host_only = 0; #ifdef STREAMSPTY @@ -114,7 +110,7 @@ int registerd_host_only = 0; /* * Because of the way ptyibuf is used with streams messages, we need - * ptyibuf+1 to be on a full-word boundary. The following wierdness + * ptyibuf+1 to be on a full-word boundary. The following weirdness * is simply to make that happen. */ long ptyibufbuf[BUFSIZ/sizeof(long)+1]; @@ -146,13 +142,12 @@ int lowpty = 0, highpty; /* low, high pty numbers */ int debug = 0; int keepalive = 1; -char *progname; +char *altlogin; +void doit __P((struct sockaddr *)); +int terminaltypeok __P((char *)); +void startslave __P((char *, int, char *)); extern void usage P((void)); -void doit(struct sockaddr_in *); -int terminaltypeok(char *); -void startslave(char *, int, char *); - /* * The string to pass to getopt(). We do it this way so @@ -160,7 +155,8 @@ void startslave(char *, int, char *); * passed off to getopt(). */ char valid_opts[] = { - 'd', ':', 'h', 'k', 'n', 'S', ':', 'u', ':', 'U', + 'd', ':', 'h', 'k', 'n', 'p', ':', 'S', ':', 'u', ':', 'U', + '4', '6', #ifdef AUTHENTICATION 'a', ':', 'X', ':', #endif @@ -170,9 +166,6 @@ char valid_opts[] = { #ifdef DIAGNOSTICS 'D', ':', #endif -#ifdef ENCRYPTION - 'e', ':', -#endif #if defined(CRAY) && defined(NEWINIT) 'I', ':', #endif @@ -188,15 +181,15 @@ char valid_opts[] = { '\0' }; +int family = AF_INET; + int main(argc, argv) char *argv[]; { - struct sockaddr_in from; + struct sockaddr_storage from; int on = 1, fromlen; register int ch; - extern char *optarg; - extern int optind; #if defined(IPPROTO_IP) && defined(IP_TOS) int tos = -1; #endif @@ -204,11 +197,22 @@ main(argc, argv) pfrontp = pbackp = ptyobuf; netip = netibuf; nfrontp = nbackp = netobuf; -#ifdef ENCRYPTION - nclearto = 0; -#endif /* ENCRYPTION */ - progname = *argv; + /* + * This initialization causes linemode to default to a configuration + * that works on all telnet clients, including the FreeBSD client. + * This is not quite the same as the telnet client issuing a "mode + * character" command, but has most of the same benefits, and is + * preferable since some clients (like usofts) don't have the + * mode character command anyway and linemode breaks things. + * The most notable symptom of fix is that csh "set filec" operations + * like (filename completion) and ^D (choices) keys now work + * in telnet sessions and can be used more than once on the same line. + * CR/LF handling is also corrected in some termio modes. This + * change resolves problem reports bin/771 and bin/1037. + */ + + linemode=1; /*Default to mode that works on bulk of clients*/ #ifdef CRAY /* @@ -218,7 +222,7 @@ main(argc, argv) highpty = getnpty(); #endif /* CRAY */ - while ((ch = getopt(argc, argv, valid_opts)) != EOF) { + while ((ch = getopt(argc, argv, valid_opts)) != -1) { switch(ch) { #ifdef AUTHENTICATION @@ -243,8 +247,7 @@ main(argc, argv) */ auth_level = -1; } else { - fprintf(stderr, - "telnetd: unknown authorization level for -a\n"); + warnx("unknown authorization level for -a"); } break; #endif /* AUTHENTICATION */ @@ -286,17 +289,6 @@ main(argc, argv) break; #endif /* DIAGNOSTICS */ -#ifdef ENCRYPTION - case 'e': - if (strcmp(optarg, "debug") == 0) { - extern int encrypt_debug_mode; - encrypt_debug_mode = 1; - break; - } - usage(); - /* NOTREACHED */ - break; -#endif /* ENCRYPTION */ case 'h': hostinfo = 0; @@ -329,6 +321,10 @@ main(argc, argv) keepalive = 0; break; + case 'p': + altlogin = optarg; + break; + #ifdef CRAY case 'r': { @@ -366,17 +362,20 @@ main(argc, argv) case 'S': #ifdef HAS_GETTOS if ((tos = parsetos(optarg, "tcp")) < 0) - fprintf(stderr, "%s%s%s\n", - "telnetd: Bad TOS argument '", optarg, + warnx("%s%s%s", + "bad TOS argument '", optarg, "'; will try to use default TOS"); #else - fprintf(stderr, "%s%s\n", "TOS option unavailable; ", - "-S flag not supported\n"); + warnx("TOS option unavailable; -S flag not supported"); #endif break; case 'u': utmp_len = atoi(optarg); + if (utmp_len < 0) + utmp_len = -utmp_len; + if (utmp_len >= sizeof(remote_hostname)) + utmp_len = sizeof(remote_hostname) - 1; break; case 'U': @@ -392,8 +391,18 @@ main(argc, argv) break; #endif /* AUTHENTICATION */ + case '4': + family = AF_INET; + break; + +#ifdef INET6 + case '6': + family = AF_INET6; + break; +#endif + default: - fprintf(stderr, "telnetd: %c: unknown option\n", ch); + warnx("%c: unknown option", ch); /* FALLTHROUGH */ case '?': usage(); @@ -405,55 +414,43 @@ main(argc, argv) argv += optind; if (debug) { - int s, ns, foo; - struct servent *sp; - static struct sockaddr_in sin = { AF_INET }; + int s, ns, foo, error; + char *service = "telnet"; + struct addrinfo hints, *res; if (argc > 1) { usage(); /* NOT REACHED */ - } else if (argc == 1) { - if (sp = getservbyname(*argv, "tcp")) { - sin.sin_port = sp->s_port; - } else { - sin.sin_port = atoi(*argv); - if ((int)sin.sin_port <= 0) { - fprintf(stderr, "telnetd: %s: bad port #\n", *argv); - usage(); - /* NOT REACHED */ - } - sin.sin_port = htons((u_short)sin.sin_port); - } - } else { - sp = getservbyname("telnet", "tcp"); - if (sp == 0) { - fprintf(stderr, "telnetd: tcp/telnet: unknown service\n"); - exit(1); - } - sin.sin_port = sp->s_port; + } else if (argc == 1) + service = *argv; + + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = family; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = 0; + error = getaddrinfo(NULL, service, &hints, &res); + + if (error) { + errx(1, "tcp/%s: %s\n", service, gai_strerror(error)); + if (error == EAI_SYSTEM) + errx(1, "tcp/%s: %s\n", service, strerror(errno)); + usage(); } - s = socket(AF_INET, SOCK_STREAM, 0); - if (s < 0) { - perror("telnetd: socket");; - exit(1); - } + s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (s < 0) + err(1, "socket"); (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); - if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) { - perror("bind"); - exit(1); - } - if (listen(s, 1) < 0) { - perror("listen"); - exit(1); - } - foo = sizeof sin; - ns = accept(s, (struct sockaddr *)&sin, &foo); - if (ns < 0) { - perror("accept"); - exit(1); - } + if (bind(s, res->ai_addr, res->ai_addrlen) < 0) + err(1, "bind"); + if (listen(s, 1) < 0) + err(1, "listen"); + foo = res->ai_addrlen; + ns = accept(s, res->ai_addr, &foo); + if (ns < 0) + err(1, "accept"); (void) dup2(ns, 0); (void) close(ns); (void) close(s); @@ -479,12 +476,10 @@ main(argc, argv) int szi = sizeof(int); #endif /* SO_SEC_MULTI */ - memset((char *)&dv, 0, sizeof(dv)); + bzero((char *)&dv, sizeof(dv)); - if (getsysv(&sysv, sizeof(struct sysv)) != 0) { - perror("getsysv"); - exit(1); - } + if (getsysv(&sysv, sizeof(struct sysv)) != 0) + err(1, "getsysv"); /* * Get socket security label and set device values @@ -495,8 +490,7 @@ main(argc, argv) (char *)&ss, &szss) < 0) || (getsockopt(0, SOL_SOCKET, SO_SEC_MULTI, (char *)&sock_multi, &szi) < 0)) { - perror("getsockopt"); - exit(1); + err(1, "getsockopt"); } else { dv.dv_actlvl = ss.ss_actlabel.lt_level; dv.dv_actcmp = ss.ss_actlabel.lt_compart; @@ -526,8 +520,7 @@ main(argc, argv) openlog("telnetd", LOG_PID | LOG_ODELAY, LOG_DAEMON); fromlen = sizeof (from); if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) { - fprintf(stderr, "%s: ", progname); - perror("getpeername"); + warn("getpeername"); _exit(1); } if (keepalive && @@ -537,7 +530,7 @@ main(argc, argv) } #if defined(IPPROTO_IP) && defined(IP_TOS) - { + if (from.ss_family == AF_INET) { # if defined(HAS_GETTOS) struct tosent *tp; if (tos < 0 && (tp = gettosbyname("telnet", "tcp"))) @@ -553,15 +546,15 @@ main(argc, argv) } #endif /* defined(IPPROTO_IP) && defined(IP_TOS) */ net = 0; - doit(&from); + doit((struct sockaddr *)&from); /* NOTREACHED */ - exit(0); + return(0); } /* end of main */ void usage() { - fprintf(stderr, "Usage: telnetd"); + fprintf(stderr, "usage: telnetd"); #ifdef AUTHENTICATION fprintf(stderr, " [-a (debug|other|user|valid|off|none)]\n\t"); #endif @@ -634,18 +627,12 @@ getterminaltype(name) } #endif -#ifdef ENCRYPTION - send_will(TELOPT_ENCRYPT, 1); -#endif /* ENCRYPTION */ send_do(TELOPT_TTYPE, 1); send_do(TELOPT_TSPEED, 1); send_do(TELOPT_XDISPLOC, 1); send_do(TELOPT_NEW_ENVIRON, 1); send_do(TELOPT_OLD_ENVIRON, 1); while ( -#ifdef ENCRYPTION - his_do_dont_is_changing(TELOPT_ENCRYPT) || -#endif /* ENCRYPTION */ his_will_wont_is_changing(TELOPT_TTYPE) || his_will_wont_is_changing(TELOPT_TSPEED) || his_will_wont_is_changing(TELOPT_XDISPLOC) || @@ -653,53 +640,33 @@ getterminaltype(name) his_will_wont_is_changing(TELOPT_OLD_ENVIRON)) { ttloop(); } -#ifdef ENCRYPTION - /* - * Wait for the negotiation of what type of encryption we can - * send with. If autoencrypt is not set, this will just return. - */ - if (his_state_is_will(TELOPT_ENCRYPT)) { - encrypt_wait(); - } -#endif /* ENCRYPTION */ if (his_state_is_will(TELOPT_TSPEED)) { static unsigned char sb[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; - memmove(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; - DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); + output_datalen(sb, sizeof sb); } if (his_state_is_will(TELOPT_XDISPLOC)) { static unsigned char sb[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; - memmove(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; - DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); + output_datalen(sb, sizeof sb); } if (his_state_is_will(TELOPT_NEW_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE }; - memmove(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; - DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); + output_datalen(sb, sizeof sb); } else if (his_state_is_will(TELOPT_OLD_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE }; - memmove(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; - DIAG(TD_OPTIONS, printsub('>', sb + 2, sizeof sb - 2);); + output_datalen(sb, sizeof sb); } if (his_state_is_will(TELOPT_TTYPE)) { - memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); - nfrontp += sizeof ttytype_sbbuf; - DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2, - sizeof ttytype_sbbuf - 2);); + output_datalen(ttytype_sbbuf, sizeof ttytype_sbbuf); } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) @@ -728,12 +695,14 @@ getterminaltype(name) * we have to just go with what we (might) have already gotten. */ if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) { - (void) strncpy(first, terminaltype, sizeof(first)); + (void) strncpy(first, terminaltype, sizeof(first)-1); + first[sizeof(first)-1] = '\0'; for(;;) { /* * Save the unknown name, and request the next name. */ - (void) strncpy(last, terminaltype, sizeof(last)); + (void) strncpy(last, terminaltype, sizeof(last)-1); + last[sizeof(last)-1] = '\0'; _gettermname(); if (terminaltypeok(terminaltype)) break; @@ -751,8 +720,10 @@ getterminaltype(name) * the start of the list. */ _gettermname(); - if (strncmp(first, terminaltype, sizeof(first)) != 0) - (void) strncpy(terminaltype, first, sizeof(first)); + if (strncmp(first, terminaltype, sizeof(first)) != 0) { + (void) strncpy(terminaltype, first, sizeof(terminaltype)-1); + terminaltype[sizeof(terminaltype)-1] = '\0'; + } break; } } @@ -772,10 +743,7 @@ _gettermname() if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); - memmove(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); - nfrontp += sizeof ttytype_sbbuf; - DIAG(TD_OPTIONS, printsub('>', ttytype_sbbuf + 2, - sizeof ttytype_sbbuf - 2);); + output_datalen(ttytype_sbbuf, sizeof ttytype_sbbuf); while (sequenceIs(ttypesubopt, baseline)) ttloop(); } @@ -802,31 +770,27 @@ terminaltypeok(s) } #ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 64 +#define MAXHOSTNAMELEN 256 #endif /* MAXHOSTNAMELEN */ char *hostname; char host_name[MAXHOSTNAMELEN]; -char remote_host_name[MAXHOSTNAMELEN]; -#ifndef convex -extern void telnet P((int, int)); -#else extern void telnet P((int, int, char *)); -#endif +int level; +char user_name[256]; /* * Get a pty, scan input lines. */ -void + void doit(who) - struct sockaddr_in *who; + struct sockaddr *who; { - char *host = NULL, *inet_ntoa(); + char *host = NULL; + int err; struct hostent *hp; - int level; int ptynum; - char user_name[256]; /* * Find an available pty to use. @@ -838,14 +802,12 @@ doit(who) #else for (;;) { char *lp; - extern char *line, *getpty(); if ((lp = getpty()) == NULL) fatal(net, "Out of ptys"); - if ((pty = open(lp, O_RDWR)) >= 0) { - strncpy(line,lp, sizeof(line)-1); - line[sizeof(line)-1] = '\0'; + if ((pty = open(lp, 2)) >= 0) { + strlcpy(line,lp,sizeof(line)); line[5] = 't'; break; } @@ -859,42 +821,43 @@ doit(who) if (secflag) { char slave_dev[16]; - sprintf(tty_dev, "/dev/pty/%03d", ptynum); + sprintf(tty_dev, "%spty/%03d", _PATH_DEV, ptynum); if (setdevs(tty_dev, &dv) < 0) fatal(net, "cannot set pty security"); - sprintf(slave_dev, "/dev/ttyp%03d", ptynum); + sprintf(slave_dev, "%sp%03d", _PATH_TTY, ptynum); if (setdevs(slave_dev, &dv) < 0) fatal(net, "cannot set tty security"); } #endif /* _SC_CRAY_SECURE_SYS */ - /* get name of connected client */ - hp = gethostbyaddr((char *)&who->sin_addr, sizeof (struct in_addr), - who->sin_family); - - if (hp == NULL && registerd_host_only) { - fatal(net, "Couldn't resolve your address into a host name.\r\n\ - Please contact your net administrator"); - } else if (hp && - (strlen(hp->h_name) <= (unsigned int)((utmp_len < 0) ? -utmp_len - : utmp_len))) { - host = hp->h_name; - } else { - host = inet_ntoa(who->sin_addr); - } - /* - * We must make a copy because Kerberos is probably going - * to also do a gethost* and overwrite the static data... - */ - strncpy(remote_host_name, host, sizeof(remote_host_name)-1); - remote_host_name[sizeof(remote_host_name)-1] = 0; - host = remote_host_name; - - (void) gethostname(host_name, sizeof (host_name)); + /* get name of connected client */ + hp = gethostbyaddr((char *)&((struct sockaddr_in *)who)->sin_addr, sizeof (struct in_addr), + ((struct sockaddr_in *)who)->sin_family); + + if (hp == NULL && registerd_host_only) { + fatal(net, "Couldn't resolve your address into a host name.\r\n\ + Please contact your net administrator"); + } else if (hp && + (strlen(hp->h_name) <= (unsigned int)((utmp_len < 0) ? -utmp_len + : utmp_len))) { + host = hp->h_name; + } else { + host = inet_ntoa(((struct sockaddr_in *)who)->sin_addr); + } + /* + * We must make a copy because Kerberos is probably going + * to also do a gethost* and overwrite the static data... + */ + strncpy(remote_hostname, host, sizeof(remote_hostname)-1); + remote_hostname[sizeof(remote_hostname)-1] = 0; + host = remote_hostname; + + (void) gethostname(host_name, sizeof(host_name) - 1); + host_name[sizeof(host_name) - 1] = '\0'; hostname = host_name; -#if defined(AUTHENTICATION) || defined(ENCRYPTION) - auth_encrypt_init(hostname, host, "TELNETD", 1); +#if defined(AUTHENTICATION) + auth_encrypt_init(hostname, remote_hostname, "TELNETD", 1); #endif init_env(); @@ -905,12 +868,6 @@ doit(who) level = getterminaltype(user_name); setenv("TERM", terminaltype ? terminaltype : "network", 1); - /* - * Start up the login process on the slave side of the terminal - */ -#ifndef convex - startslave(host, level, user_name); - #if defined(_SC_CRAY_SECURE_SYS) if (secflag) { if (setulvl(dv.dv_actlvl) < 0) @@ -920,10 +877,8 @@ doit(who) } #endif /* _SC_CRAY_SECURE_SYS */ - telnet(net, pty); /* begin server processing */ -#else - telnet(net, pty, host); -#endif + telnet(net, pty, remote_hostname); /* begin server process */ + /*NOTREACHED*/ } /* end of doit */ @@ -947,15 +902,9 @@ Xterm_output(ibufp, obuf, icountp, ocount) * hand data to telnet receiver finite state machine. */ void -#ifndef convex -telnet(f, p) -#else telnet(f, p, host) -#endif int f, p; -#ifdef convex char *host; -#endif { int on = 1; #define TABBUFSIZ 512 @@ -965,8 +914,12 @@ telnet(f, p, host) char *HE; char *HN; char *IM; + char *IF; + char *if_buf; + int if_fd; + struct stat statbuf; + void netflush(); - int nfd; /* * Initialize the slc mapping table. @@ -1051,9 +1004,7 @@ telnet(f, p, host) * mode, which we do not want. */ if (his_want_state_is_will(TELOPT_ECHO)) { - DIAG(TD_OPTIONS, - {sprintf(nfrontp, "td: simulating recv\r\n"); - nfrontp += strlen(nfrontp);}); + DIAG(TD_OPTIONS, output_data("td: simulating recv\r\n")); willoption(TELOPT_ECHO); } @@ -1119,9 +1070,9 @@ telnet(f, p, host) * side. Set up signal handler now. */ if ((int)signal(SIGUSR1, termstat) < 0) - perror("signal"); + warn("signal"); else if (ioctl(p, TCSIGME, (char *)SIGUSR1) < 0) - perror("ioctl:TCSIGME"); + warn("ioctl:TCSIGME"); /* * Make processing loop check terminal characteristics early on. */ @@ -1164,10 +1115,11 @@ telnet(f, p, host) HE = Getstr("he", &cp); HN = Getstr("hn", &cp); IM = Getstr("im", &cp); - if (HN && *HN) { - (void) strncpy(host_name, HN, sizeof(host_name)-1); - hostname[sizeof(host_name)-1] = '\0'; - } + IF = Getstr("if", &cp); + if (HN && *HN) + (void) strlcpy(host_name, HN, sizeof(host_name)); + if (IF && (if_fd = open(IF, O_RDONLY, 000)) != -1) + IM = 0; if (IM == 0) IM = ""; } else { @@ -1177,6 +1129,14 @@ telnet(f, p, host) edithost(HE, host_name); if (hostinfo && *IM) putf(IM, ptyibuf2); + else if (IF && if_fd != -1) { + fstat (if_fd, &statbuf); + if_buf = (char *) mmap (0, statbuf.st_size, PROT_READ, + 0, if_fd, 0); + putf(if_buf, ptyibuf2); + munmap (if_buf, statbuf.st_size); + close (if_fd); + } if (pcc) (void) strncat(ptyibuf2, ptyip, pcc+1); @@ -1190,15 +1150,15 @@ telnet(f, p, host) localstat(); #endif /* LINEMODE */ - DIAG(TD_REPORT, - {sprintf(nfrontp, "td: Entering processing loop\r\n"); - nfrontp += strlen(nfrontp);}); + DIAG(TD_REPORT, output_data("td: Entering processing loop\r\n")); -#ifdef convex - startslave(host); -#endif + /* + * Startup the login process on the slave side of the terminal + * now. We delay this until here to insure option negotiation + * is complete. + */ + startslave(host, level, user_name); - nfd = ((f > p) ? f : p) + 1; for (;;) { fd_set ibits, obits, xbits; register int c; @@ -1230,7 +1190,7 @@ telnet(f, p, host) if (!SYNCHing) { FD_SET(f, &xbits); } - if ((c = select(nfd, &ibits, &obits, &xbits, + if ((c = select(16, &ibits, &obits, &xbits, (struct timeval *)0)) < 1) { if (c == -1) { if (errno == EINTR) { @@ -1318,8 +1278,7 @@ telnet(f, p, host) netip = netibuf; } DIAG((TD_REPORT | TD_NETDATA), - {sprintf(nfrontp, "td: netread %d chars\r\n", ncc); - nfrontp += strlen(nfrontp);}); + output_data("td: netread %d chars\r\n", ncc)); DIAG(TD_NETDATA, printdata("nd", netip, ncc)); } @@ -1366,12 +1325,8 @@ telnet(f, p, host) * royally if we send them urgent * mode data. */ - *nfrontp++ = IAC; - *nfrontp++ = DM; + output_data("%c%c", IAC, DM); neturg = nfrontp-1; /* off by one XXX */ - DIAG(TD_OPTIONS, - printoption("td: send IAC", DM)); - #endif } if (his_state_is_will(TELOPT_LFLOW) && @@ -1381,16 +1336,11 @@ telnet(f, p, host) ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0; if (newflow != flowmode) { flowmode = newflow; - (void) sprintf(nfrontp, - "%c%c%c%c%c%c", + output_data("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); - nfrontp += 6; - DIAG(TD_OPTIONS, printsub('>', - (unsigned char *)nfrontp-4, - 4);); } } pcc--; @@ -1413,19 +1363,19 @@ telnet(f, p, host) break; c = *ptyip++ & 0377, pcc--; if (c == IAC) - *nfrontp++ = c; + output_data("%c", c); #if defined(CRAY2) && defined(UNICOS5) else if (c == '\n' && my_state_is_wont(TELOPT_BINARY) && newmap) - *nfrontp++ = '\r'; + output_data("\r"); #endif /* defined(CRAY2) && defined(UNICOS5) */ - *nfrontp++ = c; + output_data("%c", c); if ((c == '\r') && (my_state_is_wont(TELOPT_BINARY))) { if (pcc > 0 && ((*ptyip & 0377) == '\n')) { - *nfrontp++ = *ptyip++ & 0377; + output_data("%c", *ptyip++ & 0377); pcc--; } else - *nfrontp++ = '\0'; + output_data("%c", '\0'); } } #if defined(CRAY2) && defined(UNICOS5) @@ -1556,14 +1506,6 @@ interrupt() { ptyflush(); /* half-hearted */ -#if defined(STREAMSPTY) && defined(TIOCSIGNAL) - /* Streams PTY style ioctl to post a signal */ - { - int sig = SIGINT; - (void) ioctl(pty, TIOCSIGNAL, &sig); - (void) ioctl(pty, I_FLUSH, FLUSHR); - } -#else #ifdef TCSIG (void) ioctl(pty, TCSIG, (char *)SIGINT); #else /* TCSIG */ @@ -1571,7 +1513,6 @@ interrupt() *pfrontp++ = slctab[SLC_IP].sptr ? (unsigned char)*slctab[SLC_IP].sptr : '\177'; #endif /* TCSIG */ -#endif } /* @@ -1619,8 +1560,7 @@ recv_ayt() return; } #endif - (void) strcpy(nfrontp, "\r\n[Yes]\r\n"); - nfrontp += 9; + output_data("\r\n[Yes]\r\n"); } void diff --git a/telnetd.tproj/telnetd.h b/telnetd.tproj/telnetd.h index 56ccdcd..234b973 100644 --- a/telnetd.tproj/telnetd.h +++ b/telnetd.tproj/telnetd.h @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -59,7 +36,6 @@ #include "defs.h" #include "ext.h" -#include #ifdef DIAGNOSTICS #define DIAG(a,b) if (diagnostic & (a)) b diff --git a/telnetd.tproj/termstat.c b/telnetd.tproj/termstat.c index 0705dec..0b6e1d2 100644 --- a/telnetd.tproj/termstat.c +++ b/telnetd.tproj/termstat.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,7 +32,11 @@ */ #ifndef lint -static char sccsid[] = "@(#)termstat.c 8.2 (Berkeley) 5/30/95"; +#if 0 +static char sccsid[] = "@(#)termstat.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/termstat.c,v 1.11 2001/07/20 15:14:03 ru Exp $"; #endif /* not lint */ #include "telnetd.h" @@ -155,7 +136,6 @@ int newmap = 1; /* nonzero if \n maps to ^M^J */ void localstat() { - void netflush(); int need_will_echo = 0; #if defined(CRAY2) && defined(UNICOS5) @@ -166,25 +146,6 @@ localstat() newmap = tty_isnewmap(); #endif /* defined(CRAY2) && defined(UNICOS5) */ - /* - * Check for state of BINARY options. - */ - if (tty_isbinaryin()) { - if (his_want_state_is_wont(TELOPT_BINARY)) - send_do(TELOPT_BINARY, 1); - } else { - if (his_want_state_is_will(TELOPT_BINARY)) - send_dont(TELOPT_BINARY, 1); - } - - if (tty_isbinaryout()) { - if (my_want_state_is_wont(TELOPT_BINARY)) - send_will(TELOPT_BINARY, 1); - } else { - if (my_want_state_is_will(TELOPT_BINARY)) - send_wont(TELOPT_BINARY, 1); - } - /* * Check for changes to flow control if client supports it. */ @@ -204,25 +165,34 @@ localstat() tty_setlinemode(uselinemode); } -#ifdef ENCRYPTION - /* - * If the terminal is not echoing, but editing is enabled, - * something like password input is going to happen, so - * if we the other side is not currently sending encrypted - * data, ask the other side to start encrypting. - */ - if (his_state_is_will(TELOPT_ENCRYPT)) { - static int enc_passwd = 0; - if (uselinemode && !tty_isecho() && tty_isediting() - && (enc_passwd == 0) && !decrypt_input) { - encrypt_send_request_start(); - enc_passwd = 1; - } else if (enc_passwd) { - encrypt_send_request_end(); - enc_passwd = 0; - } - } -#endif /* ENCRYPTION */ + if (uselinemode) { + + /* + * Check for state of BINARY options. + * + * We only need to do the binary dance if we are actually going + * to use linemode. As this confuses some telnet clients that dont + * support linemode, and doesnt gain us anything, we dont do it + * unless we're doing linemode. -Crh (henrich@msu.edu) + */ + + if (tty_isbinaryin()) { + if (his_want_state_is_wont(TELOPT_BINARY)) + send_do(TELOPT_BINARY, 1); + } else { + if (his_want_state_is_will(TELOPT_BINARY)) + send_dont(TELOPT_BINARY, 1); + } + + if (tty_isbinaryout()) { + if (my_want_state_is_wont(TELOPT_BINARY)) + send_will(TELOPT_BINARY, 1); + } else { + if (my_want_state_is_will(TELOPT_BINARY)) + send_wont(TELOPT_BINARY, 1); + } + + } /* * Do echo mode handling as soon as we know what the @@ -308,10 +278,9 @@ localstat() # endif /* KLUDGELINEMODE */ send_do(TELOPT_LINEMODE, 1); /* send along edit modes */ - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, + output_data("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; # ifdef KLUDGELINEMODE } @@ -337,10 +306,9 @@ localstat() /* * Send along appropriate edit mode mask. */ - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, + output_data("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; } @@ -384,20 +352,18 @@ flowstat() if (his_state_is_will(TELOPT_LFLOW)) { if (tty_flowmode() != flowmode) { flowmode = tty_flowmode(); - (void) sprintf(nfrontp, "%c%c%c%c%c%c", + output_data("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); - nfrontp += 6; } if (tty_restartany() != restartany) { restartany = tty_restartany(); - (void) sprintf(nfrontp, "%c%c%c%c%c%c", + output_data("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, restartany ? LFLOW_RESTART_ANY : LFLOW_RESTART_XON, IAC, SE); - nfrontp += 6; } } } @@ -414,7 +380,6 @@ flowstat() clientstat(code, parm1, parm2) register int code, parm1, parm2; { - void netflush(); /* * Get a copy of terminal characteristics. @@ -470,10 +435,9 @@ clientstat(code, parm1, parm2) useeditmode |= MODE_SOFT_TAB; if (tty_islitecho()) useeditmode |= MODE_LIT_ECHO; - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, + output_data("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; } @@ -502,7 +466,7 @@ clientstat(code, parm1, parm2) ack = (useeditmode & MODE_ACK); useeditmode &= ~MODE_ACK; - if (changed = (useeditmode ^ editmode)) { + if ((changed = (useeditmode ^ editmode))) { /* * This check is for a timing problem. If the * state of the tty has changed (due to the user @@ -529,11 +493,10 @@ clientstat(code, parm1, parm2) set_termbuf(); if (!ack) { - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, + output_data("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode|MODE_ACK, IAC, SE); - nfrontp += 7; } editmode = useeditmode; @@ -586,7 +549,7 @@ clientstat(code, parm1, parm2) /* * Change terminal speed as requested by client. * We set the receive speed first, so that if we can't - * store seperate receive and transmit speeds, the transmit + * store separate receive and transmit speeds, the transmit * speed will take precedence. */ tty_rspeed(parm2); @@ -655,7 +618,7 @@ defer_terminit() if (def_col || def_row) { struct winsize ws; - memset((char *)&ws, 0, sizeof(ws)); + bzero((char *)&ws, sizeof(ws)); ws.ws_col = def_col; ws.ws_row = def_row; (void) ioctl(pty, TIOCSWINSZ, (char *)&ws); diff --git a/telnetd.tproj/utility.c b/telnetd.tproj/utility.c index 9154811..32dd170 100644 --- a/telnetd.tproj/utility.c +++ b/telnetd.tproj/utility.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -55,9 +32,17 @@ */ #ifndef lint -static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95"; +#if 0 +static char sccsid[] = "@(#)utility.c 8.2 (Berkeley) 12/15/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/telnetd/utility.c,v 1.15 2001/07/20 15:14:03 ru Exp $"; #endif /* not lint */ +#ifdef __FreeBSD__ +#include +#include +#endif #define PRINTOPTIONS #include "telnetd.h" @@ -77,23 +62,20 @@ static char sccsid[] = "@(#)utility.c 8.4 (Berkeley) 5/30/95"; void ttloop() { - void netflush(); - DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop\r\n"); - nfrontp += strlen(nfrontp);}); - if (nfrontp-nbackp) { + DIAG(TD_REPORT, output_data("td: ttloop\r\n")); + if (nfrontp - nbackp > 0) { netflush(); } ncc = read(net, netibuf, sizeof netibuf); if (ncc < 0) { - syslog(LOG_INFO, "ttloop: read: %m\n"); + syslog(LOG_INFO, "ttloop: read: %m"); exit(1); } else if (ncc == 0) { - syslog(LOG_INFO, "ttloop: peer died: %m\n"); + syslog(LOG_INFO, "ttloop: peer died: %m"); exit(1); } - DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc); - nfrontp += strlen(nfrontp);}); + DIAG(TD_REPORT, output_data("td: ttloop read %d chars\r\n", ncc)); netip = netibuf; telrcv(); /* state machine */ if (ncc > 0) { @@ -116,6 +98,7 @@ stilloob(s) do { FD_ZERO(&excepts); FD_SET(s, &excepts); + memset((char *)&timeout, 0, sizeof timeout); value = select(s+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout); } while ((value == -1) && (errno == EINTR)); @@ -135,9 +118,8 @@ ptyflush() int n; if ((n = pfrontp - pbackp) > 0) { - DIAG((TD_REPORT | TD_PTYDATA), - { sprintf(nfrontp, "td: ptyflush %d chars\r\n", n); - nfrontp += strlen(nfrontp); }); + DIAG(TD_REPORT | TD_PTYDATA, + output_data("td: ptyflush %d chars\r\n", n)); DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); n = write(pty, pbackp, n); } @@ -216,11 +198,7 @@ netclear() #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \ ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL)) -#ifdef ENCRYPTION - thisitem = nclearto > netobuf ? nclearto : netobuf; -#else /* ENCRYPTION */ thisitem = netobuf; -#endif /* ENCRYPTION */ while ((next = nextitem(thisitem)) <= nbackp) { thisitem = next; @@ -228,11 +206,7 @@ netclear() /* Now, thisitem is first before/at boundary. */ -#ifdef ENCRYPTION - good = nclearto > netobuf ? nclearto : netobuf; -#else /* ENCRYPTION */ good = netobuf; /* where the good bytes go */ -#endif /* ENCRYPTION */ while (nfrontp > thisitem) { if (wewant(thisitem)) { @@ -243,7 +217,7 @@ netclear() next = nextitem(next); } while (wewant(next) && (nfrontp > next)); length = next-thisitem; - memmove(good, thisitem, length); + bcopy(thisitem, good, length); good += length; thisitem = next; } else { @@ -267,21 +241,14 @@ netflush() int n; extern int not42; - if ((n = nfrontp - nbackp) > 0) { - DIAG(TD_REPORT, - { sprintf(nfrontp, "td: netflush %d chars\r\n", n); - n += strlen(nfrontp); /* get count first */ - nfrontp += strlen(nfrontp); /* then move pointer */ - }); -#ifdef ENCRYPTION - if (encrypt_output) { - char *s = nclearto ? nclearto : nbackp; - if (nfrontp - s > 0) { - (*encrypt_output)((unsigned char *)s, nfrontp-s); - nclearto = nfrontp; - } - } -#endif /* ENCRYPTION */ + while ((n = nfrontp - nbackp) > 0) { +#if 0 + /* XXX This causes output_data() to recurse and die */ + + DIAG(TD_REPORT, { + n += output_data("td: netflush %d chars\r\n", n); + }); +#endif /* * if no urgent data, or if the other side appears to be an * old 4.2 client (and thus unable to survive TCP urgent data), @@ -305,57 +272,24 @@ netflush() n = send(net, nbackp, n, MSG_OOB); /* URGENT data */ } } - } - if (n < 0) { - if (errno == EWOULDBLOCK || errno == EINTR) - return; - cleanup(0); - } - nbackp += n; -#ifdef ENCRYPTION - if (nbackp > nclearto) - nclearto = 0; -#endif /* ENCRYPTION */ - if (nbackp >= neturg) { - neturg = 0; - } - if (nbackp == nfrontp) { - nbackp = nfrontp = netobuf; -#ifdef ENCRYPTION - nclearto = 0; -#endif /* ENCRYPTION */ + if (n == -1) { + if (errno == EWOULDBLOCK || errno == EINTR) + continue; + cleanup(0); + /* NOTREACHED */ + } + nbackp += n; + if (nbackp >= neturg) { + neturg = 0; + } + if (nbackp == nfrontp) { + nbackp = nfrontp = netobuf; + } } return; } /* end of netflush */ -/* - * writenet - * - * Just a handy little function to write a bit of raw data to the net. - * It will force a transmit of the buffer if necessary - * - * arguments - * ptr - A pointer to a character string to write - * len - How many bytes to write - */ - void -writenet(ptr, len) - register unsigned char *ptr; - register int len; -{ - /* flush buffer if no room for new data) */ - if ((&netobuf[BUFSIZ] - nfrontp) < len) { - /* if this fails, don't worry, buffer is a little big */ - netflush(); - } - - memmove(nfrontp, ptr, len); - nfrontp += len; - -} /* end of writenet */ - - /* * miscellaneous functions doing a variety of little jobs follow ... */ @@ -368,17 +302,7 @@ fatal(f, msg) { char buf[BUFSIZ]; - (void) sprintf(buf, "telnetd: %s.\r\n", msg); -#ifdef ENCRYPTION - if (encrypt_output) { - /* - * Better turn off encryption first.... - * Hope it flushes... - */ - encrypt_send_end(); - netflush(); - } -#endif /* ENCRYPTION */ + (void) snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg); (void) write(f, buf, (int)strlen(buf)); sleep(1); /*XXX*/ exit(1); @@ -391,7 +315,7 @@ fatalperror(f, msg) { char buf[BUFSIZ], *strerror(); - (void) sprintf(buf, "%s: %s", msg, strerror(errno)); + (void) snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(errno)); fatal(f, buf); } @@ -403,7 +327,6 @@ edithost(pat, host) register char *host; { register char *res = editedhost; - char *strncpy(); if (!pat) pat = ""; @@ -456,12 +379,16 @@ putchr(cc) *putlocation++ = cc; } +#ifdef __FreeBSD__ +static char fmtstr[] = { "%+" }; +#else /* * This is split on two lines so that SCCS will not see the M * between two % signs and expand it... */ static char fmtstr[] = { "%l:%M\ %P on %A, %d %B %Y" }; +#endif void putf(cp, where) @@ -472,15 +399,25 @@ putf(cp, where) time_t t; char db[100]; #ifdef STREAMSPTY - extern char *strchr(); + extern char *index(); #else - extern char *strrchr(); + extern char *rindex(); +#endif +#ifdef __FreeBSD__ + static struct utsname kerninfo; + + if (!*kerninfo.sysname) + uname(&kerninfo); #endif putlocation = where; while (*cp) { - if (*cp != '%') { + if (*cp =='\n') { + putstr("\r\n"); + cp++; + continue; + } else if (*cp != '%') { putchr(*cp++); continue; } @@ -489,9 +426,9 @@ putf(cp, where) case 't': #ifdef STREAMSPTY /* names are like /dev/pts/2 -- we want pts/2 */ - slash = strchr(line+1, '/'); + slash = index(line+1, '/'); #else - slash = strrchr(line, '/'); + slash = rindex(line, '/'); #endif if (slash == (char *) 0) putstr(line); @@ -504,11 +441,32 @@ putf(cp, where) break; case 'd': +#ifdef __FreeBSD__ + setlocale(LC_TIME, ""); +#endif (void)time(&t); (void)strftime(db, sizeof(db), fmtstr, localtime(&t)); putstr(db); break; +#ifdef __FreeBSD__ + case 's': + putstr(kerninfo.sysname); + break; + + case 'm': + putstr(kerninfo.machine); + break; + + case 'r': + putstr(kerninfo.release); + break; + + case 'v': + putstr(kerninfo.version); + break; +#endif + case '%': putchr('%'); break; @@ -527,12 +485,11 @@ printoption(fmt, option) register int option; { if (TELOPT_OK(option)) - sprintf(nfrontp, "%s %s\r\n", fmt, TELOPT(option)); + output_data("%s %s\r\n", fmt, TELOPT(option)); else if (TELCMD_OK(option)) - sprintf(nfrontp, "%s %s\r\n", fmt, TELCMD(option)); + output_data("%s %s\r\n", fmt, TELCMD(option)); else - sprintf(nfrontp, "%s %d\r\n", fmt, option); - nfrontp += strlen(nfrontp); + output_data("%s %d\r\n", fmt, option); return; } @@ -542,16 +499,14 @@ printsub(direction, pointer, length) unsigned char *pointer; /* where suboption data sits */ int length; /* length of suboption data */ { - register int i; - char buf[512]; + register int i = 0; - if (!(diagnostic & TD_OPTIONS)) + if (!(diagnostic & TD_OPTIONS)) return; if (direction) { - sprintf(nfrontp, "td: %s suboption ", + output_data("td: %s suboption ", direction == '<' ? "recv" : "send"); - nfrontp += strlen(nfrontp); if (length >= 3) { register int j; @@ -559,232 +514,192 @@ printsub(direction, pointer, length) j = pointer[length-1]; if (i != IAC || j != SE) { - sprintf(nfrontp, "(terminated by "); - nfrontp += strlen(nfrontp); + output_data("(terminated by "); if (TELOPT_OK(i)) - sprintf(nfrontp, "%s ", TELOPT(i)); + output_data("%s ", TELOPT(i)); else if (TELCMD_OK(i)) - sprintf(nfrontp, "%s ", TELCMD(i)); + output_data("%s ", TELCMD(i)); else - sprintf(nfrontp, "%d ", i); - nfrontp += strlen(nfrontp); + output_data("%d ", i); if (TELOPT_OK(j)) - sprintf(nfrontp, "%s", TELOPT(j)); + output_data("%s", TELOPT(j)); else if (TELCMD_OK(j)) - sprintf(nfrontp, "%s", TELCMD(j)); + output_data("%s", TELCMD(j)); else - sprintf(nfrontp, "%d", j); - nfrontp += strlen(nfrontp); - sprintf(nfrontp, ", not IAC SE!) "); - nfrontp += strlen(nfrontp); + output_data("%d", j); + output_data(", not IAC SE!) "); } } length -= 2; } if (length < 1) { - sprintf(nfrontp, "(Empty suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data("(Empty suboption??\?)"); return; } switch (pointer[0]) { case TELOPT_TTYPE: - sprintf(nfrontp, "TERMINAL-TYPE "); - nfrontp += strlen(nfrontp); + output_data("TERMINAL-TYPE "); switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); + output_data("IS \"%.*s\"", length-2, (char *)pointer+2); break; case TELQUAL_SEND: - sprintf(nfrontp, "SEND"); + output_data("SEND"); break; default: - sprintf(nfrontp, + output_data( "- unknown qualifier %d (0x%x).", pointer[1], pointer[1]); } - nfrontp += strlen(nfrontp); break; case TELOPT_TSPEED: - sprintf(nfrontp, "TERMINAL-SPEED"); - nfrontp += strlen(nfrontp); + output_data("TERMINAL-SPEED"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data(" (empty suboption??\?)"); break; } switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, " IS %.*s", length-2, (char *)pointer+2); - nfrontp += strlen(nfrontp); + output_data(" IS %.*s", length-2, (char *)pointer+2); break; default: if (pointer[1] == 1) - sprintf(nfrontp, " SEND"); + output_data(" SEND"); else - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); + output_data(" %d (unknown)", pointer[1]); for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[i]); } break; } break; case TELOPT_LFLOW: - sprintf(nfrontp, "TOGGLE-FLOW-CONTROL"); - nfrontp += strlen(nfrontp); + output_data("TOGGLE-FLOW-CONTROL"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data(" (empty suboption??\?)"); break; } switch (pointer[1]) { case LFLOW_OFF: - sprintf(nfrontp, " OFF"); break; + output_data(" OFF"); break; case LFLOW_ON: - sprintf(nfrontp, " ON"); break; + output_data(" ON"); break; case LFLOW_RESTART_ANY: - sprintf(nfrontp, " RESTART-ANY"); break; + output_data(" RESTART-ANY"); break; case LFLOW_RESTART_XON: - sprintf(nfrontp, " RESTART-XON"); break; + output_data(" RESTART-XON"); break; default: - sprintf(nfrontp, " %d (unknown)", pointer[1]); + output_data(" %d (unknown)", pointer[1]); } - nfrontp += strlen(nfrontp); for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[i]); } break; case TELOPT_NAWS: - sprintf(nfrontp, "NAWS"); - nfrontp += strlen(nfrontp); + output_data("NAWS"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data(" (empty suboption??\?)"); break; } if (length == 2) { - sprintf(nfrontp, " ?%d?", pointer[1]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[1]); break; } - sprintf(nfrontp, " %d %d (%d)", + output_data(" %d %d (%d)", pointer[1], pointer[2], (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2]))); - nfrontp += strlen(nfrontp); if (length == 4) { - sprintf(nfrontp, " ?%d?", pointer[3]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[3]); break; } - sprintf(nfrontp, " %d %d (%d)", + output_data(" %d %d (%d)", pointer[3], pointer[4], (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4]))); - nfrontp += strlen(nfrontp); for (i = 5; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[i]); } break; case TELOPT_LINEMODE: - sprintf(nfrontp, "LINEMODE "); - nfrontp += strlen(nfrontp); + output_data("LINEMODE "); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data(" (empty suboption??\?)"); break; } switch (pointer[1]) { case WILL: - sprintf(nfrontp, "WILL "); + output_data("WILL "); goto common; case WONT: - sprintf(nfrontp, "WONT "); + output_data("WONT "); goto common; case DO: - sprintf(nfrontp, "DO "); + output_data("DO "); goto common; case DONT: - sprintf(nfrontp, "DONT "); + output_data("DONT "); common: - nfrontp += strlen(nfrontp); if (length < 3) { - sprintf(nfrontp, "(no option??\?)"); - nfrontp += strlen(nfrontp); + output_data("(no option??\?)"); break; } switch (pointer[2]) { case LM_FORWARDMASK: - sprintf(nfrontp, "Forward Mask"); - nfrontp += strlen(nfrontp); + output_data("Forward Mask"); for (i = 3; i < length; i++) { - sprintf(nfrontp, " %x", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %x", pointer[i]); } break; default: - sprintf(nfrontp, "%d (unknown)", pointer[2]); - nfrontp += strlen(nfrontp); + output_data("%d (unknown)", pointer[2]); for (i = 3; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %d", pointer[i]); } break; } break; case LM_SLC: - sprintf(nfrontp, "SLC"); - nfrontp += strlen(nfrontp); + output_data("SLC"); for (i = 2; i < length - 2; i += 3) { if (SLC_NAME_OK(pointer[i+SLC_FUNC])) - sprintf(nfrontp, " %s", SLC_NAME(pointer[i+SLC_FUNC])); + output_data(" %s", SLC_NAME(pointer[i+SLC_FUNC])); else - sprintf(nfrontp, " %d", pointer[i+SLC_FUNC]); - nfrontp += strlen(nfrontp); + output_data(" %d", pointer[i+SLC_FUNC]); switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) { case SLC_NOSUPPORT: - sprintf(nfrontp, " NOSUPPORT"); break; + output_data(" NOSUPPORT"); break; case SLC_CANTCHANGE: - sprintf(nfrontp, " CANTCHANGE"); break; + output_data(" CANTCHANGE"); break; case SLC_VARIABLE: - sprintf(nfrontp, " VARIABLE"); break; + output_data(" VARIABLE"); break; case SLC_DEFAULT: - sprintf(nfrontp, " DEFAULT"); break; + output_data(" DEFAULT"); break; } - nfrontp += strlen(nfrontp); - sprintf(nfrontp, "%s%s%s", + output_data("%s%s%s", pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "", pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "", pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : ""); - nfrontp += strlen(nfrontp); if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN| SLC_FLUSHOUT| SLC_LEVELBITS)) { - sprintf(nfrontp, "(0x%x)", pointer[i+SLC_FLAGS]); - nfrontp += strlen(nfrontp); + output_data("(0x%x)", pointer[i+SLC_FLAGS]); } - sprintf(nfrontp, " %d;", pointer[i+SLC_VALUE]); - nfrontp += strlen(nfrontp); + output_data(" %d;", pointer[i+SLC_VALUE]); if ((pointer[i+SLC_VALUE] == IAC) && (pointer[i+SLC_VALUE+1] == IAC)) i++; } for (; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[i]); } break; case LM_MODE: - sprintf(nfrontp, "MODE "); - nfrontp += strlen(nfrontp); + output_data("MODE "); if (length < 3) { - sprintf(nfrontp, "(no mode??\?)"); - nfrontp += strlen(nfrontp); + output_data("(no mode??\?)"); break; } { @@ -795,24 +710,19 @@ printsub(direction, pointer, length) pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "", pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "", pointer[2]&MODE_ACK ? "|ACK" : ""); - sprintf(nfrontp, "%s", tbuf[1] ? &tbuf[1] : "0"); - nfrontp += strlen(nfrontp); + output_data("%s", tbuf[1] ? &tbuf[1] : "0"); } if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) { - sprintf(nfrontp, " (0x%x)", pointer[2]); - nfrontp += strlen(nfrontp); + output_data(" (0x%x)", pointer[2]); } for (i = 3; i < length; i++) { - sprintf(nfrontp, " ?0x%x?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?0x%x?", pointer[i]); } break; default: - sprintf(nfrontp, "%d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); + output_data("%d (unknown)", pointer[1]); for (i = 2; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %d", pointer[i]); } } break; @@ -821,24 +731,20 @@ printsub(direction, pointer, length) register char *cp; register int j, k; - sprintf(nfrontp, "STATUS"); - nfrontp += strlen(nfrontp); + output_data("STATUS"); switch (pointer[1]) { default: if (pointer[1] == TELQUAL_SEND) - sprintf(nfrontp, " SEND"); + output_data(" SEND"); else - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); + output_data(" %d (unknown)", pointer[1]); for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[i]); } break; case TELQUAL_IS: - sprintf(nfrontp, " IS\r\n"); - nfrontp += strlen(nfrontp); + output_data(" IS\r\n"); for (i = 2; i < length; i++) { switch(pointer[i]) { @@ -849,18 +755,15 @@ printsub(direction, pointer, length) common2: i++; if (TELOPT_OK(pointer[i])) - sprintf(nfrontp, " %s %s", cp, TELOPT(pointer[i])); + output_data(" %s %s", cp, TELOPT(pointer[i])); else - sprintf(nfrontp, " %s %d", cp, pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %s %d", cp, pointer[i]); - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + output_data("\r\n"); break; case SB: - sprintf(nfrontp, " SB "); - nfrontp += strlen(nfrontp); + output_data(" SB "); i++; j = k = i; while (j < length) { @@ -876,20 +779,17 @@ printsub(direction, pointer, length) } printsub(0, &pointer[i], k - i); if (i < length) { - sprintf(nfrontp, " SE"); - nfrontp += strlen(nfrontp); + output_data(" SE"); i = j; } else i = j - 1; - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + output_data("\r\n"); break; default: - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %d", pointer[i]); break; } } @@ -899,87 +799,77 @@ printsub(direction, pointer, length) } case TELOPT_XDISPLOC: - sprintf(nfrontp, "X-DISPLAY-LOCATION "); - nfrontp += strlen(nfrontp); + output_data("X-DISPLAY-LOCATION "); switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); + output_data("IS \"%.*s\"", length-2, (char *)pointer+2); break; case TELQUAL_SEND: - sprintf(nfrontp, "SEND"); + output_data("SEND"); break; default: - sprintf(nfrontp, "- unknown qualifier %d (0x%x).", + output_data("- unknown qualifier %d (0x%x).", pointer[1], pointer[1]); } - nfrontp += strlen(nfrontp); break; case TELOPT_NEW_ENVIRON: - sprintf(nfrontp, "NEW-ENVIRON "); + output_data("NEW-ENVIRON "); goto env_common1; case TELOPT_OLD_ENVIRON: - sprintf(nfrontp, "OLD-ENVIRON"); + output_data("OLD-ENVIRON"); env_common1: - nfrontp += strlen(nfrontp); switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, "IS "); + output_data("IS "); goto env_common; case TELQUAL_SEND: - sprintf(nfrontp, "SEND "); + output_data("SEND "); goto env_common; case TELQUAL_INFO: - sprintf(nfrontp, "INFO "); + output_data("INFO "); env_common: - nfrontp += strlen(nfrontp); { register int noquote = 2; for (i = 2; i < length; i++ ) { switch (pointer[i]) { case NEW_ENV_VAR: - sprintf(nfrontp, "\" VAR " + noquote); - nfrontp += strlen(nfrontp); + output_data("\" VAR " + noquote); noquote = 2; break; case NEW_ENV_VALUE: - sprintf(nfrontp, "\" VALUE " + noquote); - nfrontp += strlen(nfrontp); + output_data("\" VALUE " + noquote); noquote = 2; break; case ENV_ESC: - sprintf(nfrontp, "\" ESC " + noquote); - nfrontp += strlen(nfrontp); + output_data("\" ESC " + noquote); noquote = 2; break; case ENV_USERVAR: - sprintf(nfrontp, "\" USERVAR " + noquote); - nfrontp += strlen(nfrontp); + output_data("\" USERVAR " + noquote); noquote = 2; break; default: - def_case: if (isprint(pointer[i]) && pointer[i] != '"') { if (noquote) { - *nfrontp++ = '"'; + output_data("\""); noquote = 0; } - *nfrontp++ = pointer[i]; + output_data("%c", pointer[i]); } else { - sprintf(nfrontp, "\" %03o " + noquote, + output_data("\" %03o " + noquote, pointer[i]); - nfrontp += strlen(nfrontp); noquote = 2; } break; } } if (!noquote) - *nfrontp++ = '"'; + output_data("\""); break; } } @@ -987,188 +877,84 @@ printsub(direction, pointer, length) #if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: - sprintf(nfrontp, "AUTHENTICATION"); - nfrontp += strlen(nfrontp); + output_data("AUTHENTICATION"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data(" (empty suboption??\?)"); break; } switch (pointer[1]) { case TELQUAL_REPLY: case TELQUAL_IS: - sprintf(nfrontp, " %s ", (pointer[1] == TELQUAL_IS) ? + output_data(" %s ", (pointer[1] == TELQUAL_IS) ? "IS" : "REPLY"); - nfrontp += strlen(nfrontp); if (AUTHTYPE_NAME_OK(pointer[2])) - sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[2])); + output_data("%s ", AUTHTYPE_NAME(pointer[2])); else - sprintf(nfrontp, "%d ", pointer[2]); - nfrontp += strlen(nfrontp); + output_data("%d ", pointer[2]); if (length < 3) { - sprintf(nfrontp, "(partial suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data("(partial suboption??\?)"); break; } - sprintf(nfrontp, "%s|%s", + output_data("%s|%s", ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? "CLIENT" : "SERVER", ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? "MUTUAL" : "ONE-WAY"); - nfrontp += strlen(nfrontp); - auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); - sprintf(nfrontp, "%s", buf); - nfrontp += strlen(nfrontp); + { + char buf[512]; + auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); + output_data("%s", buf); + } break; case TELQUAL_SEND: i = 2; - sprintf(nfrontp, " SEND "); - nfrontp += strlen(nfrontp); + output_data(" SEND "); while (i < length) { if (AUTHTYPE_NAME_OK(pointer[i])) - sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[i])); + output_data("%s ", AUTHTYPE_NAME(pointer[i])); else - sprintf(nfrontp, "%d ", pointer[i]); - nfrontp += strlen(nfrontp); + output_data("%d ", pointer[i]); if (++i >= length) { - sprintf(nfrontp, "(partial suboption??\?)"); - nfrontp += strlen(nfrontp); + output_data("(partial suboption??\?)"); break; } - sprintf(nfrontp, "%s|%s ", + output_data("%s|%s ", ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? "CLIENT" : "SERVER", ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? "MUTUAL" : "ONE-WAY"); - nfrontp += strlen(nfrontp); ++i; } break; case TELQUAL_NAME: - i = 2; - sprintf(nfrontp, " NAME \""); - nfrontp += strlen(nfrontp); - while (i < length) - *nfrontp += pointer[i++]; - *nfrontp += '"'; + output_data(" NAME \"%.*s\"", length - 2, pointer + 2); break; default: for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" ?%d?", pointer[i]); } break; } break; #endif -#ifdef ENCRYPTION - case TELOPT_ENCRYPT: - sprintf(nfrontp, "ENCRYPT"); - nfrontp += strlen(nfrontp); - if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); - break; - } - switch (pointer[1]) { - case ENCRYPT_START: - sprintf(nfrontp, " START"); - nfrontp += strlen(nfrontp); - break; - - case ENCRYPT_END: - sprintf(nfrontp, " END"); - nfrontp += strlen(nfrontp); - break; - - case ENCRYPT_REQSTART: - sprintf(nfrontp, " REQUEST-START"); - nfrontp += strlen(nfrontp); - break; - - case ENCRYPT_REQEND: - sprintf(nfrontp, " REQUEST-END"); - nfrontp += strlen(nfrontp); - break; - - case ENCRYPT_IS: - case ENCRYPT_REPLY: - sprintf(nfrontp, " %s ", (pointer[1] == ENCRYPT_IS) ? - "IS" : "REPLY"); - nfrontp += strlen(nfrontp); - if (length < 3) { - sprintf(nfrontp, " (partial suboption??\?)"); - nfrontp += strlen(nfrontp); - break; - } - if (ENCTYPE_NAME_OK(pointer[2])) - sprintf(nfrontp, "%s ", ENCTYPE_NAME(pointer[2])); - else - sprintf(nfrontp, " %d (unknown)", pointer[2]); - nfrontp += strlen(nfrontp); - - encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); - sprintf(nfrontp, "%s", buf); - nfrontp += strlen(nfrontp); - break; - - case ENCRYPT_SUPPORT: - i = 2; - sprintf(nfrontp, " SUPPORT "); - nfrontp += strlen(nfrontp); - while (i < length) { - if (ENCTYPE_NAME_OK(pointer[i])) - sprintf(nfrontp, "%s ", ENCTYPE_NAME(pointer[i])); - else - sprintf(nfrontp, "%d ", pointer[i]); - nfrontp += strlen(nfrontp); - i++; - } - break; - - case ENCRYPT_ENC_KEYID: - sprintf(nfrontp, " ENC_KEYID", pointer[1]); - nfrontp += strlen(nfrontp); - goto encommon; - - case ENCRYPT_DEC_KEYID: - sprintf(nfrontp, " DEC_KEYID", pointer[1]); - nfrontp += strlen(nfrontp); - goto encommon; - - default: - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - encommon: - for (i = 2; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } - break; - } - break; -#endif /* ENCRYPTION */ default: if (TELOPT_OK(pointer[0])) - sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0])); + output_data("%s (unknown)", TELOPT(pointer[0])); else - sprintf(nfrontp, "%d (unknown)", pointer[i]); - nfrontp += strlen(nfrontp); + output_data("%d (unknown)", pointer[i]); for (i = 1; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); + output_data(" %d", pointer[i]); } break; } - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + output_data("\r\n"); } /* @@ -1190,26 +976,22 @@ printdata(tag, ptr, cnt) } /* add a line of output */ - sprintf(nfrontp, "%s: ", tag); - nfrontp += strlen(nfrontp); + output_data("%s: ", tag); for (i = 0; i < 20 && cnt; i++) { - sprintf(nfrontp, "%02x", *ptr); - nfrontp += strlen(nfrontp); + output_data("%02x", *ptr); if (isprint(*ptr)) { xbuf[i] = *ptr; } else { xbuf[i] = '.'; } if (i % 2) { - *nfrontp = ' '; - nfrontp++; + output_data(" "); } cnt--; ptr++; } xbuf[i] = '\0'; - sprintf(nfrontp, " %s\r\n", xbuf ); - nfrontp += strlen(nfrontp); + output_data(" %s\r\n", xbuf ); } } #endif /* DIAGNOSTICS */ diff --git a/telnetd.tproj/vasprintf.c b/telnetd.tproj/vasprintf.c new file mode 100644 index 0000000..1bc5d7f --- /dev/null +++ b/telnetd.tproj/vasprintf.c @@ -0,0 +1,65 @@ +/* $OpenBSD: vasprintf.c,v 1.4 1998/06/21 22:13:47 millert Exp $ */ + +/* + * Copyright (c) 1997 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author 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 ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_RCS) && !defined(lint) +static char rcsid[] = "$FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.12 2001/01/24 13:00:47 deischen Exp $"; +#endif /* LIBC_RCS and not lint */ + +#include +#include +#include + +int +vasprintf(str, fmt, ap) + char **str; + const char *fmt; + _BSD_VA_LIST_ ap; +{ + int ret; + FILE f; + + f._file = -1; + f._flags = __SWR | __SSTR ; + f._bf._base = f._p = (unsigned char *)malloc(128); + if (f._bf._base == NULL) { + *str = NULL; + errno = ENOMEM; + return (-1); + } + f._bf._size = f._w = 127; /* Leave room for the NULL */ + ret = vfprintf(&f, fmt, ap); + *f._p = '\0'; + f._bf._base = realloc(f._bf._base, f._bf._size + 1); + if (f._bf._base == NULL) { + errno = ENOMEM; + ret = -1; + } + *str = (char *)f._bf._base; + return (ret); +} diff --git a/tftpd.tproj/tftpd.8 b/tftpd.tproj/tftpd.8 index 430c1c4..76896c4 100644 --- a/tftpd.tproj/tftpd.8 +++ b/tftpd.tproj/tftpd.8 @@ -30,25 +30,26 @@ .\" SUCH DAMAGE. .\" .\" @(#)tftpd.8 8.1 (Berkeley) 6/4/93 +.\" $FreeBSD: src/libexec/tftpd/tftpd.8,v 1.15 2001/07/15 07:53:42 dd Exp $ .\" -.Dd June 4, 1993 +.Dd September 14, 2000 .Dt TFTPD 8 -.Os BSD 4.2 +.Os .Sh NAME .Nm tftpd -.Nd -Internet Trivial File Transfer Protocol server +.Nd Internet Trivial File Transfer Protocol server .Sh SYNOPSIS -.Nm tftpd -.Op Fl l -.Op Fl n +.Nm /usr/libexec/tftpd +.Op Fl cCln +.Op Fl s Ar directory +.Op Fl u Ar user .Op Ar directory ... .Sh DESCRIPTION .Nm Tftpd is a server which supports the Internet Trivial File Transfer -Protocol (\c -.Tn RFC 783). +Protocol +.Pq Tn RFC 1350 . The .Tn TFTP server operates @@ -63,11 +64,12 @@ The server is normally started by The use of .Xr tftp 1 does not require an account or password on the remote system. -Due to the lack of authentication information, -.Nm tftpd +Due to the lack of authentication information, +.Nm will allow only publicly readable files to be accessed. -Files containing the string ``/\|\fB.\|.\fP\|/'' are not allowed. +Files containing the string ``/\|\fB.\|.\fP\|/'' or starting with +``\|\fB.\|.\fP\|/'' are not allowed. Files may be written only if they already exist and are publicly writable. Note that this extends the concept of .Dq public @@ -78,29 +80,119 @@ should be considered before enabling tftp service. The server should have the user ID with the lowest possible privilege. .Pp Access to files may be restricted by invoking -.Nm tftpd +.Nm with a list of directories by including up to 20 pathnames as server program arguments in .Pa /etc/inetd.conf . In this case access is restricted to files whose names are prefixed by the one of the given directories. -The given directories are also treated as a search path for +The given directories are also treated as a search path for relative filename requests. .Pp +The +.Fl s +option provides additional security by changing +.Nm Ns No 's +root directory, thereby prohibiting accesses outside of the specified +.Ar directory . +Because +.Xr chroot 2 +requires super-user privileges, +.Nm +must be run as root. +However, after performing the +.Fn chroot , +.Nm +will set its user id to that of the specified +.Ar user , +or +.Dq nobody +if no +.Fl u +option is specified. +.Pp The options are: .Bl -tag -width Ds +.It Fl c +Changes the default root directory of a connecting host via chroot based on the +connecting IP address. +This prevents multiple clients from writing to the same file at the same time. +If the directory does not exist, the client connection is refused. +The +.Fl s +option is required for +.Fl c +and the specified +.Ar directory +is used as a base. +.It Fl C +Operates the same as +.Fl c +except it falls back to +.Fl s Ns No 's +.Ar directory +if a directory does not exist for the client's IP. .It Fl l -Logs all requests using -.Xr syslog 3 . +Log all requests using +.Xr syslog 3 +with the facility of +.Dv LOG_FTP . +Note: Logging of +.Dv LOG_FTP +messages +must also be enabled in the syslog configuration file, +.Xr syslog.conf 5 . .It Fl n -Suppresses negative acknowledgement of requests for nonexistent +Suppress negative acknowledgement of requests for nonexistent relative filenames. +.It Fl s Ar directory +Cause +.Nm +to change its root directory to +.Pa directory . +After changing roots but before accepting commands, +.Nm +will switch credentials to an unprivileged user. +.It Fl u Ar user +Switch credentials to +.Ar user +(default +.Dq nobody ) +when the +.Fl s +option is used. +The user must be specified by name, not a numeric UID. .El .Sh SEE ALSO .Xr tftp 1 , -.Xr inetd 8 +.Xr chroot 2 , +.Xr inetd 8 , +.Xr syslogd 8 +.Rs +.%A K. R. Sollins +.%T The TFTP Protocol (Revision 2) +.%D July 1992 +.%O RFC 1350, STD 33 +.Re .Sh HISTORY The .Nm command appeared in -.Bx 4.2 . +.Bx 4.2 ; +the +.Fl s +option was introduced in +.Fx 2.2 , +the +.Fl u +option was introduced in +.Fx 4.2 , +and the +.Fl c +option was introduced in +.Fx 4.3 . +.Sh BUGS +Files larger than 33488896 octets (65535 blocks) cannot be transferred +without client and server supporting blocksize negotiation (RFC1783). +.Pp +Many tftp clients will not transfer files over 16744448 octets (32767 blocks). diff --git a/tftpd.tproj/tftpd.c b/tftpd.tproj/tftpd.c index f73cb56..20146c0 100644 --- a/tftpd.tproj/tftpd.c +++ b/tftpd.tproj/tftpd.c @@ -1,26 +1,3 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 1.0 (the 'License'). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License." - * - * @APPLE_LICENSE_HEADER_END@ - */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. @@ -55,13 +32,17 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1983, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; +#endif +static const char rcsid[] = + "$FreeBSD: src/libexec/tftpd/tftpd.c,v 1.18 2001/02/02 10:52:58 asmodai Exp $"; #endif /* not lint */ /* @@ -75,6 +56,7 @@ static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include #include #include @@ -84,6 +66,7 @@ static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include #include #include #include @@ -122,10 +105,11 @@ static struct dirlist { } dirs[MAXDIRS+1]; static int suppress_naks; static int logging; +static int ipchroot; static char *errtomsg __P((int)); static void nak __P((int)); -static char *verifyhost __P((struct sockaddr_in *)); +static char * __P(verifyhost(struct sockaddr_in *)); int main(argc, argv) @@ -136,16 +120,31 @@ main(argc, argv) register int n; int ch, on; struct sockaddr_in sin; + char *chroot_dir = NULL; + struct passwd *nobody; + char *chuser = "nobody"; - openlog("tftpd", LOG_PID, LOG_FTP); - while ((ch = getopt(argc, argv, "ln")) != EOF) { + openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP); + while ((ch = getopt(argc, argv, "cClns:u:")) != -1) { switch (ch) { + case 'c': + ipchroot = 1; + break; + case 'C': + ipchroot = 2; + break; case 'l': logging = 1; break; case 'n': suppress_naks = 1; break; + case 's': + chroot_dir = optarg; + break; + case 'u': + chuser = optarg; + break; default: syslog(LOG_WARNING, "ignoring unknown option -%c", ch); } @@ -163,17 +162,25 @@ main(argc, argv) } } } + else if (chroot_dir) { + dirs->name = "/"; + dirs->len = 1; + } + if (ipchroot && chroot_dir == NULL) { + syslog(LOG_ERR, "-c requires -s"); + exit(1); + } on = 1; if (ioctl(0, FIONBIO, &on) < 0) { - syslog(LOG_ERR, "ioctl(FIONBIO): %m\n"); + syslog(LOG_ERR, "ioctl(FIONBIO): %m"); exit(1); } fromlen = sizeof (from); n = recvfrom(0, buf, sizeof (buf), 0, (struct sockaddr *)&from, &fromlen); if (n < 0) { - syslog(LOG_ERR, "recvfrom: %m\n"); + syslog(LOG_ERR, "recvfrom: %m"); exit(1); } /* @@ -220,29 +227,62 @@ main(argc, argv) } } if (pid < 0) { - syslog(LOG_ERR, "fork: %m\n"); + syslog(LOG_ERR, "fork: %m"); exit(1); } else if (pid != 0) { exit(0); } } + + /* + * Since we exit here, we should do that only after the above + * recvfrom to keep inetd from constantly forking should there + * be a problem. See the above comment about system clogging. + */ + if (chroot_dir) { + if (ipchroot) { + char tempchroot[MAXPATHLEN]; + char *tempaddr; + struct stat sb; + int statret; + + tempaddr = inet_ntoa(from.sin_addr); + snprintf(tempchroot, sizeof(tempchroot), "%s/%s", chroot_dir, tempaddr); + statret = stat(tempchroot, &sb); + if ((sb.st_mode & S_IFDIR) && + (statret == 0 || (statret == -1 && ipchroot == 1))) + chroot_dir = tempchroot; + } + /* Must get this before chroot because /etc might go away */ + if ((nobody = getpwnam(chuser)) == NULL) { + syslog(LOG_ERR, "%s: no such user", chuser); + exit(1); + } + if (chroot(chroot_dir)) { + syslog(LOG_ERR, "chroot: %s: %m", chroot_dir); + exit(1); + } + chdir( "/" ); + setuid(nobody->pw_uid); + } + from.sin_family = AF_INET; alarm(0); close(0); close(1); peer = socket(AF_INET, SOCK_DGRAM, 0); if (peer < 0) { - syslog(LOG_ERR, "socket: %m\n"); + syslog(LOG_ERR, "socket: %m"); exit(1); } memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; if (bind(peer, (struct sockaddr *)&sin, sizeof (sin)) < 0) { - syslog(LOG_ERR, "bind: %m\n"); + syslog(LOG_ERR, "bind: %m"); exit(1); } if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) { - syslog(LOG_ERR, "connect: %m\n"); + syslog(LOG_ERR, "connect: %m"); exit(1); } tp = (struct tftphdr *)buf; @@ -254,7 +294,7 @@ main(argc, argv) struct formats; int validate_access __P((char **, int)); -void tftp_sendfile __P((struct formats *)); +void xmitfile __P((struct formats *)); void recvfile __P((struct formats *)); struct formats { @@ -264,8 +304,8 @@ struct formats { void (*f_recv) __P((struct formats *)); int f_convert; } formats[] = { - { "netascii", validate_access, tftp_sendfile, recvfile, 1 }, - { "octet", validate_access, tftp_sendfile, recvfile, 0 }, + { "netascii", validate_access, xmitfile, recvfile, 1 }, + { "octet", validate_access, xmitfile, recvfile, 0 }, #ifdef notdef { "mail", validate_user, sendmail, recvmail, 1 }, #endif @@ -313,8 +353,7 @@ again: } ecode = (*pf->f_validate)(&filename, tp->th_opcode); if (logging) { - syslog(LOG_INFO, "%s: %s request for %s: %s", - verifyhost(&from), + syslog(LOG_INFO, "%s: %s request for %s: %s", verifyhost(&from), tp->th_opcode == WRQ ? "write" : "read", filename, errtomsg(ecode)); } @@ -398,11 +437,11 @@ validate_access(filep, mode) /* * Relative file name: search the approved locations for it. - * Don't allow write requests or ones that avoid directory + * Don't allow write requests that avoid directory * restrictions. */ - if (mode != RRQ || !strncmp(filename, "../", 3)) + if (!strncmp(filename, "../", 3)) return (EACCESS); /* @@ -412,7 +451,8 @@ validate_access(filep, mode) */ err = ENOTFOUND; for (dirp = dirs; dirp->name != NULL; dirp++) { - sprintf(pathname, "%s/%s", dirp->name, filename); + snprintf(pathname, sizeof(pathname), "%s/%s", + dirp->name, filename); if (stat(pathname, &stbuf) == 0 && (stbuf.st_mode & S_IFMT) == S_IFREG) { if ((stbuf.st_mode & S_IROTH) != 0) { @@ -425,7 +465,7 @@ validate_access(filep, mode) return (err); *filep = filename = pathname; } - fd = open(filename, mode == RRQ ? 0 : 1); + fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY|O_TRUNC); if (fd < 0) return (errno + 100); file = fdopen(fd, (mode == RRQ)? "r":"w"); @@ -452,13 +492,13 @@ timer() * Send the requested file. */ void -tftp_sendfile(pf) +xmitfile(pf) struct formats *pf; { struct tftphdr *dp, *r_init(); register struct tftphdr *ap; /* ack packet */ register int size, n; - volatile int block; + volatile unsigned short block; signal(SIGALRM, timer); dp = r_init(); @@ -477,7 +517,7 @@ tftp_sendfile(pf) send_data: if (send(peer, dp, size + 4, 0) != size + 4) { - syslog(LOG_ERR, "tftpd: write: %m\n"); + syslog(LOG_ERR, "write: %m"); goto abort; } read_ahead(file, pf->f_convert); @@ -486,7 +526,7 @@ send_data: n = recv(peer, ackbuf, sizeof (ackbuf), 0); alarm(0); if (n < 0) { - syslog(LOG_ERR, "tftpd: read: %m\n"); + syslog(LOG_ERR, "read: %m"); goto abort; } ap->th_opcode = ntohs((u_short)ap->th_opcode); @@ -528,7 +568,7 @@ recvfile(pf) struct tftphdr *dp, *w_init(); register struct tftphdr *ap; /* ack buffer */ register int n, size; - volatile int block; + volatile unsigned short block; signal(SIGALRM, timer); dp = w_init(); @@ -542,7 +582,7 @@ recvfile(pf) (void) setjmp(timeoutbuf); send_ack: if (send(peer, ackbuf, 4, 0) != 4) { - syslog(LOG_ERR, "tftpd: write: %m\n"); + syslog(LOG_ERR, "write: %m"); goto abort; } write_behind(file, pf->f_convert); @@ -551,7 +591,7 @@ send_ack: n = recv(peer, dp, PKTSIZE, 0); alarm(0); if (n < 0) { /* really? */ - syslog(LOG_ERR, "tftpd: read: %m\n"); + syslog(LOG_ERR, "read: %m"); goto abort; } dp->th_opcode = ntohs((u_short)dp->th_opcode); @@ -622,7 +662,7 @@ errtomsg(error) for (pe = errmsgs; pe->e_code >= 0; pe++) if (pe->e_code == error) return pe->e_msg; - sprintf(buf, "error %d", error); + snprintf(buf, sizeof(buf), "error %d", error); return buf; } @@ -655,7 +695,7 @@ nak(error) tp->th_msg[length] = '\0'; length += 5; if (send(peer, buf, length, 0) != length) - syslog(LOG_ERR, "nak: %m\n"); + syslog(LOG_ERR, "nak: %m"); } static char * @@ -664,9 +704,9 @@ verifyhost(fromp) { struct hostent *hp; - hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof (fromp->sin_addr), - fromp->sin_family); - if (hp) + hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof(fromp->sin_addr), + fromp->sin_family); + if(hp) return hp->h_name; else return inet_ntoa(fromp->sin_addr); diff --git a/timed.tproj/timed.tproj/readmsg.c b/timed.tproj/timed.tproj/readmsg.c index fab1e77..88efb49 100644 --- a/timed.tproj/timed.tproj/readmsg.c +++ b/timed.tproj/timed.tproj/readmsg.c @@ -59,7 +59,7 @@ static char sccsid[] = "@(#)readmsg.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #ifdef sgi -#ident "$Revision: 1.1.1.1 $" +#ident "$Revision: 1.2 $" #endif #include "globals.h" @@ -111,6 +111,7 @@ readmsg(type, machfrom, intvl, netfrom) struct tsplist *prev; register struct netinfo *ntp; register struct tsplist *ptr; + ssize_t n; if (trace) { fprintf(fd, "readmsg: looking for %s from %s, %s\n", @@ -229,11 +230,18 @@ again: continue; } length = sizeof(from); - if (recvfrom(sock, (char *)&msgin, sizeof(struct tsp), 0, - (struct sockaddr*)&from, &length) < 0) { + if ((n = recvfrom(sock, (char *)&msgin, sizeof(struct tsp), 0, + (struct sockaddr*)&from, &length)) < 0) { syslog(LOG_ERR, "recvfrom: %m"); exit(1); } + if (n < (ssize_t)sizeof(struct tsp)) { + syslog(LOG_NOTICE, + "short packet (%u/%u bytes) from %s", + n, sizeof(struct tsp), + inet_ntoa(from.sin_addr)); + continue; + } (void)gettimeofday(&from_when, (struct timezone *)0); bytehostorder(&msgin); @@ -245,6 +253,13 @@ again: continue; } + if (memchr(msgin.tsp_name, + '\0', sizeof msgin.tsp_name) == NULL) { + syslog(LOG_NOTICE, "hostname field not NUL terminated " + "in packet from %s", inet_ntoa(from.sin_addr)); + continue; + } + fromnet = NULL; for (ntp = nettab; ntp != NULL; ntp = ntp->next) if ((ntp->mask & from.sin_addr.s_addr) == @@ -458,6 +473,13 @@ print(msg, addr) struct sockaddr_in *addr; { char tm[26]; + + if (msg->tsp_type >= TSPTYPENUMBER) { + fprintf(fd, "bad type (%u) on packet from %s\n", + msg->tsp_type, inet_ntoa(addr->sin_addr)); + return; + } + switch (msg->tsp_type) { case TSP_LOOP: -- 2.45.2