diff options
author | ngie <ngie@FreeBSD.org> | 2015-10-05 03:25:30 +0000 |
---|---|---|
committer | ngie <ngie@FreeBSD.org> | 2015-10-05 03:25:30 +0000 |
commit | 115d008392113efc6f844baa7cc407e9eaae63db (patch) | |
tree | 6cb521ad03ca5b254c0873d2b9f27a92482207c3 /contrib/ipfilter/ipsend | |
parent | a9fe170df1126a5dccd5dea163934fb04a95b5b8 (diff) | |
download | FreeBSD-src-115d008392113efc6f844baa7cc407e9eaae63db.zip FreeBSD-src-115d008392113efc6f844baa7cc407e9eaae63db.tar.gz |
Remove some paths preparing for a re-copy from head
Diffstat (limited to 'contrib/ipfilter/ipsend')
29 files changed, 0 insertions, 7453 deletions
diff --git a/contrib/ipfilter/ipsend/.OLD/ip_compat.h b/contrib/ipfilter/ipsend/.OLD/ip_compat.h deleted file mode 100644 index b5b8f07..0000000 --- a/contrib/ipfilter/ipsend/.OLD/ip_compat.h +++ /dev/null @@ -1,244 +0,0 @@ -/* $FreeBSD$ */ - -/* - * (C)opyright 1995 by Darren Reed. - * - * This code may be freely distributed as long as it retains this notice - * and is not changed in any way. The author accepts no responsibility - * for the use of this software. I hate legaleese, don't you ? - * - * @(#)ip_compat.h 1.2 12/7/95 - */ - -/* - * These #ifdef's are here mainly for linux, but who knows, they may - * not be in other places or maybe one day linux will grow up and some - * of these will turn up there too. - */ -#ifndef ICMP_UNREACH -# define ICMP_UNREACH ICMP_DEST_UNREACH -#endif -#ifndef ICMP_SOURCEQUENCH -# define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH -#endif -#ifndef ICMP_TIMXCEED -# define ICMP_TIMXCEED ICMP_TIME_EXCEEDED -#endif -#ifndef ICMP_PARAMPROB -# define ICMP_PARAMPROB ICMP_PARAMETERPROB -#endif -#ifndef IPVERSION -# define IPVERSION 4 -#endif -#ifndef IPOPT_MINOFF -# define IPOPT_MINOFF 4 -#endif -#ifndef IPOPT_COPIED -# define IPOPT_COPIED(x) ((x)&0x80) -#endif -#ifndef IPOPT_EOL -# define IPOPT_EOL 0 -#endif -#ifndef IPOPT_NOP -# define IPOPT_NOP 1 -#endif -#ifndef IP_MF -# define IP_MF ((u_short)0x2000) -#endif -#ifndef ETHERTYPE_IP -# define ETHERTYPE_IP ((u_short)0x0800) -#endif -#ifndef TH_FIN -# define TH_FIN 0x01 -#endif -#ifndef TH_SYN -# define TH_SYN 0x02 -#endif -#ifndef TH_RST -# define TH_RST 0x04 -#endif -#ifndef TH_PUSH -# define TH_PUSH 0x08 -#endif -#ifndef TH_ACK -# define TH_ACK 0x10 -#endif -#ifndef TH_URG -# define TH_URG 0x20 -#endif -#ifndef IPOPT_EOL -# define IPOPT_EOL 0 -#endif -#ifndef IPOPT_NOP -# define IPOPT_NOP 1 -#endif -#ifndef IPOPT_RR -# define IPOPT_RR 7 -#endif -#ifndef IPOPT_TS -# define IPOPT_TS 68 -#endif -#ifndef IPOPT_SECURITY -# define IPOPT_SECURITY 130 -#endif -#ifndef IPOPT_LSRR -# define IPOPT_LSRR 131 -#endif -#ifndef IPOPT_SATID -# define IPOPT_SATID 136 -#endif -#ifndef IPOPT_SSRR -# define IPOPT_SSRR 137 -#endif -#ifndef IPOPT_SECUR_UNCLASS -# define IPOPT_SECUR_UNCLASS ((u_short)0x0000) -#endif -#ifndef IPOPT_SECUR_CONFID -# define IPOPT_SECUR_CONFID ((u_short)0xf135) -#endif -#ifndef IPOPT_SECUR_EFTO -# define IPOPT_SECUR_EFTO ((u_short)0x789a) -#endif -#ifndef IPOPT_SECUR_MMMM -# define IPOPT_SECUR_MMMM ((u_short)0xbc4d) -#endif -#ifndef IPOPT_SECUR_RESTR -# define IPOPT_SECUR_RESTR ((u_short)0xaf13) -#endif -#ifndef IPOPT_SECUR_SECRET -# define IPOPT_SECUR_SECRET ((u_short)0xd788) -#endif -#ifndef IPOPT_SECUR_TOPSECRET -# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) -#endif - -#ifdef linux -# if LINUX < 0200 -# define icmp icmphdr -# define icmp_type type -# define icmp_code code -# endif - -/* - * From /usr/include/netinet/ip_var.h - * !%@#!$@# linux... - */ -struct ipovly { - caddr_t ih_next, ih_prev; /* for protocol sequence q's */ - u_char ih_x1; /* (unused) */ - u_char ih_pr; /* protocol */ - short ih_len; /* protocol length */ - struct in_addr ih_src; /* source internet address */ - struct in_addr ih_dst; /* destination internet address */ -}; - -typedef struct { - __u16 th_sport; - __u16 th_dport; - __u32 th_seq; - __u32 th_ack; -# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ - defined(vax) - __u8 th_res:4; - __u8 th_off:4; -#else - __u8 th_off:4; - __u8 th_res:4; -#endif - __u8 th_flags; - __u16 th_win; - __u16 th_sum; - __u16 th_urp; -} tcphdr_t; - -typedef struct { - __u16 uh_sport; - __u16 uh_dport; - __s16 uh_ulen; - __u16 uh_sum; -} udphdr_t; - -typedef struct { -# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ - defined(vax) - __u8 ip_hl:4; - __u8 ip_v:4; -# else - __u8 ip_hl:4; - __u8 ip_v:4; -# endif - __u8 ip_tos; - __u16 ip_len; - __u16 ip_id; - __u16 ip_off; - __u8 ip_ttl; - __u8 ip_p; - __u16 ip_sum; - struct in_addr ip_src; - struct in_addr ip_dst; -} ip_t; - -typedef struct { - __u8 ether_dhost[6]; - __u8 ether_shost[6]; - __u16 ether_type; -} ether_header_t; - -typedef struct icmp { - u_char icmp_type; /* type of message, see below */ - u_char icmp_code; /* type sub code */ - u_short icmp_cksum; /* ones complement cksum of struct */ - union { - u_char ih_pptr; /* ICMP_PARAMPROB */ - struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ - struct ih_idseq { - n_short icd_id; - n_short icd_seq; - } ih_idseq; - int ih_void; - } icmp_hun; -#define icmp_pptr icmp_hun.ih_pptr -#define icmp_gwaddr icmp_hun.ih_gwaddr -#define icmp_id icmp_hun.ih_idseq.icd_id -#define icmp_seq icmp_hun.ih_idseq.icd_seq -#define icmp_void icmp_hun.ih_void - union { - struct id_ts { - n_time its_otime; - n_time its_rtime; - n_time its_ttime; - } id_ts; - struct id_ip { - ip_t idi_ip; - /* options and then 64 bits of data */ - } id_ip; - u_long id_mask; - char id_data[1]; - } icmp_dun; -#define icmp_otime icmp_dun.id_ts.its_otime -#define icmp_rtime icmp_dun.id_ts.its_rtime -#define icmp_ttime icmp_dun.id_ts.its_ttime -#define icmp_ip icmp_dun.id_ip.idi_ip -#define icmp_mask icmp_dun.id_mask -#define icmp_data icmp_dun.id_data -} icmphdr_t; - -# define bcopy(a,b,c) memmove(b,a,c) -# define bcmp(a,b,c) memcmp(a,b,c) - -# define ifnet device - -#else - -typedef struct udphdr udphdr_t; -typedef struct tcphdr tcphdr_t; -typedef struct ip ip_t; -typedef struct ether_header ether_header_t; - -#endif - -#if defined(__SVR4) || defined(__svr4__) -# define bcopy(a,b,c) memmove(b,a,c) -# define bcmp(a,b,c) memcmp(a,b,c) -# define bzero(a,b) memset(a,0,b) -#endif diff --git a/contrib/ipfilter/ipsend/44arp.c b/contrib/ipfilter/ipsend/44arp.c deleted file mode 100644 index 9215959..0000000 --- a/contrib/ipfilter/ipsend/44arp.c +++ /dev/null @@ -1,120 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Based upon 4.4BSD's /usr/sbin/arp - */ -#include <sys/param.h> -#include <sys/file.h> -#include <sys/socket.h> -#include <sys/sysctl.h> -#include <net/if.h> -#include <net/if_dl.h> -#include <net/if_types.h> -#ifndef __osf__ -# include <net/route.h> -#endif -#include <netinet/in.h> -#include <netinet/if_ether.h> -#include <arpa/inet.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/ip_var.h> -#include <netinet/tcp.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <netdb.h> -#include <errno.h> -#include <nlist.h> -#include <stdio.h> -#include "ipsend.h" -#include "iplang/iplang.h" - - -/* - * lookup host and return - * its IP address in address - * (4 bytes) - */ -int resolve(host, address) - char *host, *address; -{ - struct hostent *hp; - u_long add; - - add = inet_addr(host); - if (add == -1) - { - if (!(hp = gethostbyname(host))) - { - fprintf(stderr, "unknown host: %s\n", host); - return -1; - } - bcopy((char *)hp->h_addr, (char *)address, 4); - return 0; - } - bcopy((char*)&add, address, 4); - return 0; -} - - -int arp(addr, eaddr) - char *addr, *eaddr; -{ - int mib[6]; - size_t needed; - char *lim, *buf, *next; - struct rt_msghdr *rtm; - struct sockaddr_in *sin; - struct sockaddr_dl *sdl; - -#ifdef IPSEND - if (arp_getipv4(addr, ether) == 0) - return 0; -#endif - - if (!addr) - return -1; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; - mib[3] = AF_INET; - mib[4] = NET_RT_FLAGS; -#ifdef RTF_LLINFO - mib[5] = RTF_LLINFO; -#else - mib[5] = 0; -#endif - - if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1) - { - perror("route-sysctl-estimate"); - exit(-1); - } - if ((buf = malloc(needed)) == NULL) - { - perror("malloc"); - exit(-1); - } - if (sysctl(mib, 6, buf, &needed, NULL, 0) == -1) - { - perror("actual retrieval of routing table"); - exit(-1); - } - lim = buf + needed; - for (next = buf; next < lim; next += rtm->rtm_msglen) - { - rtm = (struct rt_msghdr *)next; - sin = (struct sockaddr_in *)(rtm + 1); - sdl = (struct sockaddr_dl *)(sin + 1); - if (!bcmp(addr, (char *)&sin->sin_addr, - sizeof(struct in_addr))) - { - bcopy(LLADDR(sdl), eaddr, sdl->sdl_alen); - return 0; - } - } - return -1; -} diff --git a/contrib/ipfilter/ipsend/Crashable b/contrib/ipfilter/ipsend/Crashable deleted file mode 100644 index c7ffcde..0000000 --- a/contrib/ipfilter/ipsend/Crashable +++ /dev/null @@ -1,21 +0,0 @@ -Test 1: - Solaris 2.4 - upto and including 101945-34, > 34 ? - Solaris 2.5 - 11/95 - Linux 1.2.13, < 1.3.45(?) - 3com/sonix bridge - Instant Internet - KA9Q NOS - Netblazer 40i, Version 3.2 OS - Irix 6.x - HP-UX 9.0 - HP-UX 10.1 - LivingstonsComOS - MacOS 7.x, 8.x - -Test 6: - SunOS 4.1.x - ULtrix 4.3 - -Test 7: - SunOS 4.1.x - Linux <= 1.3.84 diff --git a/contrib/ipfilter/ipsend/Makefile b/contrib/ipfilter/ipsend/Makefile deleted file mode 100644 index 34485ef..0000000 --- a/contrib/ipfilter/ipsend/Makefile +++ /dev/null @@ -1,183 +0,0 @@ -# -# Copyright (C) 2012 by Darren Reed. -# -# See the IPFILTER.LICENCE file for details on licencing. -# -IPFT=ipft_ef.o ipft_hx.o ipft_pc.o ipft_sn.o ipft_td.o ipft_tx.o opt.o -OBJS=ipsend.o ip.o ipsopt.o y.tab.o lex.yy.o -ROBJS=ipresend.o ip.o resend.o $(IPFT) -TOBJS=iptest.o iptests.o ip.o -BPF=sbpf.o -NIT=snit.o -SUNOS4=sock.o arp.o inet_addr.o -BSD=sock.o 44arp.o -LINUX=lsock.o slinux.o larp.o -LINUXK= -TOP=.. -SUNOS5=dlcommon.o sdlpi.o arp.o inet_addr.o -ULTRIX=ultrix.o sock.o arp.o inet_addr.o -HPUX=hpux.o sock.o arp.o inet_addr.o - -#CC=gcc -DEBUG=-g -CFLAGS=$(DEBUG) -I. -Iipf -# -MFLAGS="BINDEST=$(BINDEST)" "SBINDEST=$(SBINDEST)" "MANDIR=$(MANDIR)" \ - "IPFLKM=$(IPFLKM)" \ - "IPFLOG=$(IPFLOG)" "LOGFAC=$(LOGFAC)" "POLICY=$(POLICY)" \ - "SOLARIS2=$(SOLARIS2)" "DEBUG=$(DEBUG)" "DCPU=$(CPU)" \ - "CPUDIR=$(CPUDIR)" -# -all: - @echo "Use one of these targets:" - @echo " sunos4-nit (standard SunOS 4.1.x)" - @echo " sunos4-bpf (SunOS4.1.x with BPF in the kernel)" - @echo " bsd-bpf (4.4BSD variant with BPF in the kernel)" - @echo " linux10 (Linux 1.0 kernels)" - @echo " linux12 (Linux 1.2 kernels)" - @echo " linux20 (Linux 2.0 kernels)" - @echo " sunos5 (Solaris 2.x)" - -ipf: - -if [ ! -d iplang ] ; then ln -s ../iplang iplang; fi - -if [ ! -d netinet ] ; then ln -s ../netinet netinet; fi - -if [ ! -d ipf ] ; then ln -s .. ipf; fi - -y.tab.o: iplang/iplang_y.y - -if [ -h iplang ] ; then \ - (cd iplang; ${MAKE} $(MFLAGS) 'DESTDIR=../ipsend' ) \ - else \ - (cd iplang; ${MAKE} $(MFLAGS) 'DESTDIR=..' ) \ - fi - -lex.yy.o: iplang/iplang_l.l - -if [ -h iplang ] ; then \ - (cd iplang; ${MAKE} $(MFLAGS) 'DESTDIR=../ipsend' ) \ - else \ - (cd iplang; ${MAKE} $(MFLAGS) 'DESTDIR=..' ) \ - fi - -.c.o: - $(CC) $(CFLAGS) $(LINUXK) -c $< -o $@ - -install: - -$(INSTALL) -cs -g wheel -m 755 -o root ipsend ipresend iptest $(BINDEST) - -bpf sunos4-bpf : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(BPF) $(SUNOS4)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET -DIPSEND" "LLIB=-ll" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(BPF) $(SUNOS4)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(BPF) $(SUNOS4)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET" - -nit sunos4 sunos4-nit : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(NIT) $(SUNOS4)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET -DIPSEND" "LLIB=-ll" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(NIT) $(SUNOS4)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(NIT) $(SUNOS4)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET" - -dlpi sunos5 : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(SUNOS5)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) -Dsolaris -DIPSEND" "LIBS=-lsocket -lnsl" \ - "LLIB=-ll" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(SUNOS5)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) -Dsolaris" "LIBS=-lsocket -lnsl" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(SUNOS5)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) -Dsolaris" "LIBS=-lsocket -lnsl" - -bsd-bpf : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(BPF) $(BSD)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET -DIPSEND" "LLIB=-ll" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(BPF) $(BSD)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(BPF) $(BSD)" "CC=$(CC)" \ - "CFLAGS=$(CFLAGS) -DDOSOCKET" - -linuxrev : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(LINUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) $(INC) -DDOSOCKET -DIPSEND" $(LINUXK) - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(LINUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) $(INC) -DDOSOCKET" $(LINUXK) - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(LINUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) $(INC) -DDOSOCKET" $(LINUXK) - -linux10: - make linuxrev 'LINUXK="LINUXK=-DLINUX=0100"' \ - "INC=-I/usr/src/linux/include" "LLIB=-lfl" - -linux12: - make linuxrev 'LINUXK="LINUXK=-DLINUX=0102"' "INC=-I/usr/src/linux" \ - "LLIB=-lfl" - -linux20: - make linuxrev 'LINUXK="LINUXK=-DLINUX=0200"' \ - "INC=-I/usr/src/linux/include" "LLIB=-lfl" "ELIB=-lelf" - -ultrix : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(ULTRIX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) -DIPSEND" "LIBS=" "LLIB=-ll" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(ULTRIX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS)" "LIBS=" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(ULTRIX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS)" "LIBS=" - -hpux9 : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(HPUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) -DIPSEND" "LIBS=" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(HPUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS)" "LIBS=" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(HPUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS)" "LIBS=" - -hpux11 : - make ipsend "OBJS=$(OBJS)" "UNIXOBJS=$(HPUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS) -DIPSEND" "LIBS=" - make ipresend "ROBJS=$(ROBJS)" "UNIXOBJS=$(HPUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS)" "LIBS=" - make iptest "TOBJS=$(TOBJS)" "UNIXOBJS=$(HPUX)" "CC=$(CC)" \ - CFLAGS="$(CFLAGS)" "LIBS=" - -ipsend: ipf $(OBJS) $(UNIXOBJS) - $(CC) $(OBJS) $(UNIXOBJS) -o $@ $(LIBS) $(LLIB) $(ELIB) - -ipresend: $(ROBJS) $(UNIXOBJS) - $(CC) $(ROBJS) $(UNIXOBJS) -o $@ $(LIBS) $(ELIB) - -iptest: $(TOBJS) $(UNIXOBJS) - $(CC) $(TOBJS) $(UNIXOBJS) -o $@ $(LIBS) $(ELIB) - -ipft_ef.o: ipf/ipft_ef.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/ipft_ef.c -o $@ - -ipft_hx.o: ipf/ipft_hx.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/ipft_hx.c -o $@ - -ipft_pc.o: ipf/ipft_pc.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/ipft_pc.c -o $@ - -ipft_sn.o: ipf/ipft_sn.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/ipft_sn.c -o $@ - -ipft_td.o: ipf/ipft_td.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/ipft_td.c -o $@ - -ipft_tx.o: ipf/ipft_tx.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/ipft_tx.c -o $@ - -opt.o: ipf/opt.c ipf/ipt.h ipf/ipf.h ipf/ip_compat.h - $(CC) $(CFLAGS) $(LINUXK) -c ipf/opt.c -o $@ - -inet_addr.o: ipf/inet_addr.c - $(CC) $(CFLAGS) $(LINUXK) -c ipf/inet_addr.c -o $@ - -clean: - rm -rf *.o *core a.out ipsend ipresend iptest - if [ -d iplang ]; then (cd iplang; $(MAKE) $(MFLAGS) clean); fi - if [ -d $(TOP)/iplang ]; then (cd $(TOP)/iplang; $(MAKE) $(MFLAGS) clean); fi - -do-cvs: - find . -type d -name CVS -print | xargs /bin/rm -rf - find . -type f -name .cvsignore -print | xargs /bin/rm -f diff --git a/contrib/ipfilter/ipsend/arp.c b/contrib/ipfilter/ipsend/arp.c deleted file mode 100644 index 58a1523..0000000 --- a/contrib/ipfilter/ipsend/arp.c +++ /dev/null @@ -1,141 +0,0 @@ -/* $FreeBSD$ */ - -/* - * arp.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - */ -#if !defined(lint) -static const char sccsid[] = "@(#)arp.c 1.4 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/types.h> -#include <sys/socket.h> -#if !defined(ultrix) && !defined(hpux) && !defined(__hpux) && !defined(__osf__) && !defined(_AIX51) -# include <sys/sockio.h> -#endif -#include <sys/ioctl.h> -#include <netinet/in_systm.h> -#include <netinet/in.h> -#include <net/if.h> -#include <netinet/if_ether.h> -#ifndef ultrix -# include <net/if_arp.h> -#endif -#include <netinet/in.h> -#include <netinet/ip.h> -#include <netinet/ip_var.h> -#include <netinet/tcp.h> -#include <stdio.h> -#include <errno.h> -#include <netdb.h> -#include "ipsend.h" -#include "iplang/iplang.h" - - -/* - * lookup host and return - * its IP address in address - * (4 bytes) - */ -int resolve(host, address) - char *host, *address; -{ - struct hostent *hp; - u_long add; - - add = inet_addr(host); - if (add == -1) - { - if (!(hp = gethostbyname(host))) - { - fprintf(stderr, "unknown host: %s\n", host); - return -1; - } - bcopy((char *)hp->h_addr, (char *)address, 4); - return 0; - } - bcopy((char*)&add, address, 4); - return 0; -} - -/* - * ARP for the MAC address corresponding - * to the IP address. This taken from - * some BSD program, I cant remember which. - */ -int arp(ip, ether) - char *ip; - char *ether; -{ - static int sfd = -1; - static char ethersave[6], ipsave[4]; - struct arpreq ar; - struct sockaddr_in *sin, san; - struct hostent *hp; - int fd; - -#ifdef IPSEND - if (arp_getipv4(ip, ether) == 0) - return 0; -#endif - if (!bcmp(ipsave, ip, 4)) { - bcopy(ethersave, ether, 6); - return 0; - } - fd = -1; - bzero((char *)&ar, sizeof(ar)); - sin = (struct sockaddr_in *)&ar.arp_pa; - sin->sin_family = AF_INET; - bcopy(ip, (char *)&sin->sin_addr.s_addr, 4); -#ifndef hpux - if ((hp = gethostbyaddr(ip, 4, AF_INET))) -# if SOLARIS && (SOLARIS2 >= 10) - if (!(ether_hostton(hp->h_name, (struct ether_addr *)ether))) -# else - if (!(ether_hostton(hp->h_name, ether))) -# endif - goto savearp; -#endif - - if (sfd == -1) - if ((sfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - { - perror("arp: socket"); - return -1; - } -tryagain: - if (ioctl(sfd, SIOCGARP, (caddr_t)&ar) == -1) - { - if (fd == -1) - { - bzero((char *)&san, sizeof(san)); - san.sin_family = AF_INET; - san.sin_port = htons(1); - bcopy(ip, &san.sin_addr.s_addr, 4); - fd = socket(AF_INET, SOCK_DGRAM, 0); - (void) sendto(fd, ip, 4, 0, - (struct sockaddr *)&san, sizeof(san)); - sleep(1); - (void) close(fd); - goto tryagain; - } - fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr)); - if (errno != ENXIO) - perror("SIOCGARP"); - return -1; - } - - if ((ar.arp_ha.sa_data[0] == 0) && (ar.arp_ha.sa_data[1] == 0) && - (ar.arp_ha.sa_data[2] == 0) && (ar.arp_ha.sa_data[3] == 0) && - (ar.arp_ha.sa_data[4] == 0) && (ar.arp_ha.sa_data[5] == 0)) { - fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr)); - return -1; - } - - bcopy(ar.arp_ha.sa_data, ether, 6); -savearp: - bcopy(ether, ethersave, 6); - bcopy(ip, ipsave, 4); - return 0; -} diff --git a/contrib/ipfilter/ipsend/dlcommon.c b/contrib/ipfilter/ipsend/dlcommon.c deleted file mode 100644 index 55bc942..0000000 --- a/contrib/ipfilter/ipsend/dlcommon.c +++ /dev/null @@ -1,1383 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Common (shared) DLPI test routines. - * Mostly pretty boring boilerplate sorta stuff. - * These can be split into individual library routines later - * but it's just convenient to keep them in a single file - * while they're being developed. - * - * Not supported: - * Connection Oriented stuff - * QOS stuff - */ - -/* -typedef unsigned long ulong; -*/ - - -#include <sys/types.h> -#include <sys/stream.h> -#include <sys/stropts.h> -#ifdef __osf__ -# include <sys/dlpihdr.h> -#else -# include <sys/dlpi.h> -#endif -#include <sys/signal.h> -#include <stdio.h> -#include <string.h> -#include "dltest.h" - -#define CASERET(s) case s: return ("s") - - char *dlprim(); - char *dlstate(); - char *dlerrno(); - char *dlpromisclevel(); - char *dlservicemode(); - char *dlstyle(); - char *dlmactype(); - - -void -dlinforeq(fd) - int fd; -{ - dl_info_req_t info_req; - struct strbuf ctl; - int flags; - - info_req.dl_primitive = DL_INFO_REQ; - - ctl.maxlen = 0; - ctl.len = sizeof (info_req); - ctl.buf = (char *) &info_req; - - flags = RS_HIPRI; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlinforeq: putmsg"); -} - -void -dlinfoack(fd, bufp) - int fd; - char *bufp; -{ - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - ctl.maxlen = MAXDLBUF; - ctl.len = 0; - ctl.buf = bufp; - - strgetmsg(fd, &ctl, (struct strbuf*)NULL, &flags, "dlinfoack"); - - dlp = (union DL_primitives *) ctl.buf; - - expecting(DL_INFO_ACK, dlp); - - if (ctl.len < sizeof (dl_info_ack_t)) - err("dlinfoack: response ctl.len too short: %d", ctl.len); - - if (flags != RS_HIPRI) - err("dlinfoack: DL_INFO_ACK was not M_PCPROTO"); - - if (ctl.len < sizeof (dl_info_ack_t)) - err("dlinfoack: short response ctl.len: %d", ctl.len); -} - -void -dlattachreq(fd, ppa) - int fd; - u_long ppa; -{ - dl_attach_req_t attach_req; - struct strbuf ctl; - int flags; - - attach_req.dl_primitive = DL_ATTACH_REQ; - attach_req.dl_ppa = ppa; - - ctl.maxlen = 0; - ctl.len = sizeof (attach_req); - ctl.buf = (char *) &attach_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlattachreq: putmsg"); -} - -void -dlenabmultireq(fd, addr, length) - int fd; - char *addr; - int length; -{ - long buf[MAXDLBUF]; - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - dlp = (union DL_primitives*) buf; - - dlp->enabmulti_req.dl_primitive = DL_ENABMULTI_REQ; - dlp->enabmulti_req.dl_addr_length = length; - dlp->enabmulti_req.dl_addr_offset = sizeof (dl_enabmulti_req_t); - - (void) memcpy((char*)OFFADDR(buf, sizeof (dl_enabmulti_req_t)), addr, length); - - ctl.maxlen = 0; - ctl.len = sizeof (dl_enabmulti_req_t) + length; - ctl.buf = (char*) buf; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlenabmultireq: putmsg"); -} - -void -dldisabmultireq(fd, addr, length) - int fd; - char *addr; - int length; -{ - long buf[MAXDLBUF]; - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - dlp = (union DL_primitives*) buf; - - dlp->disabmulti_req.dl_primitive = DL_ENABMULTI_REQ; - dlp->disabmulti_req.dl_addr_length = length; - dlp->disabmulti_req.dl_addr_offset = sizeof (dl_disabmulti_req_t); - - (void) memcpy((char*)OFFADDR(buf, sizeof (dl_disabmulti_req_t)), addr, length); - - ctl.maxlen = 0; - ctl.len = sizeof (dl_disabmulti_req_t) + length; - ctl.buf = (char*) buf; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dldisabmultireq: putmsg"); -} - -void -dlpromisconreq(fd, level) - int fd; - u_long level; -{ - dl_promiscon_req_t promiscon_req; - struct strbuf ctl; - int flags; - - promiscon_req.dl_primitive = DL_PROMISCON_REQ; - promiscon_req.dl_level = level; - - ctl.maxlen = 0; - ctl.len = sizeof (promiscon_req); - ctl.buf = (char *) &promiscon_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlpromiscon: putmsg"); - -} - -void -dlpromiscoff(fd, level) - int fd; - u_long level; -{ - dl_promiscoff_req_t promiscoff_req; - struct strbuf ctl; - int flags; - - promiscoff_req.dl_primitive = DL_PROMISCOFF_REQ; - promiscoff_req.dl_level = level; - - ctl.maxlen = 0; - ctl.len = sizeof (promiscoff_req); - ctl.buf = (char *) &promiscoff_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlpromiscoff: putmsg"); -} - -void -dlphysaddrreq(fd, addrtype) - int fd; - u_long addrtype; -{ - dl_phys_addr_req_t phys_addr_req; - struct strbuf ctl; - int flags; - - phys_addr_req.dl_primitive = DL_PHYS_ADDR_REQ; - phys_addr_req.dl_addr_type = addrtype; - - ctl.maxlen = 0; - ctl.len = sizeof (phys_addr_req); - ctl.buf = (char *) &phys_addr_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlphysaddrreq: putmsg"); -} - -void -dlsetphysaddrreq(fd, addr, length) - int fd; - char *addr; - int length; -{ - long buf[MAXDLBUF]; - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - dlp = (union DL_primitives*) buf; - - dlp->set_physaddr_req.dl_primitive = DL_ENABMULTI_REQ; - dlp->set_physaddr_req.dl_addr_length = length; - dlp->set_physaddr_req.dl_addr_offset = sizeof (dl_set_phys_addr_req_t); - - (void) memcpy((char*)OFFADDR(buf, sizeof (dl_set_phys_addr_req_t)), addr, length); - - ctl.maxlen = 0; - ctl.len = sizeof (dl_set_phys_addr_req_t) + length; - ctl.buf = (char*) buf; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlsetphysaddrreq: putmsg"); -} - -void -dldetachreq(fd) - int fd; -{ - dl_detach_req_t detach_req; - struct strbuf ctl; - int flags; - - detach_req.dl_primitive = DL_DETACH_REQ; - - ctl.maxlen = 0; - ctl.len = sizeof (detach_req); - ctl.buf = (char *) &detach_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dldetachreq: putmsg"); -} - -void -dlbindreq(fd, sap, max_conind, service_mode, conn_mgmt, xidtest) - int fd; - u_long sap; - u_long max_conind; - u_long service_mode; - u_long conn_mgmt; - u_long xidtest; -{ - dl_bind_req_t bind_req; - struct strbuf ctl; - int flags; - - bind_req.dl_primitive = DL_BIND_REQ; - bind_req.dl_sap = sap; - bind_req.dl_max_conind = max_conind; - bind_req.dl_service_mode = service_mode; - bind_req.dl_conn_mgmt = conn_mgmt; - bind_req.dl_xidtest_flg = xidtest; - - ctl.maxlen = 0; - ctl.len = sizeof (bind_req); - ctl.buf = (char *) &bind_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlbindreq: putmsg"); -} - -void -dlunitdatareq(fd, addrp, addrlen, minpri, maxpri, datap, datalen) - int fd; - u_char *addrp; - int addrlen; - u_long minpri, maxpri; - u_char *datap; - int datalen; -{ - long buf[MAXDLBUF]; - union DL_primitives *dlp; - struct strbuf data, ctl; - - dlp = (union DL_primitives*) buf; - - dlp->unitdata_req.dl_primitive = DL_UNITDATA_REQ; - dlp->unitdata_req.dl_dest_addr_length = addrlen; - dlp->unitdata_req.dl_dest_addr_offset = sizeof (dl_unitdata_req_t); - dlp->unitdata_req.dl_priority.dl_min = minpri; - dlp->unitdata_req.dl_priority.dl_max = maxpri; - - (void) memcpy(OFFADDR(dlp, sizeof (dl_unitdata_req_t)), addrp, addrlen); - - ctl.maxlen = 0; - ctl.len = sizeof (dl_unitdata_req_t) + addrlen; - ctl.buf = (char *) buf; - - data.maxlen = 0; - data.len = datalen; - data.buf = (char *) datap; - - if (putmsg(fd, &ctl, &data, 0) < 0) - syserr("dlunitdatareq: putmsg"); -} - -void -dlunbindreq(fd) - int fd; -{ - dl_unbind_req_t unbind_req; - struct strbuf ctl; - int flags; - - unbind_req.dl_primitive = DL_UNBIND_REQ; - - ctl.maxlen = 0; - ctl.len = sizeof (unbind_req); - ctl.buf = (char *) &unbind_req; - - flags = 0; - - if (putmsg(fd, &ctl, (struct strbuf*) NULL, flags) < 0) - syserr("dlunbindreq: putmsg"); -} - -void -dlokack(fd, bufp) - int fd; - char *bufp; -{ - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - ctl.maxlen = MAXDLBUF; - ctl.len = 0; - ctl.buf = bufp; - - strgetmsg(fd, &ctl, (struct strbuf*)NULL, &flags, "dlokack"); - - dlp = (union DL_primitives *) ctl.buf; - - expecting(DL_OK_ACK, dlp); - - if (ctl.len < sizeof (dl_ok_ack_t)) - err("dlokack: response ctl.len too short: %d", ctl.len); - - if (flags != RS_HIPRI) - err("dlokack: DL_OK_ACK was not M_PCPROTO"); - - if (ctl.len < sizeof (dl_ok_ack_t)) - err("dlokack: short response ctl.len: %d", ctl.len); -} - -void -dlerrorack(fd, bufp) - int fd; - char *bufp; -{ - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - ctl.maxlen = MAXDLBUF; - ctl.len = 0; - ctl.buf = bufp; - - strgetmsg(fd, &ctl, (struct strbuf*)NULL, &flags, "dlerrorack"); - - dlp = (union DL_primitives *) ctl.buf; - - expecting(DL_ERROR_ACK, dlp); - - if (ctl.len < sizeof (dl_error_ack_t)) - err("dlerrorack: response ctl.len too short: %d", ctl.len); - - if (flags != RS_HIPRI) - err("dlerrorack: DL_OK_ACK was not M_PCPROTO"); - - if (ctl.len < sizeof (dl_error_ack_t)) - err("dlerrorack: short response ctl.len: %d", ctl.len); -} - -void -dlbindack(fd, bufp) - int fd; - char *bufp; -{ - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - ctl.maxlen = MAXDLBUF; - ctl.len = 0; - ctl.buf = bufp; - - strgetmsg(fd, &ctl, (struct strbuf*)NULL, &flags, "dlbindack"); - - dlp = (union DL_primitives *) ctl.buf; - - expecting(DL_BIND_ACK, dlp); - - if (flags != RS_HIPRI) - err("dlbindack: DL_OK_ACK was not M_PCPROTO"); - - if (ctl.len < sizeof (dl_bind_ack_t)) - err("dlbindack: short response ctl.len: %d", ctl.len); -} - -void -dlphysaddrack(fd, bufp) - int fd; - char *bufp; -{ - union DL_primitives *dlp; - struct strbuf ctl; - int flags; - - ctl.maxlen = MAXDLBUF; - ctl.len = 0; - ctl.buf = bufp; - - strgetmsg(fd, &ctl, (struct strbuf*)NULL, &flags, "dlphysaddrack"); - - dlp = (union DL_primitives *) ctl.buf; - - expecting(DL_PHYS_ADDR_ACK, dlp); - - if (flags != RS_HIPRI) - err("dlbindack: DL_OK_ACK was not M_PCPROTO"); - - if (ctl.len < sizeof (dl_phys_addr_ack_t)) - err("dlphysaddrack: short response ctl.len: %d", ctl.len); -} - -void -sigalrm() -{ - (void) err("sigalrm: TIMEOUT"); -} - -strgetmsg(fd, ctlp, datap, flagsp, caller) - int fd; - struct strbuf *ctlp, *datap; - int *flagsp; - char *caller; -{ - int rc; - static char errmsg[80]; - - /* - * Start timer. - */ - (void) signal(SIGALRM, sigalrm); - if (alarm(MAXWAIT) < 0) { - (void) sprintf(errmsg, "%s: alarm", caller); - syserr(errmsg); - } - - /* - * Set flags argument and issue getmsg(). - */ - *flagsp = 0; - if ((rc = getmsg(fd, ctlp, datap, flagsp)) < 0) { - (void) sprintf(errmsg, "%s: getmsg", caller); - syserr(errmsg); - } - - /* - * Stop timer. - */ - if (alarm(0) < 0) { - (void) sprintf(errmsg, "%s: alarm", caller); - syserr(errmsg); - } - - /* - * Check for MOREDATA and/or MORECTL. - */ - if ((rc & (MORECTL | MOREDATA)) == (MORECTL | MOREDATA)) - err("%s: MORECTL|MOREDATA", caller); - if (rc & MORECTL) - err("%s: MORECTL", caller); - if (rc & MOREDATA) - err("%s: MOREDATA", caller); - - /* - * Check for at least sizeof (long) control data portion. - */ - if (ctlp->len < sizeof (long)) - err("getmsg: control portion length < sizeof (long): %d", ctlp->len); -} - -expecting(prim, dlp) - int prim; - union DL_primitives *dlp; -{ - if (dlp->dl_primitive != (u_long)prim) { - printdlprim(dlp); - err("expected %s got %s", dlprim(prim), - dlprim(dlp->dl_primitive)); - exit(1); - } -} - -/* - * Print any DLPI msg in human readable format. - */ -printdlprim(dlp) - union DL_primitives *dlp; -{ - switch (dlp->dl_primitive) { - case DL_INFO_REQ: - printdlinforeq(dlp); - break; - - case DL_INFO_ACK: - printdlinfoack(dlp); - break; - - case DL_ATTACH_REQ: - printdlattachreq(dlp); - break; - - case DL_OK_ACK: - printdlokack(dlp); - break; - - case DL_ERROR_ACK: - printdlerrorack(dlp); - break; - - case DL_DETACH_REQ: - printdldetachreq(dlp); - break; - - case DL_BIND_REQ: - printdlbindreq(dlp); - break; - - case DL_BIND_ACK: - printdlbindack(dlp); - break; - - case DL_UNBIND_REQ: - printdlunbindreq(dlp); - break; - - case DL_SUBS_BIND_REQ: - printdlsubsbindreq(dlp); - break; - - case DL_SUBS_BIND_ACK: - printdlsubsbindack(dlp); - break; - - case DL_SUBS_UNBIND_REQ: - printdlsubsunbindreq(dlp); - break; - - case DL_ENABMULTI_REQ: - printdlenabmultireq(dlp); - break; - - case DL_DISABMULTI_REQ: - printdldisabmultireq(dlp); - break; - - case DL_PROMISCON_REQ: - printdlpromisconreq(dlp); - break; - - case DL_PROMISCOFF_REQ: - printdlpromiscoffreq(dlp); - break; - - case DL_UNITDATA_REQ: - printdlunitdatareq(dlp); - break; - - case DL_UNITDATA_IND: - printdlunitdataind(dlp); - break; - - case DL_UDERROR_IND: - printdluderrorind(dlp); - break; - - case DL_UDQOS_REQ: - printdludqosreq(dlp); - break; - - case DL_PHYS_ADDR_REQ: - printdlphysaddrreq(dlp); - break; - - case DL_PHYS_ADDR_ACK: - printdlphysaddrack(dlp); - break; - - case DL_SET_PHYS_ADDR_REQ: - printdlsetphysaddrreq(dlp); - break; - - default: - err("printdlprim: unknown primitive type 0x%x", - dlp->dl_primitive); - break; - } -} - -/* ARGSUSED */ -printdlinforeq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_INFO_REQ\n"); -} - -printdlinfoack(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - u_char brdcst[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->info_ack.dl_addr_offset), - dlp->info_ack.dl_addr_length, addr); - addrtostring(OFFADDR(dlp, dlp->info_ack.dl_brdcst_addr_offset), - dlp->info_ack.dl_brdcst_addr_length, brdcst); - - (void) printf("DL_INFO_ACK: max_sdu %d min_sdu %d\n", - dlp->info_ack.dl_max_sdu, - dlp->info_ack.dl_min_sdu); - (void) printf("addr_length %d mac_type %s current_state %s\n", - dlp->info_ack.dl_addr_length, - dlmactype(dlp->info_ack.dl_mac_type), - dlstate(dlp->info_ack.dl_current_state)); - (void) printf("sap_length %d service_mode %s qos_length %d\n", - dlp->info_ack.dl_sap_length, - dlservicemode(dlp->info_ack.dl_service_mode), - dlp->info_ack.dl_qos_length); - (void) printf("qos_offset %d qos_range_length %d qos_range_offset %d\n", - dlp->info_ack.dl_qos_offset, - dlp->info_ack.dl_qos_range_length, - dlp->info_ack.dl_qos_range_offset); - (void) printf("provider_style %s addr_offset %d version %d\n", - dlstyle(dlp->info_ack.dl_provider_style), - dlp->info_ack.dl_addr_offset, - dlp->info_ack.dl_version); - (void) printf("brdcst_addr_length %d brdcst_addr_offset %d\n", - dlp->info_ack.dl_brdcst_addr_length, - dlp->info_ack.dl_brdcst_addr_offset); - (void) printf("addr %s\n", addr); - (void) printf("brdcst_addr %s\n", brdcst); -} - -printdlattachreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_ATTACH_REQ: ppa %d\n", - dlp->attach_req.dl_ppa); -} - -printdlokack(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_OK_ACK: correct_primitive %s\n", - dlprim(dlp->ok_ack.dl_correct_primitive)); -} - -printdlerrorack(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_ERROR_ACK: error_primitive %s errno %s unix_errno %d: %s\n", - dlprim(dlp->error_ack.dl_error_primitive), - dlerrno(dlp->error_ack.dl_errno), - dlp->error_ack.dl_unix_errno, - strerror(dlp->error_ack.dl_unix_errno)); -} - -printdlenabmultireq(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->enabmulti_req.dl_addr_offset), - dlp->enabmulti_req.dl_addr_length, addr); - - (void) printf("DL_ENABMULTI_REQ: addr_length %d addr_offset %d\n", - dlp->enabmulti_req.dl_addr_length, - dlp->enabmulti_req.dl_addr_offset); - (void) printf("addr %s\n", addr); -} - -printdldisabmultireq(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->disabmulti_req.dl_addr_offset), - dlp->disabmulti_req.dl_addr_length, addr); - - (void) printf("DL_DISABMULTI_REQ: addr_length %d addr_offset %d\n", - dlp->disabmulti_req.dl_addr_length, - dlp->disabmulti_req.dl_addr_offset); - (void) printf("addr %s\n", addr); -} - -printdlpromisconreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_PROMISCON_REQ: level %s\n", - dlpromisclevel(dlp->promiscon_req.dl_level)); -} - -printdlpromiscoffreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_PROMISCOFF_REQ: level %s\n", - dlpromisclevel(dlp->promiscoff_req.dl_level)); -} - -printdlphysaddrreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_PHYS_ADDR_REQ: addr_type 0x%x\n", - dlp->physaddr_req.dl_addr_type); -} - -printdlphysaddrack(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->physaddr_ack.dl_addr_offset), - dlp->physaddr_ack.dl_addr_length, addr); - - (void) printf("DL_PHYS_ADDR_ACK: addr_length %d addr_offset %d\n", - dlp->physaddr_ack.dl_addr_length, - dlp->physaddr_ack.dl_addr_offset); - (void) printf("addr %s\n", addr); -} - -printdlsetphysaddrreq(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->set_physaddr_req.dl_addr_offset), - dlp->set_physaddr_req.dl_addr_length, addr); - - (void) printf("DL_SET_PHYS_ADDR_REQ: addr_length %d addr_offset %d\n", - dlp->set_physaddr_req.dl_addr_length, - dlp->set_physaddr_req.dl_addr_offset); - (void) printf("addr %s\n", addr); -} - -/* ARGSUSED */ -printdldetachreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_DETACH_REQ\n"); -} - -printdlbindreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_BIND_REQ: sap %d max_conind %d\n", - dlp->bind_req.dl_sap, - dlp->bind_req.dl_max_conind); - (void) printf("service_mode %s conn_mgmt %d xidtest_flg 0x%x\n", - dlservicemode(dlp->bind_req.dl_service_mode), - dlp->bind_req.dl_conn_mgmt, - dlp->bind_req.dl_xidtest_flg); -} - -printdlbindack(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->bind_ack.dl_addr_offset), - dlp->bind_ack.dl_addr_length, addr); - - (void) printf("DL_BIND_ACK: sap %d addr_length %d addr_offset %d\n", - dlp->bind_ack.dl_sap, - dlp->bind_ack.dl_addr_length, - dlp->bind_ack.dl_addr_offset); - (void) printf("max_conind %d xidtest_flg 0x%x\n", - dlp->bind_ack.dl_max_conind, - dlp->bind_ack.dl_xidtest_flg); - (void) printf("addr %s\n", addr); -} - -/* ARGSUSED */ -printdlunbindreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_UNBIND_REQ\n"); -} - -printdlsubsbindreq(dlp) - union DL_primitives *dlp; -{ - u_char sap[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->subs_bind_req.dl_subs_sap_offset), - dlp->subs_bind_req.dl_subs_sap_length, sap); - - (void) printf("DL_SUBS_BIND_REQ: subs_sap_offset %d sub_sap_len %d\n", - dlp->subs_bind_req.dl_subs_sap_offset, - dlp->subs_bind_req.dl_subs_sap_length); - (void) printf("sap %s\n", sap); -} - -printdlsubsbindack(dlp) - union DL_primitives *dlp; -{ - u_char sap[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->subs_bind_ack.dl_subs_sap_offset), - dlp->subs_bind_ack.dl_subs_sap_length, sap); - - (void) printf("DL_SUBS_BIND_ACK: subs_sap_offset %d sub_sap_length %d\n", - dlp->subs_bind_ack.dl_subs_sap_offset, - dlp->subs_bind_ack.dl_subs_sap_length); - (void) printf("sap %s\n", sap); -} - -printdlsubsunbindreq(dlp) - union DL_primitives *dlp; -{ - u_char sap[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->subs_unbind_req.dl_subs_sap_offset), - dlp->subs_unbind_req.dl_subs_sap_length, sap); - - (void) printf("DL_SUBS_UNBIND_REQ: subs_sap_offset %d sub_sap_length %d\n", - dlp->subs_unbind_req.dl_subs_sap_offset, - dlp->subs_unbind_req.dl_subs_sap_length); - (void) printf("sap %s\n", sap); -} - -printdlunitdatareq(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->unitdata_req.dl_dest_addr_offset), - dlp->unitdata_req.dl_dest_addr_length, addr); - - (void) printf("DL_UNITDATA_REQ: dest_addr_length %d dest_addr_offset %d\n", - dlp->unitdata_req.dl_dest_addr_length, - dlp->unitdata_req.dl_dest_addr_offset); - (void) printf("dl_priority.min %d dl_priority.max %d\n", - dlp->unitdata_req.dl_priority.dl_min, - dlp->unitdata_req.dl_priority.dl_max); - (void) printf("addr %s\n", addr); -} - -printdlunitdataind(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - u_char src[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->unitdata_ind.dl_dest_addr_offset), - dlp->unitdata_ind.dl_dest_addr_length, dest); - addrtostring(OFFADDR(dlp, dlp->unitdata_ind.dl_src_addr_offset), - dlp->unitdata_ind.dl_src_addr_length, src); - - (void) printf("DL_UNITDATA_IND: dest_addr_length %d dest_addr_offset %d\n", - dlp->unitdata_ind.dl_dest_addr_length, - dlp->unitdata_ind.dl_dest_addr_offset); - (void) printf("src_addr_length %d src_addr_offset %d\n", - dlp->unitdata_ind.dl_src_addr_length, - dlp->unitdata_ind.dl_src_addr_offset); - (void) printf("group_address 0x%x\n", - dlp->unitdata_ind.dl_group_address); - (void) printf("dest %s\n", dest); - (void) printf("src %s\n", src); -} - -printdluderrorind(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->uderror_ind.dl_dest_addr_offset), - dlp->uderror_ind.dl_dest_addr_length, addr); - - (void) printf("DL_UDERROR_IND: dest_addr_length %d dest_addr_offset %d\n", - dlp->uderror_ind.dl_dest_addr_length, - dlp->uderror_ind.dl_dest_addr_offset); - (void) printf("unix_errno %d errno %s\n", - dlp->uderror_ind.dl_unix_errno, - dlerrno(dlp->uderror_ind.dl_errno)); - (void) printf("addr %s\n", addr); -} - -printdltestreq(dlp) - union DL_primitives *dlp; -{ - u_char addr[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->test_req.dl_dest_addr_offset), - dlp->test_req.dl_dest_addr_length, addr); - - (void) printf("DL_TEST_REQ: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->test_req.dl_flag, - dlp->test_req.dl_dest_addr_length, - dlp->test_req.dl_dest_addr_offset); - (void) printf("dest_addr %s\n", addr); -} - -printdltestind(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - u_char src[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->test_ind.dl_dest_addr_offset), - dlp->test_ind.dl_dest_addr_length, dest); - addrtostring(OFFADDR(dlp, dlp->test_ind.dl_src_addr_offset), - dlp->test_ind.dl_src_addr_length, src); - - (void) printf("DL_TEST_IND: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->test_ind.dl_flag, - dlp->test_ind.dl_dest_addr_length, - dlp->test_ind.dl_dest_addr_offset); - (void) printf("src_addr_length %d src_addr_offset %d\n", - dlp->test_ind.dl_src_addr_length, - dlp->test_ind.dl_src_addr_offset); - (void) printf("dest_addr %s\n", dest); - (void) printf("src_addr %s\n", src); -} - -printdltestres(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->test_res.dl_dest_addr_offset), - dlp->test_res.dl_dest_addr_length, dest); - - (void) printf("DL_TEST_RES: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->test_res.dl_flag, - dlp->test_res.dl_dest_addr_length, - dlp->test_res.dl_dest_addr_offset); - (void) printf("dest_addr %s\n", dest); -} - -printdltestcon(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - u_char src[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->test_con.dl_dest_addr_offset), - dlp->test_con.dl_dest_addr_length, dest); - addrtostring(OFFADDR(dlp, dlp->test_con.dl_src_addr_offset), - dlp->test_con.dl_src_addr_length, src); - - (void) printf("DL_TEST_CON: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->test_con.dl_flag, - dlp->test_con.dl_dest_addr_length, - dlp->test_con.dl_dest_addr_offset); - (void) printf("src_addr_length %d src_addr_offset %d\n", - dlp->test_con.dl_src_addr_length, - dlp->test_con.dl_src_addr_offset); - (void) printf("dest_addr %s\n", dest); - (void) printf("src_addr %s\n", src); -} - -printdlxidreq(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->xid_req.dl_dest_addr_offset), - dlp->xid_req.dl_dest_addr_length, dest); - - (void) printf("DL_XID_REQ: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->xid_req.dl_flag, - dlp->xid_req.dl_dest_addr_length, - dlp->xid_req.dl_dest_addr_offset); - (void) printf("dest_addr %s\n", dest); -} - -printdlxidind(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - u_char src[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->xid_ind.dl_dest_addr_offset), - dlp->xid_ind.dl_dest_addr_length, dest); - addrtostring(OFFADDR(dlp, dlp->xid_ind.dl_src_addr_offset), - dlp->xid_ind.dl_src_addr_length, src); - - (void) printf("DL_XID_IND: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->xid_ind.dl_flag, - dlp->xid_ind.dl_dest_addr_length, - dlp->xid_ind.dl_dest_addr_offset); - (void) printf("src_addr_length %d src_addr_offset %d\n", - dlp->xid_ind.dl_src_addr_length, - dlp->xid_ind.dl_src_addr_offset); - (void) printf("dest_addr %s\n", dest); - (void) printf("src_addr %s\n", src); -} - -printdlxidres(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->xid_res.dl_dest_addr_offset), - dlp->xid_res.dl_dest_addr_length, dest); - - (void) printf("DL_XID_RES: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->xid_res.dl_flag, - dlp->xid_res.dl_dest_addr_length, - dlp->xid_res.dl_dest_addr_offset); - (void) printf("dest_addr %s\n", dest); -} - -printdlxidcon(dlp) - union DL_primitives *dlp; -{ - u_char dest[MAXDLADDR]; - u_char src[MAXDLADDR]; - - addrtostring(OFFADDR(dlp, dlp->xid_con.dl_dest_addr_offset), - dlp->xid_con.dl_dest_addr_length, dest); - addrtostring(OFFADDR(dlp, dlp->xid_con.dl_src_addr_offset), - dlp->xid_con.dl_src_addr_length, src); - - (void) printf("DL_XID_CON: flag 0x%x dest_addr_length %d dest_addr_offset %d\n", - dlp->xid_con.dl_flag, - dlp->xid_con.dl_dest_addr_length, - dlp->xid_con.dl_dest_addr_offset); - (void) printf("src_addr_length %d src_addr_offset %d\n", - dlp->xid_con.dl_src_addr_length, - dlp->xid_con.dl_src_addr_offset); - (void) printf("dest_addr %s\n", dest); - (void) printf("src_addr %s\n", src); -} - -printdludqosreq(dlp) - union DL_primitives *dlp; -{ - (void) printf("DL_UDQOS_REQ: qos_length %d qos_offset %d\n", - dlp->udqos_req.dl_qos_length, - dlp->udqos_req.dl_qos_offset); -} - -/* - * Return string. - */ -addrtostring(addr, length, s) - u_char *addr; - u_long length; - u_char *s; -{ - int i; - - for (i = 0; i < length; i++) { - (void) sprintf((char*) s, "%x:", addr[i] & 0xff); - s = s + strlen((char*)s); - } - if (length) - *(--s) = '\0'; -} - -/* - * Return length - */ -stringtoaddr(sp, addr) - char *sp; - char *addr; -{ - int n = 0; - char *p; - int val; - - p = sp; - while (p = strtok(p, ":")) { - if (sscanf(p, "%x", &val) != 1) - err("stringtoaddr: invalid input string: %s", sp); - if (val > 0xff) - err("stringtoaddr: invalid input string: %s", sp); - *addr++ = val; - n++; - p = NULL; - } - - return (n); -} - - -static char -hexnibble(c) - char c; -{ - static char hextab[] = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' - }; - - return (hextab[c & 0x0f]); -} - -char* -dlprim(prim) - u_long prim; -{ - static char primbuf[80]; - - switch ((int)prim) { - CASERET(DL_INFO_REQ); - CASERET(DL_INFO_ACK); - CASERET(DL_ATTACH_REQ); - CASERET(DL_DETACH_REQ); - CASERET(DL_BIND_REQ); - CASERET(DL_BIND_ACK); - CASERET(DL_UNBIND_REQ); - CASERET(DL_OK_ACK); - CASERET(DL_ERROR_ACK); - CASERET(DL_SUBS_BIND_REQ); - CASERET(DL_SUBS_BIND_ACK); - CASERET(DL_UNITDATA_REQ); - CASERET(DL_UNITDATA_IND); - CASERET(DL_UDERROR_IND); - CASERET(DL_UDQOS_REQ); - CASERET(DL_CONNECT_REQ); - CASERET(DL_CONNECT_IND); - CASERET(DL_CONNECT_RES); - CASERET(DL_CONNECT_CON); - CASERET(DL_TOKEN_REQ); - CASERET(DL_TOKEN_ACK); - CASERET(DL_DISCONNECT_REQ); - CASERET(DL_DISCONNECT_IND); - CASERET(DL_RESET_REQ); - CASERET(DL_RESET_IND); - CASERET(DL_RESET_RES); - CASERET(DL_RESET_CON); - default: - (void) sprintf(primbuf, "unknown primitive 0x%x", prim); - return (primbuf); - } -} - - -char* -dlstate(state) - u_long state; -{ - static char statebuf[80]; - - switch (state) { - CASERET(DL_UNATTACHED); - CASERET(DL_ATTACH_PENDING); - CASERET(DL_DETACH_PENDING); - CASERET(DL_UNBOUND); - CASERET(DL_BIND_PENDING); - CASERET(DL_UNBIND_PENDING); - CASERET(DL_IDLE); - CASERET(DL_UDQOS_PENDING); - CASERET(DL_OUTCON_PENDING); - CASERET(DL_INCON_PENDING); - CASERET(DL_CONN_RES_PENDING); - CASERET(DL_DATAXFER); - CASERET(DL_USER_RESET_PENDING); - CASERET(DL_PROV_RESET_PENDING); - CASERET(DL_RESET_RES_PENDING); - CASERET(DL_DISCON8_PENDING); - CASERET(DL_DISCON9_PENDING); - CASERET(DL_DISCON11_PENDING); - CASERET(DL_DISCON12_PENDING); - CASERET(DL_DISCON13_PENDING); - CASERET(DL_SUBS_BIND_PND); - default: - (void) sprintf(statebuf, "unknown state 0x%x", state); - return (statebuf); - } -} - -char* -dlerrno(errno) - u_long errno; -{ - static char errnobuf[80]; - - switch (errno) { - CASERET(DL_ACCESS); - CASERET(DL_BADADDR); - CASERET(DL_BADCORR); - CASERET(DL_BADDATA); - CASERET(DL_BADPPA); - CASERET(DL_BADPRIM); - CASERET(DL_BADQOSPARAM); - CASERET(DL_BADQOSTYPE); - CASERET(DL_BADSAP); - CASERET(DL_BADTOKEN); - CASERET(DL_BOUND); - CASERET(DL_INITFAILED); - CASERET(DL_NOADDR); - CASERET(DL_NOTINIT); - CASERET(DL_OUTSTATE); - CASERET(DL_SYSERR); - CASERET(DL_UNSUPPORTED); - CASERET(DL_UNDELIVERABLE); - CASERET(DL_NOTSUPPORTED); - CASERET(DL_TOOMANY); - CASERET(DL_NOTENAB); - CASERET(DL_BUSY); - CASERET(DL_NOAUTO); - CASERET(DL_NOXIDAUTO); - CASERET(DL_NOTESTAUTO); - CASERET(DL_XIDAUTO); - CASERET(DL_TESTAUTO); - CASERET(DL_PENDING); - - default: - (void) sprintf(errnobuf, "unknown dlpi errno 0x%x", errno); - return (errnobuf); - } -} - -char* -dlpromisclevel(level) - u_long level; -{ - static char levelbuf[80]; - - switch (level) { - CASERET(DL_PROMISC_PHYS); - CASERET(DL_PROMISC_SAP); - CASERET(DL_PROMISC_MULTI); - default: - (void) sprintf(levelbuf, "unknown promisc level 0x%x", level); - return (levelbuf); - } -} - -char* -dlservicemode(servicemode) - u_long servicemode; -{ - static char servicemodebuf[80]; - - switch (servicemode) { - CASERET(DL_CODLS); - CASERET(DL_CLDLS); - CASERET(DL_CODLS|DL_CLDLS); - default: - (void) sprintf(servicemodebuf, - "unknown provider service mode 0x%x", servicemode); - return (servicemodebuf); - } -} - -char* -dlstyle(style) - long style; -{ - static char stylebuf[80]; - - switch (style) { - CASERET(DL_STYLE1); - CASERET(DL_STYLE2); - default: - (void) sprintf(stylebuf, "unknown provider style 0x%x", style); - return (stylebuf); - } -} - -char* -dlmactype(media) - u_long media; -{ - static char mediabuf[80]; - - switch (media) { - CASERET(DL_CSMACD); - CASERET(DL_TPB); - CASERET(DL_TPR); - CASERET(DL_METRO); - CASERET(DL_ETHER); - CASERET(DL_HDLC); - CASERET(DL_CHAR); - CASERET(DL_CTCA); - default: - (void) sprintf(mediabuf, "unknown media type 0x%x", media); - return (mediabuf); - } -} - -/*VARARGS1*/ -err(fmt, a1, a2, a3, a4) - char *fmt; - char *a1, *a2, *a3, *a4; -{ - (void) fprintf(stderr, fmt, a1, a2, a3, a4); - (void) fprintf(stderr, "\n"); - (void) exit(1); -} - -syserr(s) - char *s; -{ - (void) perror(s); - exit(1); -} - -strioctl(fd, cmd, timout, len, dp) - int fd; - int cmd; - int timout; - int len; - char *dp; -{ - struct strioctl sioc; - int rc; - - sioc.ic_cmd = cmd; - sioc.ic_timout = timout; - sioc.ic_len = len; - sioc.ic_dp = dp; - rc = ioctl(fd, I_STR, &sioc); - - if (rc < 0) - return (rc); - else - return (sioc.ic_len); -} diff --git a/contrib/ipfilter/ipsend/dltest.h b/contrib/ipfilter/ipsend/dltest.h deleted file mode 100644 index 086782c..0000000 --- a/contrib/ipfilter/ipsend/dltest.h +++ /dev/null @@ -1,34 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Common DLPI Test Suite header file - * - */ - -/* - * Maximum control/data buffer size (in long's !!) for getmsg(). - */ -#define MAXDLBUF 8192 - -/* - * Maximum number of seconds we'll wait for any - * particular DLPI acknowledgment from the provider - * after issuing a request. - */ -#define MAXWAIT 15 - -/* - * Maximum address buffer length. - */ -#define MAXDLADDR 1024 - - -/* - * Handy macro. - */ -#define OFFADDR(s, n) (u_char*)((char*)(s) + (int)(n)) - -/* - * externs go here - */ -extern void sigalrm(); diff --git a/contrib/ipfilter/ipsend/ip.c b/contrib/ipfilter/ipsend/ip.c deleted file mode 100644 index fc76170..0000000 --- a/contrib/ipfilter/ipsend/ip.c +++ /dev/null @@ -1,364 +0,0 @@ -/* $FreeBSD$ */ - -/* - * ip.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - */ -#if !defined(lint) -static const char sccsid[] = "%W% %G% (C)1995"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <netinet/in_systm.h> -#include <sys/socket.h> -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#include <sys/param.h> -#ifndef linux -# include <net/route.h> -# include <netinet/if_ether.h> -# include <netinet/ip_var.h> -#endif -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include "ipsend.h" - - -static char *ipbuf = NULL, *ethbuf = NULL; - - -u_short chksum(buf,len) - u_short *buf; - int len; -{ - u_long sum = 0; - int nwords = len >> 1; - - for(; nwords > 0; nwords--) - sum += *buf++; - sum = (sum>>16) + (sum & 0xffff); - sum += (sum >>16); - return (~sum); -} - - -int send_ether(nfd, buf, len, gwip) - int nfd, len; - char *buf; - struct in_addr gwip; -{ - static struct in_addr last_gw; - static char last_arp[6] = { 0, 0, 0, 0, 0, 0}; - ether_header_t *eh; - char *s; - int err; - - if (!ethbuf) - ethbuf = (char *)calloc(1, 65536+1024); - s = ethbuf; - eh = (ether_header_t *)s; - - bcopy((char *)buf, s + sizeof(*eh), len); - if (gwip.s_addr == last_gw.s_addr) - { - bcopy(last_arp, (char *)A_A eh->ether_dhost, 6); - } - else if (arp((char *)&gwip, (char *)A_A eh->ether_dhost) == -1) - { - perror("arp"); - return -2; - } - eh->ether_type = htons(ETHERTYPE_IP); - last_gw.s_addr = gwip.s_addr; - err = sendip(nfd, s, sizeof(*eh) + len); - return err; -} - - -/* - */ -int send_ip(nfd, mtu, ip, gwip, frag) - int nfd, mtu; - ip_t *ip; - struct in_addr gwip; - int frag; -{ - static struct in_addr last_gw, local_ip; - static char local_arp[6] = { 0, 0, 0, 0, 0, 0}; - static char last_arp[6] = { 0, 0, 0, 0, 0, 0}; - static u_short id = 0; - ether_header_t *eh; - ip_t ipsv; - int err, iplen; - - if (!ipbuf) - { - ipbuf = (char *)malloc(65536); - if (!ipbuf) - { - perror("malloc failed"); - return -2; - } - } - - eh = (ether_header_t *)ipbuf; - - bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost)); - if (last_gw.s_addr && (gwip.s_addr == last_gw.s_addr)) - { - bcopy(last_arp, (char *)A_A eh->ether_dhost, 6); - } - else if (arp((char *)&gwip, (char *)A_A eh->ether_dhost) == -1) - { - perror("arp"); - return -2; - } - bcopy((char *)A_A eh->ether_dhost, last_arp, sizeof(last_arp)); - eh->ether_type = htons(ETHERTYPE_IP); - - bcopy((char *)ip, (char *)&ipsv, sizeof(*ip)); - last_gw.s_addr = gwip.s_addr; - iplen = ip->ip_len; - ip->ip_len = htons(iplen); - if (!(frag & 2)) { - if (!IP_V(ip)) - IP_V_A(ip, IPVERSION); - if (!ip->ip_id) - ip->ip_id = htons(id++); - if (!ip->ip_ttl) - ip->ip_ttl = 60; - } - - if (ip->ip_src.s_addr != local_ip.s_addr) { - (void) arp((char *)&ip->ip_src, (char *)A_A local_arp); - bcopy(local_arp, (char *)A_A eh->ether_shost,sizeof(last_arp)); - local_ip = ip->ip_src; - } else - bcopy(local_arp, (char *)A_A eh->ether_shost, 6); - - if (!frag || (sizeof(*eh) + iplen < mtu)) - { - ip->ip_sum = 0; - ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); - - bcopy((char *)ip, ipbuf + sizeof(*eh), iplen); - err = sendip(nfd, ipbuf, sizeof(*eh) + iplen); - } - else - { - /* - * Actually, this is bogus because we're putting all IP - * options in every packet, which isn't always what should be - * done. Will do for now. - */ - ether_header_t eth; - char optcpy[48], ol; - char *s; - int i, sent = 0, ts, hlen, olen; - - hlen = IP_HL(ip) << 2; - if (mtu < (hlen + 8)) { - fprintf(stderr, "mtu (%d) < ip header size (%d) + 8\n", - mtu, hlen); - fprintf(stderr, "can't fragment data\n"); - return -2; - } - ol = (IP_HL(ip) << 2) - sizeof(*ip); - for (i = 0, s = (char*)(ip + 1); ol > 0; ) - if (*s == IPOPT_EOL) { - optcpy[i++] = *s; - break; - } else if (*s == IPOPT_NOP) { - s++; - ol--; - } else - { - olen = (int)(*(u_char *)(s + 1)); - ol -= olen; - if (IPOPT_COPIED(*s)) - { - bcopy(s, optcpy + i, olen); - i += olen; - s += olen; - } - } - if (i) - { - /* - * pad out - */ - while ((i & 3) && (i & 3) != 3) - optcpy[i++] = IPOPT_NOP; - if ((i & 3) == 3) - optcpy[i++] = IPOPT_EOL; - } - - bcopy((char *)eh, (char *)ð, sizeof(eth)); - s = (char *)ip + hlen; - iplen = ntohs(ip->ip_len) - hlen; - ip->ip_off |= htons(IP_MF); - - while (1) - { - if ((sent + (mtu - hlen)) >= iplen) - { - ip->ip_off ^= htons(IP_MF); - ts = iplen - sent; - } - else - ts = (mtu - hlen); - ip->ip_off &= htons(0xe000); - ip->ip_off |= htons(sent >> 3); - ts += hlen; - ip->ip_len = htons(ts); - ip->ip_sum = 0; - ip->ip_sum = chksum((u_short *)ip, hlen); - bcopy((char *)ip, ipbuf + sizeof(*eh), hlen); - bcopy(s + sent, ipbuf + sizeof(*eh) + hlen, ts - hlen); - err = sendip(nfd, ipbuf, sizeof(*eh) + ts); - - bcopy((char *)ð, ipbuf, sizeof(eth)); - sent += (ts - hlen); - if (!(ntohs(ip->ip_off) & IP_MF)) - break; - else if (!(ip->ip_off & htons(0x1fff))) - { - hlen = i + sizeof(*ip); - IP_HL_A(ip, (sizeof(*ip) + i) >> 2); - bcopy(optcpy, (char *)(ip + 1), i); - } - } - } - - bcopy((char *)&ipsv, (char *)ip, sizeof(*ip)); - return err; -} - - -/* - * send a tcp packet. - */ -int send_tcp(nfd, mtu, ip, gwip) - int nfd, mtu; - ip_t *ip; - struct in_addr gwip; -{ - static tcp_seq iss = 2; - tcphdr_t *t, *t2; - int thlen, i, iplen, hlen; - u_32_t lbuf[20]; - ip_t *ip2; - - iplen = ip->ip_len; - hlen = IP_HL(ip) << 2; - t = (tcphdr_t *)((char *)ip + hlen); - ip2 = (struct ip *)lbuf; - t2 = (tcphdr_t *)((char *)ip2 + hlen); - thlen = TCP_OFF(t) << 2; - if (!thlen) - thlen = sizeof(tcphdr_t); - bzero((char *)ip2, sizeof(*ip2) + sizeof(*t2)); - ip->ip_p = IPPROTO_TCP; - ip2->ip_p = ip->ip_p; - ip2->ip_src = ip->ip_src; - ip2->ip_dst = ip->ip_dst; - bcopy((char *)ip + hlen, (char *)t2, thlen); - - if (!t2->th_win) - t2->th_win = htons(4096); - iss += 63; - - i = sizeof(struct tcpiphdr) / sizeof(long); - - if ((t2->th_flags == TH_SYN) && !ntohs(ip->ip_off) && - (lbuf[i] != htonl(0x020405b4))) { - lbuf[i] = htonl(0x020405b4); - bcopy((char *)ip + hlen + thlen, (char *)ip + hlen + thlen + 4, - iplen - thlen - hlen); - thlen += 4; - } - TCP_OFF_A(t2, thlen >> 2); - ip2->ip_len = htons(thlen); - ip->ip_len = hlen + thlen; - t2->th_sum = 0; - t2->th_sum = chksum((u_short *)ip2, thlen + sizeof(ip_t)); - - bcopy((char *)t2, (char *)ip + hlen, thlen); - return send_ip(nfd, mtu, ip, gwip, 1); -} - - -/* - * send a udp packet. - */ -int send_udp(nfd, mtu, ip, gwip) - int nfd, mtu; - ip_t *ip; - struct in_addr gwip; -{ - struct tcpiphdr *ti; - int thlen; - u_long lbuf[20]; - - ti = (struct tcpiphdr *)lbuf; - bzero((char *)ti, sizeof(*ti)); - thlen = sizeof(udphdr_t); - ti->ti_pr = ip->ip_p; - ti->ti_src = ip->ip_src; - ti->ti_dst = ip->ip_dst; - bcopy((char *)ip + (IP_HL(ip) << 2), - (char *)&ti->ti_sport, sizeof(udphdr_t)); - - ti->ti_len = htons(thlen); - ip->ip_len = (IP_HL(ip) << 2) + thlen; - ti->ti_sum = 0; - ti->ti_sum = chksum((u_short *)ti, thlen + sizeof(ip_t)); - - bcopy((char *)&ti->ti_sport, - (char *)ip + (IP_HL(ip) << 2), sizeof(udphdr_t)); - return send_ip(nfd, mtu, ip, gwip, 1); -} - - -/* - * send an icmp packet. - */ -int send_icmp(nfd, mtu, ip, gwip) - int nfd, mtu; - ip_t *ip; - struct in_addr gwip; -{ - struct icmp *ic; - - ic = (struct icmp *)((char *)ip + (IP_HL(ip) << 2)); - - ic->icmp_cksum = 0; - ic->icmp_cksum = chksum((u_short *)ic, sizeof(struct icmp)); - - return send_ip(nfd, mtu, ip, gwip, 1); -} - - -int send_packet(nfd, mtu, ip, gwip) - int nfd, mtu; - ip_t *ip; - struct in_addr gwip; -{ - switch (ip->ip_p) - { - case IPPROTO_TCP : - return send_tcp(nfd, mtu, ip, gwip); - case IPPROTO_UDP : - return send_udp(nfd, mtu, ip, gwip); - case IPPROTO_ICMP : - return send_icmp(nfd, mtu, ip, gwip); - default : - return send_ip(nfd, mtu, ip, gwip, 1); - } -} diff --git a/contrib/ipfilter/ipsend/ipresend.1 b/contrib/ipfilter/ipsend/ipresend.1 deleted file mode 100644 index 6761a18..0000000 --- a/contrib/ipfilter/ipsend/ipresend.1 +++ /dev/null @@ -1,108 +0,0 @@ -.\" $FreeBSD$ -.\" -.TH IPRESEND 1 -.SH NAME -ipresend \- resend IP packets out to network -.SH SYNOPSIS -.B ipresend -[ -.B \-EHPRSTX -] [ -.B \-d -<device> -] [ -.B \-g -<\fIgateway\fP> -] [ -.B \-m -<\fIMTU\fP> -] [ -.B \-r -<\fIfilename\fP> -] -.SH DESCRIPTION -.PP -\fBipresend\fP was designed to allow packets to be resent, once captured, -back out onto the network for use in testing. \fIipresend\fP supports a -number of different file formats as input, including saved snoop/tcpdump -binary data. -.SH OPTIONS -.TP -.BR \-d \0<interface> -Set the interface name to be the name supplied. This is useful with the -\fB\-P, \-S, \-T\fP and \fB\-E\fP options, where it is not otherwise possible -to associate a packet with an interface. Normal "text packets" can override -this setting. -.TP -.BR \-g \0<gateway> -Specify the hostname of the gateway through which to route packets. This -is required whenever the destination host isn't directly attached to the -same network as the host from which you're sending. -.TP -.BR \-m \0<MTU> -Specify the MTU to be used when sending out packets. This option allows you -to set a fake MTU, allowing the simulation of network interfaces with small -MTU's without setting them so. -.TP -.BR \-r \0<filename> -Specify the filename from which to take input. Default is stdin. -.TP -.B \-E -The input file is to be text output from etherfind. The text formats which -are currently supported are those which result from the following etherfind -option combinations: -.PP -.nf - etherfind -n - etherfind -n -t -.fi -.LP -.TP -.B \-H -The input file is to be hex digits, representing the binary makeup of the -packet. No length correction is made, if an incorrect length is put in -the IP header. -.TP -.B \-P -The input file specified by \fB\-i\fP is a binary file produced using libpcap -(i.e., tcpdump version 3). Packets are read from this file as being input -(for rule purposes). -.TP -.B \-R -When sending packets out, send them out "raw" (the way they came in). The -only real significance here is that it will expect the link layer (i.e. -ethernet) headers to be prepended to the IP packet being output. -.TP -.B \-S -The input file is to be in "snoop" format (see RFC 1761). Packets are read -from this file and used as input from any interface. This is perhaps the -most useful input type, currently. -.TP -.B \-T -The input file is to be text output from tcpdump. The text formats which -are currently supported are those which result from the following tcpdump -option combinations: -.PP -.nf - tcpdump -n - tcpdump -nq - tcpdump -nqt - tcpdump -nqtt - tcpdump -nqte -.fi -.LP -.TP -.B \-X -The input file is composed of text descriptions of IP packets. -.DT -.SH SEE ALSO -snoop(1m), tcpdump(8), etherfind(8c), ipftest(1), ipresend(1), iptest(1), bpf(4), dlpi(7p) -.SH DIAGNOSTICS -.PP -Needs to be run as root. -.SH BUGS -.PP -Not all of the input formats are sufficiently capable of introducing a -wide enough variety of packets for them to be all useful in testing. -If you find any, please send email to me at darrenr@pobox.com - diff --git a/contrib/ipfilter/ipsend/ipresend.c b/contrib/ipfilter/ipsend/ipresend.c deleted file mode 100644 index 7520a0e..0000000 --- a/contrib/ipfilter/ipsend/ipresend.c +++ /dev/null @@ -1,151 +0,0 @@ -/* $FreeBSD$ */ - -/* - * ipresend.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#ifndef linux -#include <netinet/ip_var.h> -#endif -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <netdb.h> -#include <string.h> -#include "ipsend.h" - - -extern char *optarg; -extern int optind; -#ifndef NO_IPF -extern struct ipread pcap, iphex, iptext; -#endif - -int opts = 0; -#ifndef DEFAULT_DEVICE -# ifdef linux -char default_device[] = "eth0"; -# else -# ifdef sun -char default_device[] = "le0"; -# else -# ifdef ultrix -char default_device[] = "ln0"; -# else -# ifdef __bsdi__ -char default_device[] = "ef0"; -# else -# ifdef __sgi -char default_device[] = "ec0"; -# else -char default_device[] = "lan0"; -# endif -# endif -# endif -# endif -# endif -#else -char default_device[] = DEFAULT_DEVICE; -#endif - - -static void usage __P((char *)); -int main __P((int, char **)); - - -static void usage(prog) - char *prog; -{ - fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\ -\t\t-r filename\tsnoop data file to resend\n\ -\t\t-R filename\tlibpcap data file to resend\n\ -\toptions:\n\ -\t\t-d device\tSend out on this device\n\ -\t\t-g gateway\tIP gateway to use if non-local dest.\n\ -\t\t-m mtu\t\tfake MTU to use when sending out\n\ -", prog); - exit(1); -} - - -int main(argc, argv) - int argc; - char **argv; -{ - struct in_addr gwip; - struct ipread *ipr = NULL; - char *name = argv[0], *gateway = NULL, *dev = NULL; - char *resend = NULL; - int mtu = 1500, c; - - while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1) - switch (c) - { - case 'd' : - dev = optarg; - break; - case 'g' : - gateway = optarg; - break; - case 'm' : - mtu = atoi(optarg); - if (mtu < 28) - { - fprintf(stderr, "mtu must be > 28\n"); - exit(1); - } - case 'r' : - resend = optarg; - break; - case 'R' : - opts |= OPT_RAW; - break; -#ifndef NO_IPF - case 'H' : - ipr = &iphex; - break; - case 'P' : - ipr = &pcap; - break; - case 'X' : - ipr = &iptext; - break; -#endif - default : - fprintf(stderr, "Unknown option \"%c\"\n", c); - usage(name); - } - - if (!ipr || !resend) - usage(name); - - gwip.s_addr = 0; - if (gateway && resolve(gateway, (char *)&gwip) == -1) - { - fprintf(stderr,"Cant resolve %s\n", gateway); - exit(2); - } - - if (!dev) - dev = default_device; - - printf("Device: %s\n", dev); - printf("Gateway: %s\n", inet_ntoa(gwip)); - printf("mtu: %d\n", mtu); - - return ip_resend(dev, mtu, ipr, gwip, resend); -} diff --git a/contrib/ipfilter/ipsend/ipsend.1 b/contrib/ipfilter/ipsend/ipsend.1 deleted file mode 100644 index 7f0a8e3..0000000 --- a/contrib/ipfilter/ipsend/ipsend.1 +++ /dev/null @@ -1,111 +0,0 @@ -.\" $FreeBSD$ -.\" -.TH IPSEND 1 -.SH NAME -ipsend \- sends IP packets -.SH SYNOPSIS -.B ipsend -[ -.B \-dITUv -] [ -.B \-i -<interface> -] [ -.B \-f -<\fIoffset\fP> -] [ -.B \-g -<\fIgateway\fP> -] [ -.B \-m -<\fIMTU\fP> -] [ -.B \-o -<\fIoption\fP> -] [ -.B \-P -<protocol> -] [ -.B \-s -<\fIsource\fP> -] [ -.B \-t -<\fIdest. port\fP> -] [ -.B \-w -<\fIwindow\fP> -] <destination> [TCP-flags] -.SH DESCRIPTION -.PP -\fBipsend\fP can be compiled in two ways. The first is used to send one-off -packets to a destination host, using command line options to specify various -attributes present in the headers. The \fIdestination\fP must be given as -the last command line option, except for when TCP flags are specified as -a combination of A, S, F, U, P and R, last. -.PP -The other way it may be compiled, with DOSOCKET defined, is to allow an -attempt at making a TCP connection using a with ipsend resending the SYN -packet as per the command line options. -.SH OPTIONS -.TP -.BR \-d -enable debugging mode. -.TP -.BR \-f \0<offset> -The \fI-f\fP allows the IP offset field in the IP header to be set to an -arbitrary value, which can be specified in decimal or hexadecimal. -.TP -.BR \-g \0<gateway> -Specify the hostname of the gateway through which to route packets. This -is required whenever the destination host isn't directly attached to the -same network as the host from which you're sending. -.TP -.BR \-i \0<interface> -Set the interface name to be the name supplied. -.TP -.TP -.BR \-m \0<MTU> -Specify the MTU to be used when sending out packets. This option allows you -to set a fake MTU, allowing the simulation of network interfaces with small -MTU's without setting them so. -.TP -.BR \-o \0<option> -Specify options to be included at the end of the IP header. An EOL option -is automatically appended and need not be given. If an option would also -have data associated with it (source as an IP# for a lsrr option), then -this will not be initialised. -.TP -.BR \-s \0<source> -Set the source address in the packet to that provided - maybe either a -hostname or IP#. -.TP -.BR \-t \0<dest. port> -Set the destination port for TCP/UDP packets. -.TP -.BR \-w \0<window> -Set the window size for TCP packets. -.TP -.B \-I -Set the protocol to ICMP. -.TP -.B \-P <protocol> -Set the protocol to the value given. If the parameter is a name, the name -is looked up in the \fI/etc/protocols\fP file. -.TP -.B \-T -Set the protocol to TCP. -.TP -.B \-U -Set the protocol to UDP. -.TP -.BR \-v -enable verbose mode. -.DT -.SH SEE ALSO -ipsend(1), ipresend(1), iptest(1), protocols(4), bpf(4), dlpi(7p) -.SH DIAGNOSTICS -.PP -Needs to be run as root. -.SH BUGS -.PP -If you find any, please send email to me at darrenr@pobox.com diff --git a/contrib/ipfilter/ipsend/ipsend.5 b/contrib/ipfilter/ipsend/ipsend.5 deleted file mode 100644 index fc86911..0000000 --- a/contrib/ipfilter/ipsend/ipsend.5 +++ /dev/null @@ -1,402 +0,0 @@ -.\" $FreeBSD$ -.TH IPSEND 5 -.SH NAME -ipsend \- IP packet description language -.SH DESCRIPTION -The \fBipsend\fP program expects, with the \fB-L\fP option, input to be a -text file which fits the grammar described below. The purpose of this -grammar is to allow IP packets to be described in an arbitary way which -also allows encapsulation to be so done to an arbitary level. -.SH GRAMMAR -.LP -.nf -line ::= iface | arp | send | defrouter | ipv4line . - -iface ::= ifhdr "{" ifaceopts "}" ";" . -ifhdr ::= "interface" | "iface" . -ifaceopts ::= "ifname" name | "mtu" mtu | "v4addr" ipaddr | - "eaddr" eaddr . - -send ::= "send" ";" | "send" "{" sendbodyopts "}" ";" . -sendbodyopts ::= sendbody [ sendbodyopts ] . -sendbody ::= "ifname" name | "via" ipaddr . - -defrouter ::= "router" ipaddr . - -arp ::= "arp" "{" arpbodyopts "}" ";" . -arpbodyopts ::= arpbody [ arpbodyopts ] . -arpbody ::= "v4addr" ipaddr | "eaddr" eaddr . - -bodyline ::= ipv4line | tcpline | udpline | icmpline | dataline . - -ipv4line ::= "ipv4" "{" ipv4bodyopts "}" ";" . -ipv4bodyopts ::= ipv4body [ ipv4bodyopts ] | bodyline . -ipv4body ::= "proto" protocol | "src" ipaddr | "dst" ipaddr | - "off" number | "v" number | "hl" number| "id" number | - "ttl" number | "tos" number | "sum" number | "len" number | - "opt" "{" ipv4optlist "}" ";" . -ipv4optlist ::= ipv4option [ ipv4optlist ] . -ipv4optlist = "nop" | "rr" | "zsu" | "mtup" | "mtur" | "encode" | "ts" | - "tr" | "sec" | "lsrr" | "e-sec" | "cipso" | "satid" | - "ssrr" | "addext" | "visa" | "imitd" | "eip" | "finn" | - "secclass" ipv4secclass. -ipv4secclass := "unclass" | "confid" | "reserv-1" | "reserv-2" | - "reserv-3" | "reserv-4" | "secret" | "topsecret" . - -tcpline ::= "tcp" "{" tcpbodyopts "}" ";" . -tcpbodyopts ::= tcpbody [ tcpbodyopts ] | bodyline . -tcpbody ::= "sport" port | "dport" port | "seq" number | "ack" number | - "off" number | "urp" number | "win" number | "sum" number | - "flags" tcpflags | data . - -udpline ::= "udp" "{" udpbodyopts "}" ";" . -udpbodyopts ::= udpbody [ udpbodyopts ] | bodyline . -udpbody ::= "sport" port | "dport" port | "len" number | "sum" number | - data . - -icmpline ::= "icmp" "{" icmpbodyopts "}" ";" . -icmpbodyopts ::= icmpbody [ icmpbodyopts ] | bodyline . -icmpbody ::= "type" icmptype [ "code" icmpcode ] . -icmptype ::= "echorep" | "echorep" "{" echoopts "}" ";" | "unreach" | - "unreach" "{" unreachtype "}" ";" | "squench" | "redir" | - "redir" "{" redirtype "}" ";" | "echo" "{" echoopts "}" ";" | - "echo" | "routerad" | "routersol" | "timex" | - "timex" "{" timextype "}" ";" | "paramprob" | - "paramprob" "{" parapptype "}" ";" | "timest" | "timestrep" | - "inforeq" | "inforep" | "maskreq" | "maskrep" . - -echoopts ::= echoopts [ icmpechoopts ] . -unreachtype ::= "net-unr" | "host-unr" | "proto-unr" | "port-unr" | - "needfrag" | "srcfail" | "net-unk" | "host-unk" | "isolate" | - "net-prohib" | "host-prohib" | "net-tos" | "host-tos" | - "filter-prohib" | "host-preced" | "cutoff-preced" . -redirtype ::= "net-redir" | "host-redir" | "tos-net-redir" | - "tos-host-redir" . -timextype ::= "intrans" | "reass" . -paramptype ::= "optabsent" . - -data ::= "data" "{" databodyopts "}" ";" . -databodyopts ::= "len" number | "value" string | "file" filename . - -icmpechoopts ::= "icmpseq" number | "icmpid" number . -.fi -.SH COMMANDS -.PP -Before sending any packets or defining any packets, it is necessary to -describe the interface(s) which will be used to send packets out. -.TP -.B interface -is used to describe a network interface. The description included need -not match the actual configuration currently employed by the operating -system. -.TP -.B send -is used to actually send out a packet across the network. If the -destination is not specified, it will attempt to send the packet -directly out on the network to the destination without routing it. -.TP -.B router -configures the default router for ipsend, as distinct from the default -route installed in the kernel. -.TP -.B ipv4 -is used to describe an IP (version 4) packet. IP header fields can be -specified, including options, followed by a data section which may contain -further protocol headers. -.SH IPv4 -.TP -.B hl <number> -manually specifies the IP header length (automatically adjusts with the -presence of IP options and defaults to 5); -.TP -.B v <number> -set the IP version. Default is 4. -.TP -.B tos <number> -set the type of service (TOS) field in the IP header. Default is 0. -.TP -.B len <number> -manually specifies the length of the IP packet. The length will automatically -be adjusted to accommodate data or further protocol headers. -.TP -.B off <number> -sets the fragment offset field of the IP packet. Default is 0. -.TP -.B ttl <number> -sets the time to live (TTL) field of the IP header. Default is 60. -.TP -.B proto <protocol> -sets the protocol field of the IP header. The protocol can either be a -number or a name found in \fB/etc/protocols\fP. -.TP -.B sum -manually specifies the checksum for the IP header. If left unset (0), it -will be calculated prior to being sent. -.TP -.B src -manually specifies the source address of the IP header. If left unset, it -will default to the host's IP address. -.TP -.B dst -sets the destination of the IP packet. The default is 0.0.0.0. -.TP -.B opt -is used to include IP options in the IP header. -.TP -.B tcp -is used to indicate the a TCP protocol header is to follow. See the \fBTCP\fP -section for TCP header options. -.TP -.B udp -is used to indicate the a UDP protocol header is to follow. See the \fBUDP\fP -section for UDP header options. -.TP -.B icmp -is used to indicate the a ICMP protocol header is to follow. See the -\fBICMP\fP section for ICMP header options. -.TP -.B data -is used to indicate that raw data is to be included in the IP packet. See the -\fBDATA\fP section for details on options available. -.SH "IPv4 Options" -these keywords indicate that the relevant IP option should be added to the -IP header (the header length field will be adjusted appropriately). -.TP -.B nop -No Operation [RFC 791] (space filler). -.TP -.B rr <number> -Record Router [RFC 791]. The number given specifies the number of -\fBbytes\fP to be used for storage. This should be a multiple of 4 for -proper operation. -.TP -.B zsu -Experimental Measurement. -.TP -.B mtup [RFC 1191]. -MTU Probe. -.TP -.B mtur [RFC 1191]. -MTU Ready. -.TP -.B encode -.TP -.B ts -Timestamp [RFC 791]. -.TP -.B tr -Traceroute [RFC 1393]. -.TP -.B "sec-class <security-level>, sec" -Security [RFC 1108]. This option specifies the security label for the packet. -Using \fBsec\fP sets up the framework of the security option but unless -\fBsec-class\fP is given, the level may not be set. -.TP -.B "lsrr <ip-address>" -Loose Source Route [RFC 791]. -.TP -.B e-sec -Extended Security [RFC 1108]. -.TP -.B cipso -Commercial Security. -.TP -.B satid -Stream ID [RFC 791]. -.TP -.B "ssrr <ip-address>" -Strict Source Route [RFC 791]. -.TP -.B addext -Address Extension -.TP -.B visa -Experimental Access Control. -.TP -.B imitd -IMI Traffic Descriptor. -.TP -.B eip -[RFC 1358]. -.TP -.B finn -Experimental Flow Control. -.SH TCP -.TP -.B sport <port> -sets the source port to the number/name given. Default is 0. -.TP -.B dport <port> -sets the destination port to the number/name given. Default is 0. -.TP -.B seq <number> -sets the sequence number to the number specified. Default is 0. -.TP -.B ack <number> -sets the acknowledge number to the number specified. Default is 0. -.TP -.B off <number> -sets the offset value for the start of data to the number specified. This -implies the size of the TCP header. It is automatically adjusted if TCP -options are included and defaults to 5. -.TP -.B urp <number> -sets the value of the urgent data pointer to the number specified. Default -is 0. -.TP -.B win <number> -sets the size of the TCP window to the number specified. Default is 4096. -.TP -.B sum <number> -manually specifies the checksum for the TCP pseudo-header and data. If left -unset, it defaults to 0 and is automatically calculated. -.TP -.B flags <tcp-flags> -sets the TCP flags field to match the flags specified. Valid flags are -"S" (SYN), "A" (ACK), "R" (RST), "F" (FIN), "U" (URG), "P" (PUSH). -.TP -.B opt -indicates that TCP header options follow. As TCP options are added to the -TCP header, the \fBoff\fP field is updated to match. -.TP -.B data -indicates that a data section is to follow and is to be included as raw -data, being appended to the header. -.SH "TCP options" -With a TCP header, it is possible to append a number of header options. -The TCP header offset will be updated automatically to reflect the change -in size. The valid options are: \fBnop\fP No Operation, -\fBeol\fP End Of (option) List, \fBmss [ size ]\fP Maximum Segment Size - this -sets the maximum receivable size of a packet containing data, -\fBwscale\fP Window Scale, \fBts\fP Timestamp. -.SH UDP -.TP -.B sport <port> -sets the source port to the number/name given. Default is 0. -.TP -.B dport <port> -sets the destination port to the number/name given. Default is 0. -.TP -.B len <number> -manually specifies the length of the UDP header and data. If left unset, -it is automatically adjusted to match the header presence and any data if -present. -.TP -.B sum <number> -manually specifies the checksum for the UDP pseudo-header and data. If left -unset, it defaults to 0 and is automatically calculated. -.TP -.B data -indicates that a data section is to follow and is to be included as raw -data, being appended to the header. -.SH ICMP -.TP -.B type <icmptype> -sets the ICMP type according the to the icmptype tag. This may either be -a number or one of the recognised tags (see the \fBICMP TYPES\fP section for a -list of names recognised). -.TP -.B code <icmpcode> -sets the ICMP code. -.TP -.B data -indicates that a data section is to follow and is to be included as raw -data, being appended to the header. -.SH DATA -Each of the following extend the packet in a different way. \fBLen\fP just -increases the length (without adding any content), \fBvalue\fP uses a string -and \fBfile\fP a file. -.TP -.B len <number> -extend the length of the packet by \fBnumber\fP bytes (without filling those -bytes with any particular data). -.TP -.B value <string> -indicates that the string provided should be added to the current packet as -data. A string may be a consecutive list of characters and numbers (with -no white spaces) or bounded by "'s (may not contain them, even if \\'d). -The \\ character is recognised with the appropriate C escaped values, including -octal numbers. -.TP -.B file <filename> -reads data in from the specified file and appends it to the current packet. -If the new total length would exceed 64k, an error will be reported. -.SH "ICMP TYPES" -.TP -.B echorep -Echo Reply. -.TP -.B "unreach [ unreachable-code ]" -Generic Unreachable error. This is used to indicate that an error has -occurred whilst trying to send the packet across the network and that the -destination cannot be reached. The unreachable code names are: -\fBnet-unr\fP network unreachable, \fBhost-unr\fP host unreachable, -\fBproto-unr\fP protocol unreachable, \fBport-unr\fP port unreachable, -\fBneedfrag\fP, \fBsrcfail\fP source route failed, -\fBnet-unk\fP network unknown, \fBhost-unk\fP host unknown, -\fBisolate\fP, \fBnet-prohib\fP administratively prohibited contact with -network, -\fBhost-prohib\fP administratively prohibited contact with host, -\fBnet-tos\fP network unreachable with given TOS, -\fBhost-tos\fP host unreachable with given TOS, -\fBfilter-prohib\fP packet prohibited by packet filter, -\fBhost-preced\fP, -\fBcutoff-preced\fP. -.TP -.B squench -Source Quence. -.TP -.B "redir [ redirect-code ]" -Redirect (routing). This is used to indicate that the route being chosen -for forwarding the packet is suboptimal and that the sender of the packet -should be routing packets via another route. The redirect code names are: -\fBnet-redir\fP redirect packets for a network, -\fBhost-redir\fP redirect packets for a host, -\fBtos-net-redir\fP redirect packets for a network with a given TOS, -\fBtos-host-redir\fP redirect packets for a host with a given TOS. -.TP -.B echo -Echo. -.TP -.B routerad -Router Advertisement. -.TP -.B routersol -Router solicitation. -.TP -.B "timex [ timexceed-code ]" -Time Exceeded. This is used to indicate that the packet failed to reach the -destination because it was in transit too long (i.e. ttl reached 0). The -valid code names are: \fBintrans\fP, -\fBreass\fP could not reassemble packet from fragments within a given time. -.TP -.B "paramprob [ paramprob-code ]" -Parameter problem. There is only one available parameter problem code name: -\fBoptabsent\fP. -.TP -.B timest -Time stamp request. -.TP -.B "timestrep [ { timestamp-code } ]" -Time stamp reply. In a timestamp reply, it is possible to supply the -following values: \fBrtime\fP, \fBotime\fP, \fBttime\fP. -.TP -.B inforeq -Information request. -.TP -.B inforep -Information reply. -.TP -.B maskreq -Address mask request. -.TP -.B maskrep -Address mask reply. -.SH FILES -/etc/hosts -.br -/etc/protocols -.br -/etc/services -.SH SEE ALSO -ipsend(1), iptest(1), hosts(5), protocols(5), services(5) diff --git a/contrib/ipfilter/ipsend/ipsend.c b/contrib/ipfilter/ipsend/ipsend.c deleted file mode 100644 index 3df5c07..0000000 --- a/contrib/ipfilter/ipsend/ipsend.c +++ /dev/null @@ -1,440 +0,0 @@ -/* $FreeBSD$ */ -/* - * ipsend.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - */ -#if !defined(lint) -static const char sccsid[] = "@(#)ipsend.c 1.5 12/10/95 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netinet/in_systm.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <netdb.h> -#include <string.h> -#include <netinet/ip.h> -#ifndef linux -# include <netinet/ip_var.h> -#endif -#include "ipsend.h" -#include "ipf.h" -#ifndef linux -# include <netinet/udp_var.h> -#endif - - -extern char *optarg; -extern int optind; -extern void iplang __P((FILE *)); - -char options[68]; -int opts; -#ifdef linux -char default_device[] = "eth0"; -#else -# ifdef ultrix -char default_device[] = "ln0"; -# else -# ifdef __bsdi__ -char default_device[] = "ef0"; -# else -# ifdef __sgi -char default_device[] = "ec0"; -# else -# ifdef __hpux -char default_device[] = "lan0"; -# else -char default_device[] = "le0"; -# endif /* __hpux */ -# endif /* __sgi */ -# endif /* __bsdi__ */ -# endif /* ultrix */ -#endif /* linux */ - - -static void usage __P((char *)); -static void do_icmp __P((ip_t *, char *)); -void udpcksum(ip_t *, struct udphdr *, int); -int main __P((int, char **)); - - -static void usage(prog) - char *prog; -{ - fprintf(stderr, "Usage: %s [options] dest [flags]\n\ -\toptions:\n\ -\t\t-d\tdebug mode\n\ -\t\t-i device\tSend out on this device\n\ -\t\t-f fragflags\tcan set IP_MF or IP_DF\n\ -\t\t-g gateway\tIP gateway to use if non-local dest.\n\ -\t\t-I code,type[,gw[,dst[,src]]]\tSet ICMP protocol\n\ -\t\t-m mtu\t\tfake MTU to use when sending out\n\ -\t\t-P protocol\tSet protocol by name\n\ -\t\t-s src\t\tsource address for IP packet\n\ -\t\t-T\t\tSet TCP protocol\n\ -\t\t-t port\t\tdestination port\n\ -\t\t-U\t\tSet UDP protocol\n\ -\t\t-v\tverbose mode\n\ -\t\t-w <window>\tSet the TCP window size\n\ -", prog); - fprintf(stderr, "Usage: %s [-dv] -L <filename>\n\ -\toptions:\n\ -\t\t-d\tdebug mode\n\ -\t\t-L filename\tUse IP language for sending packets\n\ -\t\t-v\tverbose mode\n\ -", prog); - exit(1); -} - - -static void do_icmp(ip, args) - ip_t *ip; - char *args; -{ - struct icmp *ic; - char *s; - - ip->ip_p = IPPROTO_ICMP; - ip->ip_len += sizeof(*ic); - ic = (struct icmp *)(ip + 1); - bzero((char *)ic, sizeof(*ic)); - if (!(s = strchr(args, ','))) - { - fprintf(stderr, "ICMP args missing: ,\n"); - return; - } - *s++ = '\0'; - ic->icmp_type = atoi(args); - ic->icmp_code = atoi(s); - if (ic->icmp_type == ICMP_REDIRECT && strchr(s, ',')) - { - char *t; - - t = strtok(s, ","); - t = strtok(NULL, ","); - if (resolve(t, (char *)&ic->icmp_gwaddr) == -1) - { - fprintf(stderr,"Cant resolve %s\n", t); - exit(2); - } - if ((t = strtok(NULL, ","))) - { - if (resolve(t, (char *)&ic->icmp_ip.ip_dst) == -1) - { - fprintf(stderr,"Cant resolve %s\n", t); - exit(2); - } - if ((t = strtok(NULL, ","))) - { - if (resolve(t, - (char *)&ic->icmp_ip.ip_src) == -1) - { - fprintf(stderr,"Cant resolve %s\n", t); - exit(2); - } - } - } - } -} - - -int send_packets(dev, mtu, ip, gwip) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; -{ - int wfd; - - wfd = initdevice(dev, 5); - if (wfd == -1) - return -1; - return send_packet(wfd, mtu, ip, gwip); -} - -void -udpcksum(ip_t *ip, struct udphdr *udp, int len) -{ - union pseudoh { - struct hdr { - u_short len; - u_char ttl; - u_char proto; - u_32_t src; - u_32_t dst; - } h; - u_short w[6]; - } ph; - u_32_t temp32; - u_short *opts; - - ph.h.len = htons(len); - ph.h.ttl = 0; - ph.h.proto = IPPROTO_UDP; - ph.h.src = ip->ip_src.s_addr; - ph.h.dst = ip->ip_dst.s_addr; - temp32 = 0; - opts = &ph.w[0]; - temp32 += opts[0] + opts[1] + opts[2] + opts[3] + opts[4] + opts[5]; - temp32 = (temp32 >> 16) + (temp32 & 65535); - temp32 += (temp32 >> 16); - udp->uh_sum = temp32 & 65535; - udp->uh_sum = chksum((u_short *)udp, len); - if (udp->uh_sum == 0) - udp->uh_sum = 0xffff; -} - -int main(argc, argv) - int argc; - char **argv; -{ - FILE *langfile = NULL; - struct in_addr gwip; - tcphdr_t *tcp; - udphdr_t *udp; - ip_t *ip; - char *name = argv[0], host[MAXHOSTNAMELEN + 1]; - char *gateway = NULL, *dev = NULL; - char *src = NULL, *dst, *s; - int mtu = 1500, olen = 0, c, nonl = 0; - - /* - * 65535 is maximum packet size...you never know... - */ - ip = (ip_t *)calloc(1, 65536); - tcp = (tcphdr_t *)(ip + 1); - udp = (udphdr_t *)tcp; - ip->ip_len = sizeof(*ip); - IP_HL_A(ip, sizeof(*ip) >> 2); - - while ((c = getopt(argc, argv, "I:L:P:TUdf:i:g:m:o:s:t:vw:")) != -1) { - switch (c) - { - case 'I' : - nonl++; - if (ip->ip_p) - { - fprintf(stderr, "Protocol already set: %d\n", - ip->ip_p); - break; - } - do_icmp(ip, optarg); - break; - case 'L' : - if (nonl) { - fprintf(stderr, - "Incorrect usage of -L option.\n"); - usage(name); - } - if (!strcmp(optarg, "-")) - langfile = stdin; - else if (!(langfile = fopen(optarg, "r"))) { - fprintf(stderr, "can't open file %s\n", - optarg); - exit(1); - } - iplang(langfile); - return 0; - case 'P' : - { - struct protoent *p; - - nonl++; - if (ip->ip_p) - { - fprintf(stderr, "Protocol already set: %d\n", - ip->ip_p); - break; - } - if ((p = getprotobyname(optarg))) - ip->ip_p = p->p_proto; - else - fprintf(stderr, "Unknown protocol: %s\n", - optarg); - break; - } - case 'T' : - nonl++; - if (ip->ip_p) - { - fprintf(stderr, "Protocol already set: %d\n", - ip->ip_p); - break; - } - ip->ip_p = IPPROTO_TCP; - ip->ip_len += sizeof(tcphdr_t); - break; - case 'U' : - nonl++; - if (ip->ip_p) - { - fprintf(stderr, "Protocol already set: %d\n", - ip->ip_p); - break; - } - ip->ip_p = IPPROTO_UDP; - ip->ip_len += sizeof(udphdr_t); - break; - case 'd' : - opts |= OPT_DEBUG; - break; - case 'f' : - nonl++; - ip->ip_off = strtol(optarg, NULL, 0); - break; - case 'g' : - nonl++; - gateway = optarg; - break; - case 'i' : - nonl++; - dev = optarg; - break; - case 'm' : - nonl++; - mtu = atoi(optarg); - if (mtu < 28) - { - fprintf(stderr, "mtu must be > 28\n"); - exit(1); - } - break; - case 'o' : - nonl++; - olen = buildopts(optarg, options, (IP_HL(ip) - 5) << 2); - break; - case 's' : - nonl++; - src = optarg; - break; - case 't' : - nonl++; - if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP) - tcp->th_dport = htons(atoi(optarg)); - break; - case 'v' : - opts |= OPT_VERBOSE; - break; - case 'w' : - nonl++; - if (ip->ip_p == IPPROTO_TCP) - tcp->th_win = atoi(optarg); - else - fprintf(stderr, "set protocol to TCP first\n"); - break; - default : - fprintf(stderr, "Unknown option \"%c\"\n", c); - usage(name); - } - } - - if (argc - optind < 1) - usage(name); - dst = argv[optind++]; - - if (!src) - { - gethostname(host, sizeof(host)); - src = host; - } - - if (resolve(src, (char *)&ip->ip_src) == -1) - { - fprintf(stderr,"Cant resolve %s\n", src); - exit(2); - } - - if (resolve(dst, (char *)&ip->ip_dst) == -1) - { - fprintf(stderr,"Cant resolve %s\n", dst); - exit(2); - } - - if (!gateway) - gwip = ip->ip_dst; - else if (resolve(gateway, (char *)&gwip) == -1) - { - fprintf(stderr,"Cant resolve %s\n", gateway); - exit(2); - } - - if (olen) - { - int hlen; - char *p; - - printf("Options: %d\n", olen); - hlen = sizeof(*ip) + olen; - IP_HL_A(ip, hlen >> 2); - ip->ip_len += olen; - p = (char *)malloc(65536); - if (p == NULL) - { - fprintf(stderr, "malloc failed\n"); - exit(2); - } - - bcopy(ip, p, sizeof(*ip)); - bcopy(options, p + sizeof(*ip), olen); - bcopy(ip + 1, p + hlen, ip->ip_len - hlen); - ip = (ip_t *)p; - - if (ip->ip_p == IPPROTO_TCP) { - tcp = (tcphdr_t *)(p + hlen); - } else if (ip->ip_p == IPPROTO_UDP) { - udp = (udphdr_t *)(p + hlen); - } - } - - if (ip->ip_p == IPPROTO_TCP) - for (s = argv[optind]; s && (c = *s); s++) - switch(c) - { - case 'S' : case 's' : - tcp->th_flags |= TH_SYN; - break; - case 'A' : case 'a' : - tcp->th_flags |= TH_ACK; - break; - case 'F' : case 'f' : - tcp->th_flags |= TH_FIN; - break; - case 'R' : case 'r' : - tcp->th_flags |= TH_RST; - break; - case 'P' : case 'p' : - tcp->th_flags |= TH_PUSH; - break; - case 'U' : case 'u' : - tcp->th_flags |= TH_URG; - break; - } - - if (!dev) - dev = default_device; - printf("Device: %s\n", dev); - printf("Source: %s\n", inet_ntoa(ip->ip_src)); - printf("Dest: %s\n", inet_ntoa(ip->ip_dst)); - printf("Gateway: %s\n", inet_ntoa(gwip)); - if (ip->ip_p == IPPROTO_TCP && tcp->th_flags) - printf("Flags: %#x\n", tcp->th_flags); - printf("mtu: %d\n", mtu); - - if (ip->ip_p == IPPROTO_UDP) { - udp->uh_sum = 0; - udpcksum(ip, udp, ip->ip_len - (IP_HL(ip) << 2)); - } -#ifdef DOSOCKET - if (ip->ip_p == IPPROTO_TCP && tcp->th_dport) - return do_socket(dev, mtu, ip, gwip); -#endif - return send_packets(dev, mtu, ip, gwip); -} diff --git a/contrib/ipfilter/ipsend/ipsend.h b/contrib/ipfilter/ipsend/ipsend.h deleted file mode 100644 index 75a0496..0000000 --- a/contrib/ipfilter/ipsend/ipsend.h +++ /dev/null @@ -1,73 +0,0 @@ -/* $FreeBSD$ */ - -/* - * ipsend.h (C) 1997-1998 Darren Reed - * - * This was written to test what size TCP fragments would get through - * various TCP/IP packet filters, as used in IP firewalls. In certain - * conditions, enough of the TCP header is missing for unpredictable - * results unless the filter is aware that this can happen. - * - * The author provides this program as-is, with no gaurantee for its - * suitability for any specific purpose. The author takes no responsibility - * for the misuse/abuse of this program and provides it for the sole purpose - * of testing packet filter policies. This file maybe distributed freely - * providing it is not modified and that this notice remains in tact. - * - */ -#ifndef __P -# ifdef __STDC__ -# define __P(x) x -# else -# define __P(x) () -# endif -#endif - -#include <net/if.h> - -#include "ipf.h" -#ifdef linux -#include <linux/sockios.h> -#endif -/* XXX: The following is needed by tcpip.h */ -#include <netinet/ip_var.h> -#include "netinet/tcpip.h" -#include "ipt.h" - -extern int resolve __P((char *, char *)); -extern int arp __P((char *, char *)); -extern u_short chksum __P((u_short *, int)); -extern int send_ether __P((int, char *, int, struct in_addr)); -extern int send_ip __P((int, int, ip_t *, struct in_addr, int)); -extern int send_tcp __P((int, int, ip_t *, struct in_addr)); -extern int send_udp __P((int, int, ip_t *, struct in_addr)); -extern int send_icmp __P((int, int, ip_t *, struct in_addr)); -extern int send_packet __P((int, int, ip_t *, struct in_addr)); -extern int send_packets __P((char *, int, ip_t *, struct in_addr)); -extern u_short ipseclevel __P((char *)); -extern u_32_t buildopts __P((char *, char *, int)); -extern int addipopt __P((char *, struct ipopt_names *, int, char *)); -extern int initdevice __P((char *, int)); -extern int sendip __P((int, char *, int)); -#ifdef linux -extern struct sock *find_tcp __P((int, struct tcpiphdr *)); -#else -extern struct tcpcb *find_tcp __P((int, struct tcpiphdr *)); -#endif -extern int ip_resend __P((char *, int, struct ipread *, struct in_addr, char *)); - -extern void ip_test1 __P((char *, int, ip_t *, struct in_addr, int)); -extern void ip_test2 __P((char *, int, ip_t *, struct in_addr, int)); -extern void ip_test3 __P((char *, int, ip_t *, struct in_addr, int)); -extern void ip_test4 __P((char *, int, ip_t *, struct in_addr, int)); -extern void ip_test5 __P((char *, int, ip_t *, struct in_addr, int)); -extern void ip_test6 __P((char *, int, ip_t *, struct in_addr, int)); -extern void ip_test7 __P((char *, int, ip_t *, struct in_addr, int)); -extern int do_socket __P((char *, int, struct tcpiphdr *, struct in_addr)); -extern int kmemcpy __P((char *, void *, int)); - -#define KMCPY(a,b,c) kmemcpy((char *)(a), (void *)(b), (int)(c)) - -#ifndef OPT_RAW -#define OPT_RAW 0x80000 -#endif diff --git a/contrib/ipfilter/ipsend/ipsopt.c b/contrib/ipfilter/ipsend/ipsopt.c deleted file mode 100644 index a2cc4d0..0000000 --- a/contrib/ipfilter/ipsend/ipsopt.c +++ /dev/null @@ -1,200 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Copyright (C) 2012 by Darren Reed. - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "@(#)ipsopt.c 1.2 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#ifndef linux -#include <netinet/ip_var.h> -#endif -#include <netinet/tcp.h> -#include <arpa/inet.h> -#include "ipsend.h" - - -#ifndef __P -# ifdef __STDC__ -# define __P(x) x -# else -# define __P(x) () -# endif -#endif - - -struct ipopt_names ionames[] = { - { IPOPT_EOL, 0x01, 1, "eol" }, - { IPOPT_NOP, 0x02, 1, "nop" }, - { IPOPT_RR, 0x04, 3, "rr" }, /* 1 route */ - { IPOPT_TS, 0x08, 8, "ts" }, /* 1 TS */ - { IPOPT_SECURITY, 0x08, 11, "sec-level" }, - { IPOPT_LSRR, 0x10, 7, "lsrr" }, /* 1 route */ - { IPOPT_SATID, 0x20, 4, "satid" }, - { IPOPT_SSRR, 0x40, 7, "ssrr" }, /* 1 route */ - { 0, 0, 0, NULL } /* must be last */ -}; - -struct ipopt_names secnames[] = { - { IPOPT_SECUR_UNCLASS, 0x0100, 0, "unclass" }, - { IPOPT_SECUR_CONFID, 0x0200, 0, "confid" }, - { IPOPT_SECUR_EFTO, 0x0400, 0, "efto" }, - { IPOPT_SECUR_MMMM, 0x0800, 0, "mmmm" }, - { IPOPT_SECUR_RESTR, 0x1000, 0, "restr" }, - { IPOPT_SECUR_SECRET, 0x2000, 0, "secret" }, - { IPOPT_SECUR_TOPSECRET, 0x4000,0, "topsecret" }, - { 0, 0, 0, NULL } /* must be last */ -}; - - -u_short ipseclevel(slevel) - char *slevel; -{ - struct ipopt_names *so; - - for (so = secnames; so->on_name; so++) - if (!strcasecmp(slevel, so->on_name)) - break; - - if (!so->on_name) { - fprintf(stderr, "no such security level: %s\n", slevel); - return 0; - } - return so->on_value; -} - - -int addipopt(op, io, len, class) - char *op; - struct ipopt_names *io; - int len; - char *class; -{ - struct in_addr ipadr; - int olen = len, srr = 0; - u_short val; - u_char lvl; - char *s = op, *t; - - if ((len + io->on_siz) > 48) { - fprintf(stderr, "options too long\n"); - return 0; - } - len += io->on_siz; - *op++ = io->on_value; - if (io->on_siz > 1) { - /* - * Allow option to specify RR buffer length in bytes. - */ - if (io->on_value == IPOPT_RR) { - val = (class && *class) ? atoi(class) : 4; - *op++ = val + io->on_siz; - len += val; - } else - *op++ = io->on_siz; - if (io->on_value == IPOPT_TS) - *op++ = IPOPT_MINOFF + 1; - else - *op++ = IPOPT_MINOFF; - - while (class && *class) { - t = NULL; - switch (io->on_value) - { - case IPOPT_SECURITY : - lvl = ipseclevel(class); - *(op - 1) = lvl; - break; - case IPOPT_LSRR : - case IPOPT_SSRR : - if ((t = strchr(class, ','))) - *t = '\0'; - ipadr.s_addr = inet_addr(class); - srr++; - bcopy((char *)&ipadr, op, sizeof(ipadr)); - op += sizeof(ipadr); - break; - case IPOPT_SATID : - val = atoi(class); - bcopy((char *)&val, op, 2); - break; - } - - if (t) - *t++ = ','; - class = t; - } - if (srr) - s[IPOPT_OLEN] = IPOPT_MINOFF - 1 + 4 * srr; - if (io->on_value == IPOPT_RR) - op += val; - else - op += io->on_siz - 3; - } - return len - olen; -} - - -u_32_t buildopts(cp, op, len) - char *cp, *op; - int len; -{ - struct ipopt_names *io; - u_32_t msk = 0; - char *s, *t; - int inc, lastop = -1; - - for (s = strtok(cp, ","); s; s = strtok(NULL, ",")) { - if ((t = strchr(s, '='))) - *t++ = '\0'; - for (io = ionames; io->on_name; io++) { - if (strcasecmp(s, io->on_name) || (msk & io->on_bit)) - continue; - lastop = io->on_value; - if ((inc = addipopt(op, io, len, t))) { - op += inc; - len += inc; - } - msk |= io->on_bit; - break; - } - if (!io->on_name) { - fprintf(stderr, "unknown IP option name %s\n", s); - return 0; - } - } - - if (len & 3) { - while (len & 3) { - *op++ = ((len & 3) == 3) ? IPOPT_EOL : IPOPT_NOP; - len++; - } - } else { - if (lastop != IPOPT_EOL) { - if (lastop == IPOPT_NOP) - *(op - 1) = IPOPT_EOL; - else { - *op++ = IPOPT_NOP; - *op++ = IPOPT_NOP; - *op++ = IPOPT_NOP; - *op = IPOPT_EOL; - len += 4; - } - } - } - return len; -} diff --git a/contrib/ipfilter/ipsend/iptest.1 b/contrib/ipfilter/ipsend/iptest.1 deleted file mode 100644 index 8f25f4a..0000000 --- a/contrib/ipfilter/ipsend/iptest.1 +++ /dev/null @@ -1,103 +0,0 @@ -.\" $FreeBSD$ -.\" -.TH IPTEST 1 -.SH NAME -iptest \- automatically generate a packets to test IP functionality -.SH SYNOPSIS -.B iptest -[ -.B \-1234567 -] [ -.B \-d -<device> -] [ -.B \-g -<gateway> -] [ -.B \-m -<\fIMTU\fP> -] [ -.B \-p -<\fIpointtest\fP> -] [ -.B \-s -<\fIsource\fP> -] <destination> -.SH DESCRIPTION -.PP -\fBiptest\fP ... -.SH OPTIONS -.TP -.B \-1 -Run IP test group #1. This group of tests generates packets with the IP -header fields set to invalid values given other packet characteristics. -The point tests are: 1 (ip_hl < ip_len), 2 (ip_hl > ip_len), -3 (ip_v < 4), 4 (ip_v > 4), 5 (ip_len < packetsize, long packets), -6 (ip_len > packet size, short packets), 7 (Zero length fragments), -8 (packet > 64k after reassembly), 9 (IP offset with MSB set), 10 (ttl -variations). -.TP -.B \-2 -Run IP test group #2. This group of tests generates packets with the IP -options constructed with invalid values given other packet characteristics. -The point tests are: 1 (option length > packet length), 2 (option length = 0). -.TP -.B \-3 -Run IP test group #3. This group of tests generates packets with the ICMP -header fields set to non-standard values. The point tests are: 1 (ICMP types -0-31 & 255), 2 (type 3 & code 0 - 31), 3 (type 4 & code 0, 127, 128, 255), -4 (type 5 & code 0, 127, 128, 255), 5 (types 8-10,13-18 with codes 0, 127, -128 and 255), 6 (type 12 & code 0, 127, 128, 129, 255) and 7 (type 3 & codes -9-10, 13-14 and 17-18 - shortened packets). -.TP -.B \-4 -Run IP test group #4. This group of tests generates packets with the UDP -header fields set to non-standard values. The point tests are: 1 (UDP length -> packet size), 2 (UDP length < packetsize), 3 (sport = 0, 1, 32767, 32768, -65535), 4 (dport = 0, 1, 32767, 32768, 65535) and 5 (sizeof(struct ip) <= MTU -<= sizeof(struct udphdr) + sizeof(struct ip)). -.TP -.B \-5 -Run IP test group #5. This group of tests generates packets with the TCP -header fields set to non-standard values. The point tests are: 1 (TCP flags -variations, all combinations), 2 (seq = 0, 0x7fffffff, 0x8000000, 0xa0000000, -0xffffffff), 3 (ack = 0, 0x7fffffff, 0x8000000, 0xa0000000, 0xffffffff), -4 (SYN packet with window of 0, 32768, 65535), 5 (set urgent pointer to 1, -0x7fff, 0x8000, 0xffff), 6 (data offset), 7 (sport = 0, 1, 32767, 32768, -65535) and 8 (dport = 0, 1, 32767, 32768, 65535). -.TP -.B \-6 -Run IP test group #6. This test generates a large number of fragments in -an attempt to exhaust the network buffers used for holding packets for later -reassembly. WARNING: this may crash or cause serious performance degradation -to the target host. -.TP -.B \-7 -Run IP test group #7. This test generates 1024 random IP packets with only -the IP version, checksum, length and IP offset field correct. -.TP -.BR \-d \0<interface> -Set the interface name to be the name supplied. -.TP -.BR \-g \0<gateway> -Specify the hostname of the gateway through which to route packets. This -is required whenever the destination host isn't directly attached to the -same network as the host from which you're sending. -.TP -.BR \-m \0<MTU> -Specify the MTU to be used when sending out packets. This option allows you -to set a fake MTU, allowing the simulation of network interfaces with small -MTU's without setting them so. -.TP -.B \-p <test> -Run a... -.DT -.SH SEE ALSO -ipsend(1), ipresend(1), bpf(4), ipsend(5), dlpi(7p) -.SH DIAGNOSTICS -Only one of the numeric test options may be given when \fIiptest\fP is run. -.PP -Needs to be run as root. -.SH BUGS -.PP -If you find any, please send email to me at darrenr@pobox.com diff --git a/contrib/ipfilter/ipsend/iptest.c b/contrib/ipfilter/ipsend/iptest.c deleted file mode 100644 index c6cfb1c..0000000 --- a/contrib/ipfilter/ipsend/iptest.c +++ /dev/null @@ -1,218 +0,0 @@ -/* $FreeBSD$ */ - -/* - * ipsend.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#ifndef linux -#include <netinet/ip_var.h> -#endif -#ifdef linux -#include <linux/sockios.h> -#endif -#include <stdio.h> -#include <netdb.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include "ipsend.h" - - -extern char *optarg; -extern int optind; - -char options[68]; -#ifdef linux -char default_device[] = "eth0"; -#else -# ifdef sun -char default_device[] = "le0"; -# else -# ifdef ultrix -char default_device[] = "ln0"; -# else -# ifdef __bsdi__ -char default_device[] = "ef0"; -# else -# ifdef __sgi -char default_device[] = "ec0"; -# else -char default_device[] = "lan0"; -# endif -# endif -# endif -# endif -#endif - -static void usage __P((char *)); -int main __P((int, char **)); - - -static void usage(prog) - char *prog; -{ - fprintf(stderr, "Usage: %s [options] dest\n\ -\toptions:\n\ -\t\t-d device\tSend out on this device\n\ -\t\t-g gateway\tIP gateway to use if non-local dest.\n\ -\t\t-m mtu\t\tfake MTU to use when sending out\n\ -\t\t-p pointtest\t\n\ -\t\t-s src\t\tsource address for IP packet\n\ -\t\t-1 \t\tPerform test 1 (IP header)\n\ -\t\t-2 \t\tPerform test 2 (IP options)\n\ -\t\t-3 \t\tPerform test 3 (ICMP)\n\ -\t\t-4 \t\tPerform test 4 (UDP)\n\ -\t\t-5 \t\tPerform test 5 (TCP)\n\ -\t\t-6 \t\tPerform test 6 (overlapping fragments)\n\ -\t\t-7 \t\tPerform test 7 (random packets)\n\ -", prog); - exit(1); -} - - -int main(argc, argv) - int argc; - char **argv; -{ - struct tcpiphdr *ti; - struct in_addr gwip; - ip_t *ip; - char *name = argv[0], host[MAXHOSTNAMELEN + 1]; - char *gateway = NULL, *dev = NULL; - char *src = NULL, *dst; - int mtu = 1500, tests = 0, pointtest = 0, c; - - /* - * 65535 is maximum packet size...you never know... - */ - ip = (ip_t *)calloc(1, 65536); - ti = (struct tcpiphdr *)ip; - ip->ip_len = sizeof(*ip); - IP_HL_A(ip, sizeof(*ip) >> 2); - - while ((c = getopt(argc, argv, "1234567d:g:m:p:s:")) != -1) - switch (c) - { - case '1' : - case '2' : - case '3' : - case '4' : - case '5' : - case '6' : - case '7' : - tests = c - '0'; - break; - case 'd' : - dev = optarg; - break; - case 'g' : - gateway = optarg; - break; - case 'm' : - mtu = atoi(optarg); - if (mtu < 28) - { - fprintf(stderr, "mtu must be > 28\n"); - exit(1); - } - break; - case 'p' : - pointtest = atoi(optarg); - break; - case 's' : - src = optarg; - break; - default : - fprintf(stderr, "Unknown option \"%c\"\n", c); - usage(name); - } - - if ((argc <= optind) || !argv[optind]) - usage(name); - dst = argv[optind++]; - - if (!src) - { - gethostname(host, sizeof(host)); - host[sizeof(host) - 1] = '\0'; - src = host; - } - - if (resolve(dst, (char *)&ip->ip_dst) == -1) - { - fprintf(stderr,"Cant resolve %s\n", dst); - exit(2); - } - - if (resolve(src, (char *)&ip->ip_src) == -1) - { - fprintf(stderr,"Cant resolve %s\n", src); - exit(2); - } - - if (!gateway) - gwip = ip->ip_dst; - else if (resolve(gateway, (char *)&gwip) == -1) - { - fprintf(stderr,"Cant resolve %s\n", gateway); - exit(2); - } - - - if (!dev) - dev = default_device; - printf("Device: %s\n", dev); - printf("Source: %s\n", inet_ntoa(ip->ip_src)); - printf("Dest: %s\n", inet_ntoa(ip->ip_dst)); - printf("Gateway: %s\n", inet_ntoa(gwip)); - printf("mtu: %d\n", mtu); - - switch (tests) - { - case 1 : - ip_test1(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - case 2 : - ip_test2(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - case 3 : - ip_test3(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - case 4 : - ip_test4(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - case 5 : - ip_test5(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - case 6 : - ip_test6(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - case 7 : - ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - default : - ip_test1(dev, mtu, (ip_t *)ti, gwip, pointtest); - ip_test2(dev, mtu, (ip_t *)ti, gwip, pointtest); - ip_test3(dev, mtu, (ip_t *)ti, gwip, pointtest); - ip_test4(dev, mtu, (ip_t *)ti, gwip, pointtest); - ip_test5(dev, mtu, (ip_t *)ti, gwip, pointtest); - ip_test6(dev, mtu, (ip_t *)ti, gwip, pointtest); - ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest); - break; - } - return 0; -} diff --git a/contrib/ipfilter/ipsend/iptests.c b/contrib/ipfilter/ipsend/iptests.c deleted file mode 100644 index 0ca02db..0000000 --- a/contrib/ipfilter/ipsend/iptests.c +++ /dev/null @@ -1,1426 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Copyright (C) 2012 by Darren Reed. - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#if defined(__NetBSD__) && defined(__vax__) -/* - * XXX need to declare boolean_t for _KERNEL <sys/files.h> - * which ends up including <sys/device.h> for vax. See PR#32907 - * for further details. - */ -typedef int boolean_t; -#endif -#include <sys/time.h> -#if !defined(__osf__) -# ifdef __NetBSD__ -# include <machine/lock.h> -# include <machine/mutex.h> -# endif -# define _KERNEL -# define KERNEL -# if !defined(solaris) && !defined(linux) && !defined(__sgi) && !defined(hpux) -# include <sys/file.h> -# else -# ifdef solaris -# include <sys/dditypes.h> -# endif -# endif -# undef _KERNEL -# undef KERNEL -#endif -#if !defined(solaris) && !defined(linux) && !defined(__sgi) -# include <nlist.h> -# include <sys/user.h> -# include <sys/proc.h> -#endif -#if !defined(ultrix) && !defined(hpux) && !defined(linux) && \ - !defined(__sgi) && !defined(__osf__) && !defined(_AIX51) -# include <kvm.h> -#endif -#ifndef ultrix -# include <sys/socket.h> -#endif -#if defined(solaris) -# include <sys/stream.h> -#else -# include <sys/socketvar.h> -#endif -#ifdef sun -#include <sys/systm.h> -#include <sys/session.h> -#endif -#if BSD >= 199103 -# include <sys/sysctl.h> -# include <sys/filedesc.h> -# include <paths.h> -#endif -#include <netinet/in_systm.h> -#include <sys/socket.h> -#ifdef __hpux -# define _NET_ROUTE_INCLUDED -#endif -#include <net/if.h> -#if defined(linux) && (LINUX >= 0200) -# include <asm/atomic.h> -#endif -#if !defined(linux) -# if defined(__FreeBSD__) -# include "radix_ipf.h" -# endif -# if !defined(solaris) -# include <net/route.h> -# endif -#else -# define __KERNEL__ /* because there's a macro not wrapped by this */ -# include <net/route.h> /* in this file :-/ */ -#endif -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netinet/ip.h> -#if defined(__SVR4) || defined(__svr4__) || defined(__sgi) -# include <sys/sysmacros.h> -#endif -#include <stdio.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#ifdef __hpux -# undef _NET_ROUTE_INCLUDED -#endif -#if !defined(linux) -# include <netinet/ip_var.h> -# if !defined(__hpux) && !defined(solaris) -# include <netinet/in_pcb.h> -# endif -#endif -#include "ipsend.h" -#if !defined(linux) && !defined(__hpux) -# include <netinet/tcp_timer.h> -# include <netinet/tcp_var.h> -#endif -#if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106000000) -# define USE_NANOSLEEP -#endif - - -#ifdef USE_NANOSLEEP -# define PAUSE() ts.tv_sec = 0; ts.tv_nsec = 10000000; \ - (void) nanosleep(&ts, NULL) -#else -# define PAUSE() tv.tv_sec = 0; tv.tv_usec = 10000; \ - (void) select(0, NULL, NULL, NULL, &tv) -#endif - - -void ip_test1(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - udphdr_t *u; - int nfd, i = 0, len, id = getpid(); - - IP_HL_A(ip, sizeof(*ip) >> 2); - IP_V_A(ip, IPVERSION); - ip->ip_tos = 0; - ip->ip_off = 0; - ip->ip_ttl = 60; - ip->ip_p = IPPROTO_UDP; - ip->ip_sum = 0; - u = (udphdr_t *)(ip + 1); - u->uh_sport = htons(1); - u->uh_dport = htons(9); - u->uh_sum = 0; - u->uh_ulen = htons(sizeof(*u) + 4); - ip->ip_len = sizeof(*ip) + ntohs(u->uh_ulen); - len = ip->ip_len; - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - if (!ptest || (ptest == 1)) { - /* - * Part1: hl < len - */ - ip->ip_id = 0; - printf("1.1. sending packets with ip_hl < ip_len\n"); - for (i = 0; i < ((sizeof(*ip) + ntohs(u->uh_ulen)) >> 2); i++) { - IP_HL_A(ip, i >> 2); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 2)) { - /* - * Part2: hl > len - */ - ip->ip_id = 0; - printf("1.2. sending packets with ip_hl > ip_len\n"); - for (; i < ((sizeof(*ip) * 2 + ntohs(u->uh_ulen)) >> 2); i++) { - IP_HL_A(ip, i >> 2); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 3)) { - /* - * Part3: v < 4 - */ - ip->ip_id = 0; - printf("1.3. ip_v < 4\n"); - IP_HL_A(ip, sizeof(*ip) >> 2); - for (i = 0; i < 4; i++) { - IP_V_A(ip, i); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 4)) { - /* - * Part4: v > 4 - */ - ip->ip_id = 0; - printf("1.4. ip_v > 4\n"); - for (i = 5; i < 16; i++) { - IP_V_A(ip, i); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 5)) { - /* - * Part5: len < packet - */ - ip->ip_id = 0; - IP_V_A(ip, IPVERSION); - i = ip->ip_len + 1; - printf("1.5.0 ip_len < packet size (size++, long packets)\n"); - for (; i < (ip->ip_len * 2); i++) { - ip->ip_id = htons(id++); - ip->ip_sum = 0; - ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); - (void) send_ether(nfd, (char *)ip, i, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - printf("1.5.1 ip_len < packet size (ip_len-, short packets)\n"); - for (i = len; i > 0; i--) { - ip->ip_id = htons(id++); - ip->ip_len = i; - ip->ip_sum = 0; - ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); - (void) send_ether(nfd, (char *)ip, len, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 6)) { - /* - * Part6: len > packet - */ - ip->ip_id = 0; - printf("1.6.0 ip_len > packet size (increase ip_len)\n"); - for (i = len + 1; i < (len * 2); i++) { - ip->ip_id = htons(id++); - ip->ip_len = i; - ip->ip_sum = 0; - ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); - (void) send_ether(nfd, (char *)ip, len, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - ip->ip_len = len; - printf("1.6.1 ip_len > packet size (size--, short packets)\n"); - for (i = len; i > 0; i--) { - ip->ip_id = htons(id++); - ip->ip_sum = 0; - ip->ip_sum = chksum((u_short *)ip, IP_HL(ip) << 2); - (void) send_ether(nfd, (char *)ip, i, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 7)) { - /* - * Part7: 0 length fragment - */ - printf("1.7.0 Zero length fragments (ip_off = 0x2000)\n"); - ip->ip_id = 0; - ip->ip_len = sizeof(*ip); - ip->ip_off = htons(IP_MF); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("1.7.1 Zero length fragments (ip_off = 0x3000)\n"); - ip->ip_id = 0; - ip->ip_len = sizeof(*ip); - ip->ip_off = htons(IP_MF); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("1.7.2 Zero length fragments (ip_off = 0xa000)\n"); - ip->ip_id = 0; - ip->ip_len = sizeof(*ip); - ip->ip_off = htons(0xa000); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("1.7.3 Zero length fragments (ip_off = 0x0100)\n"); - ip->ip_id = 0; - ip->ip_len = sizeof(*ip); - ip->ip_off = htons(0x0100); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - } - - if (!ptest || (ptest == 8)) { - struct timeval tv; - - gettimeofday(&tv, NULL); - srand(tv.tv_sec ^ getpid() ^ tv.tv_usec); - /* - * Part8.1: 63k packet + 1k fragment at offset 0x1ffe - * Mark it as being ICMP (so it doesn't get junked), but - * don't bother about the ICMP header, we're not worrying - * about that here. - */ - ip->ip_p = IPPROTO_ICMP; - ip->ip_off = htons(IP_MF); - u->uh_dport = htons(9); - ip->ip_id = htons(id++); - printf("1.8.1 63k packet + 1k fragment at offset 0x1ffe\n"); - ip->ip_len = 768 + 20 + 8; - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - - ip->ip_len = MIN(768 + 20, mtu - 68); - i = 512; - for (; i < (63 * 1024 + 768); i += 768) { - ip->ip_off = htons(IP_MF | (i >> 3)); - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - ip->ip_len = 896 + 20; - ip->ip_off = htons(i >> 3); - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - putchar('\n'); - fflush(stdout); - - /* - * Part8.2: 63k packet + 1k fragment at offset 0x1ffe - * Mark it as being ICMP (so it doesn't get junked), but - * don't bother about the ICMP header, we're not worrying - * about that here. (Lossage here) - */ - ip->ip_p = IPPROTO_ICMP; - ip->ip_off = htons(IP_MF); - u->uh_dport = htons(9); - ip->ip_id = htons(id++); - printf("1.8.2 63k packet + 1k fragment at offset 0x1ffe\n"); - ip->ip_len = 768 + 20 + 8; - if ((rand() & 0x1f) != 0) { - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - } else - printf("skip 0\n"); - - ip->ip_len = MIN(768 + 20, mtu - 68); - i = 512; - for (; i < (63 * 1024 + 768); i += 768) { - ip->ip_off = htons(IP_MF | (i >> 3)); - if ((rand() & 0x1f) != 0) { - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - } else - printf("skip %d\n", i); - fflush(stdout); - PAUSE(); - } - ip->ip_len = 896 + 20; - ip->ip_off = htons(i >> 3); - if ((rand() & 0x1f) != 0) { - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - } else - printf("skip\n"); - putchar('\n'); - fflush(stdout); - - /* - * Part8.3: 33k packet - test for not dealing with -ve length - * Mark it as being ICMP (so it doesn't get junked), but - * don't bother about the ICMP header, we're not worrying - * about that here. - */ - ip->ip_p = IPPROTO_ICMP; - ip->ip_off = htons(IP_MF); - u->uh_dport = htons(9); - ip->ip_id = htons(id++); - printf("1.8.3 33k packet\n"); - ip->ip_len = 768 + 20 + 8; - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - - ip->ip_len = MIN(768 + 20, mtu - 68); - i = 512; - for (; i < (32 * 1024 + 768); i += 768) { - ip->ip_off = htons(IP_MF | (i >> 3)); - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - ip->ip_len = 896 + 20; - ip->ip_off = htons(i >> 3); - (void) send_ip(nfd, mtu, ip, gwip, 1); - printf("%d\r", i); - putchar('\n'); - fflush(stdout); - } - - ip->ip_len = len; - ip->ip_off = 0; - if (!ptest || (ptest == 9)) { - /* - * Part9: off & 0x8000 == 0x8000 - */ - ip->ip_id = 0; - ip->ip_off = htons(0x8000); - printf("1.9. ip_off & 0x8000 == 0x8000\n"); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - } - - ip->ip_off = 0; - - if (!ptest || (ptest == 10)) { - /* - * Part10: ttl = 255 - */ - ip->ip_id = 0; - ip->ip_ttl = 255; - printf("1.10.0 ip_ttl = 255\n"); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - ip->ip_ttl = 128; - printf("1.10.1 ip_ttl = 128\n"); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - ip->ip_ttl = 0; - printf("1.10.2 ip_ttl = 0\n"); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - } - - (void) close(nfd); -} - - -void ip_test2(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - int nfd; - u_char *s; - - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - IP_HL_A(ip, 6); - ip->ip_len = IP_HL(ip) << 2; - s = (u_char *)(ip + 1); - s[IPOPT_OPTVAL] = IPOPT_NOP; - s++; - if (!ptest || (ptest == 1)) { - /* - * Test 1: option length > packet length, - * header length == packet length - */ - s[IPOPT_OPTVAL] = IPOPT_TS; - s[IPOPT_OLEN] = 4; - s[IPOPT_OFFSET] = IPOPT_MINOFF; - ip->ip_p = IPPROTO_IP; - printf("2.1 option length > packet length\n"); - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - } - - IP_HL_A(ip, 7); - ip->ip_len = IP_HL(ip) << 2; - if (!ptest || (ptest == 1)) { - /* - * Test 2: options have length = 0 - */ - printf("2.2.1 option length = 0, RR\n"); - s[IPOPT_OPTVAL] = IPOPT_RR; - s[IPOPT_OLEN] = 0; - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("2.2.2 option length = 0, TS\n"); - s[IPOPT_OPTVAL] = IPOPT_TS; - s[IPOPT_OLEN] = 0; - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("2.2.3 option length = 0, SECURITY\n"); - s[IPOPT_OPTVAL] = IPOPT_SECURITY; - s[IPOPT_OLEN] = 0; - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("2.2.4 option length = 0, LSRR\n"); - s[IPOPT_OPTVAL] = IPOPT_LSRR; - s[IPOPT_OLEN] = 0; - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("2.2.5 option length = 0, SATID\n"); - s[IPOPT_OPTVAL] = IPOPT_SATID; - s[IPOPT_OLEN] = 0; - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - - printf("2.2.6 option length = 0, SSRR\n"); - s[IPOPT_OPTVAL] = IPOPT_SSRR; - s[IPOPT_OLEN] = 0; - (void) send_ip(nfd, mtu, ip, gwip, 1); - fflush(stdout); - PAUSE(); - } - - (void) close(nfd); -} - - -/* - * test 3 (ICMP) - */ -void ip_test3(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ - static int ict1[10] = { 8, 9, 10, 13, 14, 15, 16, 17, 18, 0 }; - static int ict2[8] = { 3, 9, 10, 13, 14, 17, 18, 0 }; -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - struct icmp *icp; - int nfd, i; - - IP_HL_A(ip, sizeof(*ip) >> 2); - IP_V_A(ip, IPVERSION); - ip->ip_tos = 0; - ip->ip_off = 0; - ip->ip_ttl = 60; - ip->ip_p = IPPROTO_ICMP; - ip->ip_sum = 0; - ip->ip_len = sizeof(*ip) + sizeof(*icp); - icp = (struct icmp *)((char *)ip + (IP_HL(ip) << 2)); - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - if (!ptest || (ptest == 1)) { - /* - * Type 0 - 31, 255, code = 0 - */ - bzero((char *)icp, sizeof(*icp)); - for (i = 0; i < 32; i++) { - icp->icmp_type = i; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, i); - } - icp->icmp_type = 255; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.1.%d ICMP type %d code 0 (all 0's)\r", i, 255); - putchar('\n'); - } - - if (!ptest || (ptest == 2)) { - /* - * Type 3, code = 0 - 31 - */ - icp->icmp_type = 3; - for (i = 0; i < 32; i++) { - icp->icmp_code = i; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.2.%d ICMP type 3 code %d (all 0's)\r", i, i); - } - } - - if (!ptest || (ptest == 3)) { - /* - * Type 4, code = 0,127,128,255 - */ - icp->icmp_type = 4; - icp->icmp_code = 0; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.3.1 ICMP type 4 code 0 (all 0's)\r"); - icp->icmp_code = 127; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.3.2 ICMP type 4 code 127 (all 0's)\r"); - icp->icmp_code = 128; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.3.3 ICMP type 4 code 128 (all 0's)\r"); - icp->icmp_code = 255; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.3.4 ICMP type 4 code 255 (all 0's)\r"); - } - - if (!ptest || (ptest == 4)) { - /* - * Type 5, code = 0,127,128,255 - */ - icp->icmp_type = 5; - icp->icmp_code = 0; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.4.1 ICMP type 5 code 0 (all 0's)\r"); - icp->icmp_code = 127; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.4.2 ICMP type 5 code 127 (all 0's)\r"); - icp->icmp_code = 128; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.4.3 ICMP type 5 code 128 (all 0's)\r"); - icp->icmp_code = 255; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.4.4 ICMP type 5 code 255 (all 0's)\r"); - } - - if (!ptest || (ptest == 5)) { - /* - * Type 8-10;13-18, code - 0,127,128,255 - */ - for (i = 0; ict1[i]; i++) { - icp->icmp_type = ict1[i]; - icp->icmp_code = 0; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type 5 code 0 (all 0's)\r", - i * 4); - icp->icmp_code = 127; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type 5 code 127 (all 0's)\r", - i * 4 + 1); - icp->icmp_code = 128; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type 5 code 128 (all 0's)\r", - i * 4 + 2); - icp->icmp_code = 255; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type 5 code 255 (all 0's)\r", - i * 4 + 3); - } - putchar('\n'); - } - - if (!ptest || (ptest == 6)) { - /* - * Type 12, code - 0,127,128,129,255 - */ - icp->icmp_type = 12; - icp->icmp_code = 0; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.6.1 ICMP type 12 code 0 (all 0's)\r"); - icp->icmp_code = 127; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.6.2 ICMP type 12 code 127 (all 0's)\r"); - icp->icmp_code = 128; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.6.3 ICMP type 12 code 128 (all 0's)\r"); - icp->icmp_code = 129; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.6.4 ICMP type 12 code 129 (all 0's)\r"); - icp->icmp_code = 255; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.6.5 ICMP type 12 code 255 (all 0's)\r"); - putchar('\n'); - } - - if (!ptest || (ptest == 7)) { - /* - * Type 3;9-10;13-14;17-18 - shorter packets - */ - ip->ip_len = sizeof(*ip) + sizeof(*icp) / 2; - for (i = 0; ict2[i]; i++) { - icp->icmp_type = ict1[i]; - icp->icmp_code = 0; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type %d code 0 (all 0's)\r", - i * 4, icp->icmp_type); - icp->icmp_code = 127; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type %d code 127 (all 0's)\r", - i * 4 + 1, icp->icmp_type); - icp->icmp_code = 128; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type %d code 128 (all 0's)\r", - i * 4 + 2, icp->icmp_type); - icp->icmp_code = 255; - (void) send_icmp(nfd, mtu, ip, gwip); - PAUSE(); - printf("3.5.%d ICMP type %d code 127 (all 0's)\r", - i * 4 + 3, icp->icmp_type); - } - putchar('\n'); - } -} - - -/* Perform test 4 (UDP) */ - -void ip_test4(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - udphdr_t *u; - int nfd, i; - - - IP_HL_A(ip, sizeof(*ip) >> 2); - IP_V_A(ip, IPVERSION); - ip->ip_tos = 0; - ip->ip_off = 0; - ip->ip_ttl = 60; - ip->ip_p = IPPROTO_UDP; - ip->ip_sum = 0; - u = (udphdr_t *)((char *)ip + (IP_HL(ip) << 2)); - u->uh_sport = htons(1); - u->uh_dport = htons(1); - u->uh_ulen = htons(sizeof(*u) + 4); - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - if (!ptest || (ptest == 1)) { - /* - * Test 1. ulen > packet - */ - u->uh_ulen = htons(sizeof(*u) + 4); - ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); - printf("4.1 UDP uh_ulen > packet size - short packets\n"); - for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { - u->uh_ulen = htons(i); - (void) send_udp(nfd, 1500, ip, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 2)) { - /* - * Test 2. ulen < packet - */ - u->uh_ulen = htons(sizeof(*u) + 4); - ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); - printf("4.2 UDP uh_ulen < packet size - short packets\n"); - for (i = ntohs(u->uh_ulen) * 2; i > sizeof(*u) + 4; i--) { - ip->ip_len = i; - (void) send_udp(nfd, 1500, ip, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 3)) { - /* - * Test 3: sport = 0, sport = 1, sport = 32767 - * sport = 32768, sport = 65535 - */ - u->uh_ulen = sizeof(*u) + 4; - ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); - printf("4.3.1 UDP sport = 0\n"); - u->uh_sport = 0; - (void) send_udp(nfd, 1500, ip, gwip); - printf("0\n"); - fflush(stdout); - PAUSE(); - printf("4.3.2 UDP sport = 1\n"); - u->uh_sport = htons(1); - (void) send_udp(nfd, 1500, ip, gwip); - printf("1\n"); - fflush(stdout); - PAUSE(); - printf("4.3.3 UDP sport = 32767\n"); - u->uh_sport = htons(32767); - (void) send_udp(nfd, 1500, ip, gwip); - printf("32767\n"); - fflush(stdout); - PAUSE(); - printf("4.3.4 UDP sport = 32768\n"); - u->uh_sport = htons(32768); - (void) send_udp(nfd, 1500, ip, gwip); - printf("32768\n"); - putchar('\n'); - fflush(stdout); - PAUSE(); - printf("4.3.5 UDP sport = 65535\n"); - u->uh_sport = htons(65535); - (void) send_udp(nfd, 1500, ip, gwip); - printf("65535\n"); - fflush(stdout); - PAUSE(); - } - - if (!ptest || (ptest == 4)) { - /* - * Test 4: dport = 0, dport = 1, dport = 32767 - * dport = 32768, dport = 65535 - */ - u->uh_ulen = ntohs(sizeof(*u) + 4); - u->uh_sport = htons(1); - ip->ip_len = (IP_HL(ip) << 2) + ntohs(u->uh_ulen); - printf("4.4.1 UDP dport = 0\n"); - u->uh_dport = 0; - (void) send_udp(nfd, 1500, ip, gwip); - printf("0\n"); - fflush(stdout); - PAUSE(); - printf("4.4.2 UDP dport = 1\n"); - u->uh_dport = htons(1); - (void) send_udp(nfd, 1500, ip, gwip); - printf("1\n"); - fflush(stdout); - PAUSE(); - printf("4.4.3 UDP dport = 32767\n"); - u->uh_dport = htons(32767); - (void) send_udp(nfd, 1500, ip, gwip); - printf("32767\n"); - fflush(stdout); - PAUSE(); - printf("4.4.4 UDP dport = 32768\n"); - u->uh_dport = htons(32768); - (void) send_udp(nfd, 1500, ip, gwip); - printf("32768\n"); - fflush(stdout); - PAUSE(); - printf("4.4.5 UDP dport = 65535\n"); - u->uh_dport = htons(65535); - (void) send_udp(nfd, 1500, ip, gwip); - printf("65535\n"); - fflush(stdout); - PAUSE(); - } - - if (!ptest || (ptest == 5)) { - /* - * Test 5: sizeof(ip_t) <= MTU <= sizeof(udphdr_t) + - * sizeof(ip_t) - */ - printf("4.5 UDP 20 <= MTU <= 32\n"); - for (i = sizeof(*ip); i <= ntohs(u->uh_ulen); i++) { - (void) send_udp(nfd, i, ip, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } -} - - -/* Perform test 5 (TCP) */ - -void ip_test5(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - tcphdr_t *t; - int nfd, i; - - t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2)); -#if !defined(linux) && !defined(__osf__) - t->th_x2 = 0; -#endif - TCP_OFF_A(t, 0); - t->th_sport = htons(1); - t->th_dport = htons(1); - t->th_win = htons(4096); - t->th_urp = 0; - t->th_sum = 0; - t->th_seq = htonl(1); - t->th_ack = 0; - ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - if (!ptest || (ptest == 1)) { - /* - * Test 1: flags variations, 0 - 3f - */ - TCP_OFF_A(t, sizeof(*t) >> 2); - printf("5.1 Test TCP flag combinations\n"); - for (i = 0; i <= (TH_URG|TH_ACK|TH_PUSH|TH_RST|TH_SYN|TH_FIN); - i++) { - t->th_flags = i; - (void) send_tcp(nfd, mtu, ip, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - } - - if (!ptest || (ptest == 2)) { - t->th_flags = TH_SYN; - /* - * Test 2: seq = 0, seq = 1, seq = 0x7fffffff, seq=0x80000000, - * seq = 0xa000000, seq = 0xffffffff - */ - printf("5.2.1 TCP seq = 0\n"); - t->th_seq = htonl(0); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.2.2 TCP seq = 1\n"); - t->th_seq = htonl(1); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.2.3 TCP seq = 0x7fffffff\n"); - t->th_seq = htonl(0x7fffffff); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.2.4 TCP seq = 0x80000000\n"); - t->th_seq = htonl(0x80000000); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.2.5 TCP seq = 0xc0000000\n"); - t->th_seq = htonl(0xc0000000); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.2.6 TCP seq = 0xffffffff\n"); - t->th_seq = htonl(0xffffffff); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - } - - if (!ptest || (ptest == 3)) { - t->th_flags = TH_ACK; - /* - * Test 3: ack = 0, ack = 1, ack = 0x7fffffff, ack = 0x8000000 - * ack = 0xa000000, ack = 0xffffffff - */ - printf("5.3.1 TCP ack = 0\n"); - t->th_ack = 0; - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.3.2 TCP ack = 1\n"); - t->th_ack = htonl(1); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.3.3 TCP ack = 0x7fffffff\n"); - t->th_ack = htonl(0x7fffffff); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.3.4 TCP ack = 0x80000000\n"); - t->th_ack = htonl(0x80000000); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.3.5 TCP ack = 0xc0000000\n"); - t->th_ack = htonl(0xc0000000); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.3.6 TCP ack = 0xffffffff\n"); - t->th_ack = htonl(0xffffffff); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - } - - if (!ptest || (ptest == 4)) { - t->th_flags = TH_SYN; - /* - * Test 4: win = 0, win = 32768, win = 65535 - */ - printf("5.4.1 TCP win = 0\n"); - t->th_seq = htonl(0); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.4.2 TCP win = 32768\n"); - t->th_seq = htonl(0x7fff); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.4.3 TCP win = 65535\n"); - t->th_win = htons(0xffff); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - } - -#if !defined(linux) && !defined(__SVR4) && !defined(__svr4__) && \ - !defined(__sgi) && !defined(__hpux) && !defined(__osf__) - { - struct tcpcb *tcbp, tcb; - struct tcpiphdr ti; - struct sockaddr_in sin; - int fd; - socklen_t slen; - - bzero((char *)&sin, sizeof(sin)); - - for (i = 1; i < 63; i++) { - fd = socket(AF_INET, SOCK_STREAM, 0); - bzero((char *)&sin, sizeof(sin)); - sin.sin_addr.s_addr = ip->ip_dst.s_addr; - sin.sin_port = htons(i); - sin.sin_family = AF_INET; - if (!connect(fd, (struct sockaddr *)&sin, sizeof(sin))) - break; - close(fd); - } - - if (i == 63) { - printf("Couldn't open a TCP socket between ports 1 and 63\n"); - printf("to host %s for test 5 and 6 - skipping.\n", - inet_ntoa(ip->ip_dst)); - goto skip_five_and_six; - } - - bcopy((char *)ip, (char *)&ti, sizeof(*ip)); - t->th_dport = htons(i); - slen = sizeof(sin); - if (!getsockname(fd, (struct sockaddr *)&sin, &slen)) - t->th_sport = sin.sin_port; - if (!(tcbp = find_tcp(fd, &ti))) { - printf("Can't find PCB\n"); - goto skip_five_and_six; - } - KMCPY(&tcb, tcbp, sizeof(tcb)); - ti.ti_win = tcb.rcv_adv; - ti.ti_seq = htonl(tcb.snd_nxt - 1); - ti.ti_ack = tcb.rcv_nxt; - - if (!ptest || (ptest == 5)) { - /* - * Test 5: urp - */ - t->th_flags = TH_ACK|TH_URG; - printf("5.5.1 TCP Urgent pointer, sport %hu dport %hu\n", - ntohs(t->th_sport), ntohs(t->th_dport)); - t->th_urp = htons(1); - (void) send_tcp(nfd, mtu, ip, gwip); - PAUSE(); - - t->th_seq = htonl(tcb.snd_nxt); - ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t) + 1; - t->th_urp = htons(0x7fff); - (void) send_tcp(nfd, mtu, ip, gwip); - PAUSE(); - t->th_urp = htons(0x8000); - (void) send_tcp(nfd, mtu, ip, gwip); - PAUSE(); - t->th_urp = htons(0xffff); - (void) send_tcp(nfd, mtu, ip, gwip); - PAUSE(); - t->th_urp = 0; - t->th_flags &= ~TH_URG; - ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); - } - - if (!ptest || (ptest == 6)) { - /* - * Test 6: data offset, off = 0, off is inside, off is outside - */ - t->th_flags = TH_ACK; - printf("5.6.1 TCP off = 1-15, len = 40\n"); - for (i = 1; i < 16; i++) { - TCP_OFF_A(t, ntohs(i)); - (void) send_tcp(nfd, mtu, ip, gwip); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - ip->ip_len = sizeof(ip_t) + sizeof(tcphdr_t); - } - - (void) close(fd); - } -skip_five_and_six: -#endif - t->th_seq = htonl(1); - t->th_ack = htonl(1); - TCP_OFF_A(t, 0); - - if (!ptest || (ptest == 7)) { - t->th_flags = TH_SYN; - /* - * Test 7: sport = 0, sport = 1, sport = 32767 - * sport = 32768, sport = 65535 - */ - printf("5.7.1 TCP sport = 0\n"); - t->th_sport = 0; - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.7.2 TCP sport = 1\n"); - t->th_sport = htons(1); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.7.3 TCP sport = 32767\n"); - t->th_sport = htons(32767); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.7.4 TCP sport = 32768\n"); - t->th_sport = htons(32768); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.7.5 TCP sport = 65535\n"); - t->th_sport = htons(65535); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - } - - if (!ptest || (ptest == 8)) { - t->th_sport = htons(1); - t->th_flags = TH_SYN; - /* - * Test 8: dport = 0, dport = 1, dport = 32767 - * dport = 32768, dport = 65535 - */ - printf("5.8.1 TCP dport = 0\n"); - t->th_dport = 0; - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.8.2 TCP dport = 1\n"); - t->th_dport = htons(1); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.8.3 TCP dport = 32767\n"); - t->th_dport = htons(32767); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.8.4 TCP dport = 32768\n"); - t->th_dport = htons(32768); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - - printf("5.8.5 TCP dport = 65535\n"); - t->th_dport = htons(65535); - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - } - - /* LAND attack - self connect, so make src & dst ip/port the same */ - if (!ptest || (ptest == 9)) { - printf("5.9 TCP LAND attack. sport = 25, dport = 25\n"); - /* chose SMTP port 25 */ - t->th_sport = htons(25); - t->th_dport = htons(25); - t->th_flags = TH_SYN; - ip->ip_src = ip->ip_dst; - (void) send_tcp(nfd, mtu, ip, gwip); - fflush(stdout); - PAUSE(); - } - - /* TCP options header checking */ - /* 0 length options, etc */ -} - - -/* Perform test 6 (exhaust mbuf test) */ - -void ip_test6(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - udphdr_t *u; - int nfd, i, j, k; - - IP_V_A(ip, IPVERSION); - ip->ip_tos = 0; - ip->ip_off = 0; - ip->ip_ttl = 60; - ip->ip_p = IPPROTO_UDP; - ip->ip_sum = 0; - u = (udphdr_t *)(ip + 1); - u->uh_sport = htons(1); - u->uh_dport = htons(9); - u->uh_sum = 0; - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - u->uh_ulen = htons(7168); - - printf("6. Exhaustive mbuf test.\n"); - printf(" Send 7k packet in 768 & 128 byte fragments, 128 times.\n"); - printf(" Total of around 8,900 packets\n"); - for (i = 0; i < 128; i++) { - /* - * First send the entire packet in 768 byte chunks. - */ - ip->ip_len = sizeof(*ip) + 768 + sizeof(*u); - IP_HL_A(ip, sizeof(*ip) >> 2); - ip->ip_off = htons(IP_MF); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d %d\r", i, 0); - fflush(stdout); - PAUSE(); - /* - * And again using 128 byte chunks. - */ - ip->ip_len = sizeof(*ip) + 128 + sizeof(*u); - ip->ip_off = htons(IP_MF); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d %d\r", i, 0); - fflush(stdout); - PAUSE(); - - for (j = 768; j < 3584; j += 768) { - ip->ip_len = sizeof(*ip) + 768; - ip->ip_off = htons(IP_MF|(j>>3)); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d %d\r", i, j); - fflush(stdout); - PAUSE(); - - ip->ip_len = sizeof(*ip) + 128; - for (k = j - 768; k < j; k += 128) { - ip->ip_off = htons(IP_MF|(k>>3)); - (void) send_ip(nfd, 1500, ip, gwip, 1); - printf("%d %d\r", i, k); - fflush(stdout); - PAUSE(); - } - } - } - putchar('\n'); -} - - -/* Perform test 7 (random packets) */ - -static u_long tbuf[64]; - -void ip_test7(dev, mtu, ip, gwip, ptest) - char *dev; - int mtu; - ip_t *ip; - struct in_addr gwip; - int ptest; -{ - ip_t *pip; -#ifdef USE_NANOSLEEP - struct timespec ts; -#else - struct timeval tv; -#endif - int nfd, i, j; - u_char *s; - - nfd = initdevice(dev, 1); - if (nfd == -1) - return; - - pip = (ip_t *)tbuf; - - srand(time(NULL) ^ (getpid() * getppid())); - - printf("7. send 1024 random IP packets.\n"); - - for (i = 0; i < 512; i++) { - for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) - *s = (rand() >> 13) & 0xff; - IP_V_A(pip, IPVERSION); - bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, - sizeof(struct in_addr)); - pip->ip_sum = 0; - pip->ip_len &= 0xff; - (void) send_ip(nfd, mtu, pip, gwip, 0); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); - - for (i = 0; i < 512; i++) { - for (s = (u_char *)pip, j = 0; j < sizeof(tbuf); j++, s++) - *s = (rand() >> 13) & 0xff; - IP_V_A(pip, IPVERSION); - pip->ip_off &= htons(0xc000); - bcopy((char *)&ip->ip_dst, (char *)&pip->ip_dst, - sizeof(struct in_addr)); - pip->ip_sum = 0; - pip->ip_len &= 0xff; - (void) send_ip(nfd, mtu, pip, gwip, 0); - printf("%d\r", i); - fflush(stdout); - PAUSE(); - } - putchar('\n'); -} diff --git a/contrib/ipfilter/ipsend/larp.c b/contrib/ipfilter/ipsend/larp.c deleted file mode 100644 index 5b79f73..0000000 --- a/contrib/ipfilter/ipsend/larp.c +++ /dev/null @@ -1,93 +0,0 @@ -/* $FreeBSD$ */ - -/* - * larp.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "@(#)larp.c 1.1 8/19/95 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <netinet/in.h> -#include <net/if.h> -#include <net/if_arp.h> -#include <stdio.h> -#include <netdb.h> -#include <errno.h> - -#include "ip_compat.h" -#include "iplang/iplang.h" - -/* - * lookup host and return - * its IP address in address - * (4 bytes) - */ -int resolve(host, address) - char *host, *address; -{ - struct hostent *hp; - u_long add; - - add = inet_addr(host); - if (add == -1) - { - if (!(hp = gethostbyname(host))) - { - fprintf(stderr, "unknown host: %s\n", host); - return -1; - } - bcopy((char *)hp->h_addr, (char *)address, 4); - return 0; - } - bcopy((char*)&add, address, 4); - return 0; -} - -/* - * ARP for the MAC address corresponding - * to the IP address. This taken from - * some BSD program, I cant remember which. - */ -int arp(ip, ether) - char *ip; - char *ether; -{ - static int s = -1; - struct arpreq ar; - struct sockaddr_in *sin; - char *inet_ntoa(); - -#ifdef IP_SEND - if (arp_getipv4(ip, ether) == 0) - return 0; -#endif - bzero((char *)&ar, sizeof(ar)); - sin = (struct sockaddr_in *)&ar.arp_pa; - sin->sin_family = AF_INET; - bcopy(ip, (char *)&sin->sin_addr.s_addr, 4); - - if (s == -1) - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - { - perror("arp: socket"); - return -1; - } - - if (ioctl(s, SIOCGARP, (caddr_t)&ar) == -1) - { - fprintf(stderr, "(%s):", inet_ntoa(sin->sin_addr)); - if (errno != ENXIO) - perror("SIOCGARP"); - return -1; - } - - bcopy(ar.arp_ha.sa_data, ether, 6); - return 0; -} diff --git a/contrib/ipfilter/ipsend/linux.h b/contrib/ipfilter/ipsend/linux.h deleted file mode 100644 index e738f3b..0000000 --- a/contrib/ipfilter/ipsend/linux.h +++ /dev/null @@ -1,19 +0,0 @@ -/* $FreeBSD$ */ - -/* - * Copyright (C) 2012 by Darren Reed. - * - * This code may be freely distributed as long as it retains this notice - * and is not changed in any way. The author accepts no responsibility - * for the use of this software. I hate legaleese, don't you ? - * - * @(#)linux.h 1.1 8/19/95 - */ - -#include <linux/config.h> -#ifdef MODULE -#include <linux/module.h> -#include <linux/version.h> -#endif /* MODULE */ - -#include "ip_compat.h" diff --git a/contrib/ipfilter/ipsend/lsock.c b/contrib/ipfilter/ipsend/lsock.c deleted file mode 100644 index 5cf2bf7..0000000 --- a/contrib/ipfilter/ipsend/lsock.c +++ /dev/null @@ -1,259 +0,0 @@ -/* $FreeBSD$ */ - -/* - * lsock.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "@(#)lsock.c 1.2 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <stddef.h> -#include <pwd.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/param.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <sys/dir.h> -#define __KERNEL__ -#if LINUX >= 0200 -# undef UINT_MAX -# undef INT_MAX -# undef ULONG_MAX -# undef LONG_MAX -# include <linux/notifier.h> -#endif -#include <linux/fs.h> -#if LINUX >= 0200 -#include "linux/netdevice.h" -#include "net/sock.h" -#endif -#undef __KERNEL__ -#include <linux/sched.h> -#include <linux/netdevice.h> -#include <nlist.h> -#include <sys/user.h> -#include <sys/socket.h> -#include <math.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <net/if.h> -#if LINUX < 0200 -#include <net/inet/sock.h> -#endif -#include "ipsend.h" - -int nproc; -struct task_struct *proc; - -#ifndef KMEM -# ifdef _PATH_KMEM -# define KMEM _PATH_KMEM -# endif -#endif -#ifndef KMEM -# define KMEM "/dev/kmem" -#endif -#ifndef KERNEL -# define KERNEL "/System.map" -#endif - -int kmemcpy(buf, pos, n) - char *buf; - void *pos; - int n; -{ - static int kfd = -1; - - if (kfd == -1) - kfd = open(KMEM, O_RDONLY); - - if (lseek(kfd, (off_t)pos, SEEK_SET) == -1) - { - perror("lseek"); - return -1; - } - if (read(kfd, buf, n) == -1) - { - perror("read"); - return -1; - } - return n; -} - -struct nlist names[3] = { - { "_task" }, - { "_nr_tasks" }, - { NULL } - }; - -struct task_struct *getproc() -{ - struct task_struct *p, **pp; - void *v; - pid_t pid = getpid(); - int siz, n; - - n = nlist(KERNEL, names); - if (n != 0) - { - fprintf(stderr, "nlist(%#x) == %d\n", names, n); - return NULL; - } - if (KMCPY(&nproc, names[1].n_value, sizeof(nproc)) == -1) - { - fprintf(stderr, "read nproc (%#x)\n", names[1].n_value); - return NULL; - } - siz = nproc * sizeof(struct task_struct *); - if (KMCPY(&v, names[0].n_value, sizeof(v)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) proc\n", - names[0].n_value, &v, sizeof(v)); - return NULL; - } - pp = (struct task_struct **)malloc(siz); - if (KMCPY(pp, v, siz) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) proc\n", - v, pp, siz); - return NULL; - } - proc = (struct task_struct *)malloc(siz); - for (n = 0; n < NR_TASKS; n++) - { - if (KMCPY((proc + n), pp[n], sizeof(*proc)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) proc\n", - pp[n], proc + n, sizeof(*proc)); - return NULL; - } - } - - p = proc; - - for (n = NR_TASKS; n; n--, p++) - if (p->pid == pid) - break; - if (!n) - return NULL; - - return p; -} - - -struct sock *find_tcp(fd, ti) - int fd; - struct tcpiphdr *ti; -{ - struct sock *s; - struct inode *i; - struct files_struct *fs; - struct task_struct *p; - struct file *f, **o; - - if (!(p = getproc())) - return NULL; - - fs = p->files; - o = (struct file **)calloc(1, sizeof(*o) * (fs->count + 1)); - if (KMCPY(o, fs->fd, (fs->count + 1) * sizeof(*o)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - fd - failed\n", - fs->fd, o, sizeof(*o)); - return NULL; - } - f = (struct file *)calloc(1, sizeof(*f)); - if (KMCPY(f, o[fd], sizeof(*f)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - o[fd] - failed\n", - o[fd], f, sizeof(*f)); - return NULL; - } - - i = (struct inode *)calloc(1, sizeof(*i)); - if (KMCPY(i, f->f_inode, sizeof(*i)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - f_inode - failed\n", - f->f_inode, i, sizeof(*i)); - return NULL; - } - return i->u.socket_i.data; -} - -int do_socket(dev, mtu, ti, gwip) - char *dev; - int mtu; - struct tcpiphdr *ti; - struct in_addr gwip; -{ - struct sockaddr_in rsin, lsin; - struct sock *s, sk; - int fd, nfd, len; - - printf("Dest. Port: %d\n", ti->ti_dport); - - fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd == -1) - { - perror("socket"); - return -1; - } - - if (fcntl(fd, F_SETFL, FNDELAY) == -1) - { - perror("fcntl"); - return -1; - } - - bzero((char *)&lsin, sizeof(lsin)); - lsin.sin_family = AF_INET; - bcopy((char *)&ti->ti_src, (char *)&lsin.sin_addr, - sizeof(struct in_addr)); - if (bind(fd, (struct sockaddr *)&lsin, sizeof(lsin)) == -1) - { - perror("bind"); - return -1; - } - len = sizeof(lsin); - (void) getsockname(fd, (struct sockaddr *)&lsin, &len); - ti->ti_sport = lsin.sin_port; - printf("sport %d\n", ntohs(lsin.sin_port)); - nfd = initdevice(dev, 0); - if (nfd == -1) - return -1; - - if (!(s = find_tcp(fd, ti))) - return -1; - - bzero((char *)&rsin, sizeof(rsin)); - rsin.sin_family = AF_INET; - bcopy((char *)&ti->ti_dst, (char *)&rsin.sin_addr, - sizeof(struct in_addr)); - rsin.sin_port = ti->ti_dport; - if (connect(fd, (struct sockaddr *)&rsin, sizeof(rsin)) == -1 && - errno != EINPROGRESS) - { - perror("connect"); - return -1; - } - KMCPY(&sk, s, sizeof(sk)); - ti->ti_win = sk.window; - ti->ti_seq = sk.sent_seq - 1; - ti->ti_ack = sk.rcv_ack_seq; - ti->ti_flags = TH_SYN; - - if (send_tcp(nfd, mtu, (ip_t *)ti, gwip) == -1) - return -1; - (void)write(fd, "Hello World\n", 12); - sleep(2); - close(fd); - return 0; -} diff --git a/contrib/ipfilter/ipsend/resend.c b/contrib/ipfilter/ipsend/resend.c deleted file mode 100644 index 45159bf..0000000 --- a/contrib/ipfilter/ipsend/resend.c +++ /dev/null @@ -1,143 +0,0 @@ -/* $FreeBSD$ */ - -/* - * resend.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <net/if.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#ifndef linux -# include <netinet/ip_var.h> -# include <netinet/if_ether.h> -#endif -#include <stdio.h> -#include <netdb.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include "ipsend.h" - -extern int opts; - -void dumppacket __P((ip_t *)); - - -void dumppacket(ip) - ip_t *ip; -{ - tcphdr_t *t; - int i, j; - - t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2)); - if (ip->ip_tos) - printf("tos %#x ", ip->ip_tos); - if (ip->ip_off & 0x3fff) - printf("frag @%#x ", (ip->ip_off & 0x1fff) << 3); - printf("len %d id %d ", ip->ip_len, ip->ip_id); - printf("ttl %d p %d src %s", ip->ip_ttl, ip->ip_p, - inet_ntoa(ip->ip_src)); - if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP) - printf(",%d", t->th_sport); - printf(" dst %s", inet_ntoa(ip->ip_dst)); - if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP) - printf(",%d", t->th_dport); - if (ip->ip_p == IPPROTO_TCP) { - printf(" seq %lu:%lu flags ", - (u_long)t->th_seq, (u_long)t->th_ack); - for (j = 0, i = 1; i < 256; i *= 2, j++) - if (t->th_flags & i) - printf("%c", "FSRPAU--"[j]); - } - putchar('\n'); -} - - -int ip_resend(dev, mtu, r, gwip, datain) - char *dev; - int mtu; - struct in_addr gwip; - struct ipread *r; - char *datain; -{ - ether_header_t *eh; - char dhost[6]; - ip_t *ip; - int fd, wfd = initdevice(dev, 5), len, i; - mb_t mb; - - if (wfd == -1) - return -1; - - if (datain) - fd = (*r->r_open)(datain); - else - fd = (*r->r_open)("-"); - - if (fd < 0) - exit(-1); - - ip = (struct ip *)mb.mb_buf; - eh = (ether_header_t *)malloc(sizeof(*eh)); - if(!eh) - { - perror("malloc failed"); - return -2; - } - - bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost)); - if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1)) - { - perror("arp"); - free(eh); - return -2; - } - - while ((i = (*r->r_readip)(&mb, NULL, NULL)) > 0) - { - if (!(opts & OPT_RAW)) { - len = ntohs(ip->ip_len); - eh = (ether_header_t *)realloc((char *)eh, sizeof(*eh) + len); - eh->ether_type = htons((u_short)ETHERTYPE_IP); - if (!gwip.s_addr) { - if (arp((char *)&gwip, - (char *)A_A eh->ether_dhost) == -1) { - perror("arp"); - continue; - } - } else - bcopy(dhost, (char *)A_A eh->ether_dhost, - sizeof(dhost)); - if (!ip->ip_sum) - ip->ip_sum = chksum((u_short *)ip, - IP_HL(ip) << 2); - bcopy(ip, (char *)(eh + 1), len); - len += sizeof(*eh); - dumppacket(ip); - } else { - eh = (ether_header_t *)mb.mb_buf; - len = i; - } - - if (sendip(wfd, (char *)eh, len) == -1) - { - perror("send_packet"); - break; - } - } - (*r->r_close)(); - free(eh); - return 0; -} diff --git a/contrib/ipfilter/ipsend/sbpf.c b/contrib/ipfilter/ipsend/sbpf.c deleted file mode 100644 index fcb66bc..0000000 --- a/contrib/ipfilter/ipsend/sbpf.c +++ /dev/null @@ -1,153 +0,0 @@ -/* $FreeBSD$ */ -/* - * (C)opyright 1995-1998 Darren Reed. (from tcplog) - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#include <sys/param.h> -#include <sys/types.h> -#include <sys/mbuf.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#if BSD < 199103 -#include <sys/fcntlcom.h> -#endif -#if (__FreeBSD_version >= 300000) -# include <sys/dirent.h> -#else -# include <sys/dir.h> -#endif -#include <net/bpf.h> - -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/udp.h> -#include <netinet/tcp.h> - -#include <stdio.h> -#include <netdb.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#ifdef __NetBSD__ -# include <paths.h> -#endif -#include <ctype.h> -#include <signal.h> -#include <errno.h> - -#include "ipsend.h" - -#if !defined(lint) -static const char sccsid[] = "@(#)sbpf.c 1.3 8/25/95 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif - -/* - * the code herein is dervied from libpcap. - */ -static u_char *buf = NULL; -static int bufsize = 0, timeout = 1; - - -int initdevice(device, tout) - char *device; - int tout; -{ - struct bpf_version bv; - struct timeval to; - struct ifreq ifr; -#ifdef _PATH_BPF - char *bpfname = _PATH_BPF; - int fd; - - if ((fd = open(bpfname, O_RDWR)) < 0) - { - fprintf(stderr, "no bpf devices available as /dev/bpfxx\n"); - return -1; - } -#else - char bpfname[16]; - int fd = 0, i; - - for (i = 0; i < 16; i++) - { - (void) sprintf(bpfname, "/dev/bpf%d", i); - if ((fd = open(bpfname, O_RDWR)) >= 0) - break; - } - if (i == 16) - { - fprintf(stderr, "no bpf devices available as /dev/bpfxx\n"); - return -1; - } -#endif - - if (ioctl(fd, BIOCVERSION, (caddr_t)&bv) < 0) - { - perror("BIOCVERSION"); - return -1; - } - if (bv.bv_major != BPF_MAJOR_VERSION || - bv.bv_minor < BPF_MINOR_VERSION) - { - fprintf(stderr, "kernel bpf (v%d.%d) filter out of date:\n", - bv.bv_major, bv.bv_minor); - fprintf(stderr, "current version: %d.%d\n", - BPF_MAJOR_VERSION, BPF_MINOR_VERSION); - return -1; - } - - (void) strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); - if (ioctl(fd, BIOCSETIF, &ifr) == -1) - { - fprintf(stderr, "%s(%d):", ifr.ifr_name, fd); - perror("BIOCSETIF"); - exit(1); - } - /* - * get kernel buffer size - */ - if (ioctl(fd, BIOCGBLEN, &bufsize) == -1) - { - perror("BIOCSBLEN"); - exit(-1); - } - buf = (u_char*)malloc(bufsize); - /* - * set the timeout - */ - timeout = tout; - to.tv_sec = 1; - to.tv_usec = 0; - if (ioctl(fd, BIOCSRTIMEOUT, (caddr_t)&to) == -1) - { - perror("BIOCSRTIMEOUT"); - exit(-1); - } - - (void) ioctl(fd, BIOCFLUSH, 0); - return fd; -} - - -/* - * output an IP packet onto a fd opened for /dev/bpf - */ -int sendip(fd, pkt, len) - int fd, len; - char *pkt; -{ - if (write(fd, pkt, len) == -1) - { - perror("send"); - return -1; - } - - return len; -} diff --git a/contrib/ipfilter/ipsend/sdlpi.c b/contrib/ipfilter/ipsend/sdlpi.c deleted file mode 100644 index 1aee2e4..0000000 --- a/contrib/ipfilter/ipsend/sdlpi.c +++ /dev/null @@ -1,173 +0,0 @@ -/* $FreeBSD$ */ - -/* - * (C)opyright 1992-1998 Darren Reed. (from tcplog) - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ - -#include <stdio.h> -#include <netdb.h> -#include <ctype.h> -#include <fcntl.h> -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/timeb.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#include <sys/stropts.h> - -#ifdef sun -# include <sys/pfmod.h> -# include <sys/bufmod.h> -#endif -#ifdef __osf__ -# include <sys/dlpihdr.h> -#else -# include <sys/dlpi.h> -#endif -#ifdef __hpux -# include <sys/dlpi_ext.h> -#endif - -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/if_ether.h> -#include <netinet/ip_var.h> -#include <netinet/udp.h> -#include <netinet/udp_var.h> -#include <netinet/tcp.h> - -#include "ipsend.h" - -#if !defined(lint) -static const char sccsid[] = "@(#)sdlpi.c 1.3 10/30/95 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif - -#define CHUNKSIZE 8192 -#define BUFSPACE (4*CHUNKSIZE) - - -/* - * Be careful to only include those defined in the flags option for the - * interface are included in the header size. - */ -int initdevice(device, tout) - char *device; - int tout; -{ - char devname[16], *s, buf[256]; - int i, fd; - - (void) strcpy(devname, "/dev/"); - (void) strncat(devname, device, sizeof(devname) - strlen(devname)); - - s = devname + 5; - while (*s && !ISDIGIT(*s)) - s++; - if (!*s) - { - fprintf(stderr, "bad device name %s\n", devname); - exit(-1); - } - i = atoi(s); - *s = '\0'; - /* - * For writing - */ - if ((fd = open(devname, O_RDWR)) < 0) - { - fprintf(stderr, "O_RDWR(1) "); - perror(devname); - exit(-1); - } - - if (dlattachreq(fd, i) == -1) - { - fprintf(stderr, "dlattachreq: DLPI error\n"); - exit(-1); - } - else if (dlokack(fd, buf) == -1) - { - fprintf(stderr, "dlokack(attach): DLPI error\n"); - exit(-1); - } -#ifdef DL_HP_RAWDLS - if (dlpromisconreq(fd, DL_PROMISC_SAP) < 0) - { - fprintf(stderr, "dlpromisconreq: DL_PROMISC_PHYS error\n"); - exit(-1); - } - else if (dlokack(fd, buf) < 0) - { - fprintf(stderr, "dlokack(promisc): DLPI error\n"); - exit(-1); - } - /* 22 is INSAP as per the HP-UX DLPI Programmer's Guide */ - - dlbindreq(fd, 22, 1, DL_HP_RAWDLS, 0, 0); -#else - dlbindreq(fd, ETHERTYPE_IP, 0, DL_CLDLS, 0, 0); -#endif - dlbindack(fd, buf); - /* - * write full headers - */ -#ifdef DLIOCRAW /* we require RAW DLPI mode, which is a Sun extension */ - if (strioctl(fd, DLIOCRAW, -1, 0, NULL) == -1) - { - fprintf(stderr, "DLIOCRAW error\n"); - exit(-1); - } -#endif - return fd; -} - - -/* - * output an IP packet onto a fd opened for /dev/nit - */ -int sendip(fd, pkt, len) - int fd, len; - char *pkt; -{ - struct strbuf dbuf, *dp = &dbuf, *cp = NULL; - int pri = 0; -#ifdef DL_HP_RAWDLS - struct strbuf cbuf; - dl_hp_rawdata_req_t raw; - - cp = &cbuf; - raw.dl_primitive = DL_HP_RAWDATA_REQ; - cp->len = sizeof(raw); - cp->buf = (char *)&raw; - cp->maxlen = cp->len; - pri = MSG_HIPRI; -#endif - /* - * construct NIT STREAMS messages, first control then data. - */ - dp->buf = pkt; - dp->len = len; - dp->maxlen = dp->len; - - if (putmsg(fd, cp, dp, pri) == -1) - { - perror("putmsg"); - return -1; - } - if (ioctl(fd, I_FLUSH, FLUSHW) == -1) - { - perror("I_FLUSHW"); - return -1; - } - return len; -} - diff --git a/contrib/ipfilter/ipsend/sirix.c b/contrib/ipfilter/ipsend/sirix.c deleted file mode 100644 index 3b565b1..0000000 --- a/contrib/ipfilter/ipsend/sirix.c +++ /dev/null @@ -1,93 +0,0 @@ -/* $FreeBSD$ */ - -/* - * (C)opyright 1992-1998 Darren Reed. - * (C)opyright 1997 Marc Boucher. - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#include <stdio.h> -#include <sys/types.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/socket.h> -#include <sys/ioctl.h> - -#include <net/if.h> -#include <net/raw.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/if_ether.h> -#include <netinet/ip_var.h> -#include "ipsend.h" -#include <netinet/udp_var.h> - -#if !defined(lint) && defined(LIBC_SCCS) -static char sirix[] = "@(#)sirix.c 1.0 10/9/97 (C)1997 Marc Boucher"; -#endif - - -int initdevice(char *device, int tout) -{ - int fd; - struct sockaddr_raw sr; - - if ((fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN)) < 0) - { - perror("socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN)"); - return -1; - } - - memset(&sr, 0, sizeof(sr)); - sr.sr_family = AF_RAW; - sr.sr_port = ETHERTYPE_IP; - strncpy(sr.sr_ifname, device, sizeof(sr.sr_ifname)); - if (bind(fd, &sr, sizeof(sr)) < 0) - { - perror("bind AF_RAW"); - close(fd); - return -1; - } - return fd; -} - - -/* - * output an IP packet - */ -int sendip(int fd, char *pkt, int len) -{ - struct sockaddr_raw sr; - int srlen = sizeof(sr); - struct ifreq ifr; - struct ether_header *eh = (struct ether_header *)pkt; - - if (getsockname(fd, &sr, &srlen) == -1) - { - perror("getsockname"); - return -1; - } - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, sr.sr_ifname, sizeof ifr.ifr_name); - - if (ioctl(fd, SIOCGIFADDR, &ifr) == -1) - { - perror("ioctl SIOCGIFADDR"); - return -1; - } - - memcpy(eh->ether_shost, ifr.ifr_addr.sa_data, sizeof(eh->ether_shost)); - - if (write(fd, pkt, len) == -1) - { - perror("send"); - return -1; - } - - return len; -} diff --git a/contrib/ipfilter/ipsend/slinux.c b/contrib/ipfilter/ipsend/slinux.c deleted file mode 100644 index 7405d5e..0000000 --- a/contrib/ipfilter/ipsend/slinux.c +++ /dev/null @@ -1,92 +0,0 @@ -/* $FreeBSD$ */ - -/* - * (C)opyright 1992-1998 Darren Reed. (from tcplog) - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ - -#include <stdio.h> -#include <string.h> -#include <netdb.h> -#include <ctype.h> -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/timeb.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#include <sys/dir.h> -#include <linux/netdevice.h> -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/tcp.h> -#include "ipsend.h" - -#if !defined(lint) -static const char sccsid[] = "@(#)slinux.c 1.2 8/25/95"; -static const char rcsid[] = "@(#)$Id$"; -#endif - -#define CHUNKSIZE 8192 -#define BUFSPACE (4*CHUNKSIZE) - -/* - * Be careful to only include those defined in the flags option for the - * interface are included in the header size. - */ - -static int timeout; -static char *eth_dev = NULL; - - -int initdevice(dev, spare) - char *dev; - int spare; -{ - int fd; - - eth_dev = strdup(dev); - if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1) - { - perror("socket(SOCK_PACKET)"); - exit(-1); - } - - return fd; -} - - -/* - * output an IP packet onto a fd opened for /dev/nit - */ -int sendip(fd, pkt, len) - int fd, len; - char *pkt; -{ - struct sockaddr s; - struct ifreq ifr; - - strncpy(ifr.ifr_name, eth_dev, sizeof(ifr.ifr_name)); - if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) - { - perror("SIOCGIFHWADDR"); - return -1; - } - bcopy(ifr.ifr_hwaddr.sa_data, pkt + 6, 6); - s.sa_family = ETHERTYPE_IP; - strncpy(s.sa_data, eth_dev, sizeof(s.sa_data)); - - if (sendto(fd, pkt, len, 0, &s, sizeof(s)) == -1) - { - perror("send"); - return -1; - } - - return len; -} diff --git a/contrib/ipfilter/ipsend/snit.c b/contrib/ipfilter/ipsend/snit.c deleted file mode 100644 index 0d75b4e..0000000 --- a/contrib/ipfilter/ipsend/snit.c +++ /dev/null @@ -1,160 +0,0 @@ -/* $FreeBSD$ */ - -/* - * (C)opyright 1992-1998 Darren Reed. (from tcplog) - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ - -#include <stdio.h> -#include <netdb.h> -#include <ctype.h> -#include <signal.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/timeb.h> -#include <sys/socket.h> -#include <sys/file.h> -#include <sys/ioctl.h> -#include <net/nit.h> -#include <sys/fcntlcom.h> -#include <sys/dir.h> -#include <net/nit_if.h> -#include <net/nit_pf.h> -#include <net/nit_buf.h> -#include <net/packetfilt.h> -#include <sys/stropts.h> - -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/if_ether.h> -#include <netinet/ip_var.h> -#include <netinet/udp.h> -#include <netinet/udp_var.h> -#include <netinet/tcp.h> - -#include "ipsend.h" - -#if !defined(lint) -static const char sccsid[] = "@(#)snit.c 1.5 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif - -#define CHUNKSIZE 8192 -#define BUFSPACE (4*CHUNKSIZE) - -/* - * Be careful to only include those defined in the flags option for the - * interface are included in the header size. - */ -#define BUFHDR_SIZE (sizeof(struct nit_bufhdr)) -#define NIT_HDRSIZE (BUFHDR_SIZE) - -static int timeout; - - -int initdevice(device, tout) - char *device; - int tout; -{ - struct strioctl si; - struct timeval to; - struct ifreq ifr; - int fd; - - if ((fd = open("/dev/nit", O_RDWR)) < 0) - { - perror("/dev/nit"); - exit(-1); - } - - /* - * arrange to get messages from the NIT STREAM and use NIT_BUF option - */ - ioctl(fd, I_SRDOPT, (char*)RMSGD); - ioctl(fd, I_PUSH, "nbuf"); - - /* - * set the timeout - */ - timeout = tout; - si.ic_timout = 1; - to.tv_sec = 1; - to.tv_usec = 0; - si.ic_cmd = NIOCSTIME; - si.ic_len = sizeof(to); - si.ic_dp = (char*)&to; - if (ioctl(fd, I_STR, (char*)&si) == -1) - { - perror("ioctl: NIT timeout"); - exit(-1); - } - - /* - * request the interface - */ - strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); - ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = ' '; - si.ic_cmd = NIOCBIND; - si.ic_len = sizeof(ifr); - si.ic_dp = (char*)𝔦 - if (ioctl(fd, I_STR, (char*)&si) == -1) - { - perror(ifr.ifr_name); - exit(1); - } - return fd; -} - - -/* - * output an IP packet onto a fd opened for /dev/nit - */ -int sendip(fd, pkt, len) - int fd, len; - char *pkt; -{ - struct sockaddr sk, *sa = &sk; - struct strbuf cbuf, *cp = &cbuf, dbuf, *dp = &dbuf; - - /* - * For ethernet, need at least 802.3 header and IP header. - */ - if (len < (sizeof(sa->sa_data) + sizeof(struct ip))) - return -1; - /* - * to avoid any output processing for IP, say we're not. - */ - sa->sa_family = AF_UNSPEC; - bcopy(pkt, sa->sa_data, sizeof(sa->sa_data)); - pkt += sizeof(sa->sa_data); - len -= sizeof(sa->sa_data); - - /* - * construct NIT STREAMS messages, first control then data. - */ - cp->len = sizeof(*sa); - cp->maxlen = sizeof(*sa); - cp->buf = (char *)sa; - - dp->buf = pkt; - dp->len = len; - dp->maxlen = dp->len; - - if (putmsg(fd, cp, dp, 0) == -1) - { - perror("putmsg"); - return -1; - } - - if (ioctl(fd, I_FLUSH, FLUSHW) == -1) - { - perror("I_FLUSH"); - return -1; - } - return len; -} diff --git a/contrib/ipfilter/ipsend/sock.c b/contrib/ipfilter/ipsend/sock.c deleted file mode 100644 index 6d0f3db..0000000 --- a/contrib/ipfilter/ipsend/sock.c +++ /dev/null @@ -1,457 +0,0 @@ -/* $FreeBSD$ */ -/* - * sock.c (C) 1995-1998 Darren Reed - * - * See the IPFILTER.LICENCE file for details on licencing. - * - */ -#if !defined(lint) -static const char sccsid[] = "@(#)sock.c 1.2 1/11/96 (C)1995 Darren Reed"; -static const char rcsid[] = "@(#)$Id$"; -#endif -#include <sys/param.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/stat.h> -#if defined(__NetBSD__) && defined(__vax__) -/* - * XXX need to declare boolean_t for _KERNEL <sys/files.h> - * which ends up including <sys/device.h> for vax. See PR#32907 - * for further details. - */ -typedef int boolean_t; -#endif -#ifndef ultrix -#include <fcntl.h> -#endif -#if (__FreeBSD_version >= 300000) -# include <sys/dirent.h> -#else -# include <sys/dir.h> -#endif -#if !defined(__osf__) -# ifdef __NetBSD__ -# include <machine/lock.h> -# endif -# ifdef __FreeBSD__ -# define _WANT_FILE -# else -# define _KERNEL -# define KERNEL -# endif -# ifdef ultrix -# undef LOCORE -# include <sys/smp_lock.h> -# endif -# include <sys/file.h> -# ifdef __FreeBSD__ -# undef _WANT_FILE -# else -# undef _KERNEL -# undef KERNEL -# endif -#endif -#include <nlist.h> -#include <sys/user.h> -#include <sys/socket.h> -#include <sys/socketvar.h> -#include <sys/proc.h> -#if !defined(ultrix) && !defined(hpux) && !defined(__osf__) -# include <kvm.h> -#endif -#ifdef sun -#include <sys/systm.h> -#include <sys/session.h> -#endif -#if BSD >= 199103 -#include <sys/sysctl.h> -#include <sys/filedesc.h> -#include <paths.h> -#endif -#include <math.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/tcp.h> -#include <net/if.h> -#ifndef __osf__ -# include <net/route.h> -#endif -#include <netinet/ip_var.h> -#include <netinet/in_pcb.h> -#include <netinet/tcp_timer.h> -#include <netinet/tcp_var.h> -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <stdlib.h> -#include <stddef.h> -#include <pwd.h> -#include "ipsend.h" - - -int nproc; -struct proc *proc; - -#ifndef KMEM -# ifdef _PATH_KMEM -# define KMEM _PATH_KMEM -# endif -#endif -#ifndef KERNEL -# ifdef _PATH_UNIX -# define KERNEL _PATH_UNIX -# endif -#endif -#ifndef KMEM -# define KMEM "/dev/kmem" -#endif -#ifndef KERNEL -# define KERNEL "/vmunix" -#endif - - -#if BSD < 199103 -static struct proc *getproc __P((void)); -#else -static struct kinfo_proc *getproc __P((void)); -#endif - - -int kmemcpy(buf, pos, n) - char *buf; - void *pos; - int n; -{ - static int kfd = -1; - off_t offset = (u_long)pos; - - if (kfd == -1) - kfd = open(KMEM, O_RDONLY); - - if (lseek(kfd, offset, SEEK_SET) == -1) - { - perror("lseek"); - return -1; - } - if (read(kfd, buf, n) == -1) - { - perror("read"); - return -1; - } - return n; -} - -struct nlist names[4] = { - { "_proc" }, - { "_nproc" }, -#ifdef ultrix - { "_u" }, -#else - { NULL }, -#endif - { NULL } - }; - -#if BSD < 199103 -static struct proc *getproc() -{ - struct proc *p; - pid_t pid = getpid(); - int siz, n; - - n = nlist(KERNEL, names); - if (n != 0) - { - fprintf(stderr, "nlist(%#x) == %d\n", names, n); - return NULL; - } - if (KMCPY(&nproc, names[1].n_value, sizeof(nproc)) == -1) - { - fprintf(stderr, "read nproc (%#x)\n", names[1].n_value); - return NULL; - } - siz = nproc * sizeof(struct proc); - if (KMCPY(&p, names[0].n_value, sizeof(p)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) proc\n", - names[0].n_value, &p, sizeof(p)); - return NULL; - } - proc = (struct proc *)malloc(siz); - if (KMCPY(proc, p, siz) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) proc\n", - p, proc, siz); - return NULL; - } - - p = proc; - - for (n = nproc; n; n--, p++) - if (p->p_pid == pid) - break; - if (!n) - return NULL; - - return p; -} - - -struct tcpcb *find_tcp(fd, ti) - int fd; - struct tcpiphdr *ti; -{ - struct tcpcb *t; - struct inpcb *i; - struct socket *s; - struct user *up; - struct proc *p; - struct file *f, **o; - - if (!(p = getproc())) - return NULL; - up = (struct user *)malloc(sizeof(*up)); -#ifndef ultrix - if (KMCPY(up, p->p_uarea, sizeof(*up)) == -1) - { - fprintf(stderr, "read(%#x,%#x) failed\n", p, p->p_uarea); - return NULL; - } -#else - if (KMCPY(up, names[2].n_value, sizeof(*up)) == -1) - { - fprintf(stderr, "read(%#x,%#x) failed\n", p, names[2].n_value); - return NULL; - } -#endif - - o = (struct file **)calloc(1, sizeof(*o) * (up->u_lastfile + 1)); - if (KMCPY(o, up->u_ofile, (up->u_lastfile + 1) * sizeof(*o)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - u_ofile - failed\n", - up->u_ofile, o, sizeof(*o)); - return NULL; - } - f = (struct file *)calloc(1, sizeof(*f)); - if (KMCPY(f, o[fd], sizeof(*f)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - o[fd] - failed\n", - up->u_ofile[fd], f, sizeof(*f)); - return NULL; - } - - s = (struct socket *)calloc(1, sizeof(*s)); - if (KMCPY(s, f->f_data, sizeof(*s)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - f_data - failed\n", - o[fd], s, sizeof(*s)); - return NULL; - } - - i = (struct inpcb *)calloc(1, sizeof(*i)); - if (KMCPY(i, s->so_pcb, sizeof(*i)) == -1) - { - fprintf(stderr, "kvm_read(%#x,%#x,%d) - so_pcb - failed\n", - s->so_pcb, i, sizeof(*i)); - return NULL; - } - - t = (struct tcpcb *)calloc(1, sizeof(*t)); - if (KMCPY(t, i->inp_ppcb, sizeof(*t)) == -1) - { - fprintf(stderr, "read(%#x,%#x,%d) - inp_ppcb - failed\n", - i->inp_ppcb, t, sizeof(*t)); - return NULL; - } - return (struct tcpcb *)i->inp_ppcb; -} -#else -static struct kinfo_proc *getproc() -{ - static struct kinfo_proc kp; - pid_t pid = getpid(); - int mib[4]; - size_t n; - - mib[0] = CTL_KERN; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_PID; - mib[3] = pid; - - n = sizeof(kp); - if (sysctl(mib, 4, &kp, &n, NULL, 0) == -1) - { - perror("sysctl"); - return NULL; - } - return &kp; -} - - -struct tcpcb *find_tcp(tfd, ti) - int tfd; - struct tcpiphdr *ti; -{ - struct tcpcb *t; - struct inpcb *i; - struct socket *s; - struct filedesc *fd; - struct kinfo_proc *p; - struct file *f, **o; - - if (!(p = getproc())) - return NULL; - - fd = (struct filedesc *)malloc(sizeof(*fd)); - if (fd == NULL) - return NULL; -#if defined( __FreeBSD_version) && __FreeBSD_version >= 500013 - if (KMCPY(fd, p->ki_fd, sizeof(*fd)) == -1) - { - fprintf(stderr, "read(%#lx,%#lx) failed\n", - (u_long)p, (u_long)p->ki_fd); - free(fd); - return NULL; - } -#else - if (KMCPY(fd, p->kp_proc.p_fd, sizeof(*fd)) == -1) - { - fprintf(stderr, "read(%#lx,%#lx) failed\n", - (u_long)p, (u_long)p->kp_proc.p_fd); - free(fd); - return NULL; - } -#endif - - o = NULL; - f = NULL; - s = NULL; - i = NULL; - t = NULL; - - o = (struct file **)calloc(1, sizeof(*o) * (fd->fd_lastfile + 1)); - if (KMCPY(o, fd->fd_ofiles, (fd->fd_lastfile + 1) * sizeof(*o)) == -1) - { - fprintf(stderr, "read(%#lx,%#lx,%lu) - u_ofile - failed\n", - (u_long)fd->fd_ofiles, (u_long)o, (u_long)sizeof(*o)); - goto finderror; - } - f = (struct file *)calloc(1, sizeof(*f)); - if (KMCPY(f, o[tfd], sizeof(*f)) == -1) - { - fprintf(stderr, "read(%#lx,%#lx,%lu) - o[tfd] - failed\n", - (u_long)o[tfd], (u_long)f, (u_long)sizeof(*f)); - goto finderror; - } - - s = (struct socket *)calloc(1, sizeof(*s)); - if (KMCPY(s, f->f_data, sizeof(*s)) == -1) - { - fprintf(stderr, "read(%#lx,%#lx,%lu) - f_data - failed\n", - (u_long)f->f_data, (u_long)s, (u_long)sizeof(*s)); - goto finderror; - } - - i = (struct inpcb *)calloc(1, sizeof(*i)); - if (KMCPY(i, s->so_pcb, sizeof(*i)) == -1) - { - fprintf(stderr, "kvm_read(%#lx,%#lx,%lu) - so_pcb - failed\n", - (u_long)s->so_pcb, (u_long)i, (u_long)sizeof(*i)); - goto finderror; - } - - t = (struct tcpcb *)calloc(1, sizeof(*t)); - if (KMCPY(t, i->inp_ppcb, sizeof(*t)) == -1) - { - fprintf(stderr, "read(%#lx,%#lx,%lu) - inp_ppcb - failed\n", - (u_long)i->inp_ppcb, (u_long)t, (u_long)sizeof(*t)); - goto finderror; - } - return (struct tcpcb *)i->inp_ppcb; - -finderror: - if (o != NULL) - free(o); - if (f != NULL) - free(f); - if (s != NULL) - free(s); - if (i != NULL) - free(i); - if (t != NULL) - free(t); - return NULL; -} -#endif /* BSD < 199301 */ - -int do_socket(dev, mtu, ti, gwip) - char *dev; - int mtu; - struct tcpiphdr *ti; - struct in_addr gwip; -{ - struct sockaddr_in rsin, lsin; - struct tcpcb *t, tcb; - int fd, nfd; - socklen_t len; - - printf("Dest. Port: %d\n", ti->ti_dport); - - fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd == -1) - { - perror("socket"); - return -1; - } - - if (fcntl(fd, F_SETFL, FNDELAY) == -1) - { - perror("fcntl"); - return -1; - } - - bzero((char *)&lsin, sizeof(lsin)); - lsin.sin_family = AF_INET; - bcopy((char *)&ti->ti_src, (char *)&lsin.sin_addr, - sizeof(struct in_addr)); - if (bind(fd, (struct sockaddr *)&lsin, sizeof(lsin)) == -1) - { - perror("bind"); - return -1; - } - len = sizeof(lsin); - (void) getsockname(fd, (struct sockaddr *)&lsin, &len); - ti->ti_sport = lsin.sin_port; - printf("sport %d\n", ntohs(lsin.sin_port)); - - nfd = initdevice(dev, 1); - if (nfd == -1) - return -1; - - if (!(t = find_tcp(fd, ti))) - return -1; - - bzero((char *)&rsin, sizeof(rsin)); - rsin.sin_family = AF_INET; - bcopy((char *)&ti->ti_dst, (char *)&rsin.sin_addr, - sizeof(struct in_addr)); - rsin.sin_port = ti->ti_dport; - if (connect(fd, (struct sockaddr *)&rsin, sizeof(rsin)) == -1 && - errno != EINPROGRESS) - { - perror("connect"); - return -1; - } - KMCPY(&tcb, t, sizeof(tcb)); - ti->ti_win = tcb.rcv_adv; - ti->ti_seq = tcb.snd_nxt - 1; - ti->ti_ack = tcb.rcv_nxt; - - if (send_tcp(nfd, mtu, (ip_t *)ti, gwip) == -1) - return -1; - (void)write(fd, "Hello World\n", 12); - sleep(2); - close(fd); - return 0; -} diff --git a/contrib/ipfilter/ipsend/sockraw.c b/contrib/ipfilter/ipsend/sockraw.c deleted file mode 100644 index c923227..0000000 --- a/contrib/ipfilter/ipsend/sockraw.c +++ /dev/null @@ -1,89 +0,0 @@ -/* $FreeBSD$ */ - -/* - * (C)opyright 2000 Darren Reed. - * - * See the IPFILTER.LICENCE file for details on licencing. - * - * WARNING: Attempting to use this .c file on HP-UX 11.00 will cause the - * system to crash. - */ -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> - -#include <net/if.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> -#include <netinet/if_ether.h> -#include <netinet/ip_var.h> -#include <netinet/udp.h> -#include <netinet/udp_var.h> -#include <netinet/tcp.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <stdlib.h> -#include <errno.h> -#include "ipsend.h" - -#if !defined(lint) && defined(LIBC_SCCS) -static char sirix[] = "@(#)sirix.c 1.0 10/9/97 (C)1997 Marc Boucher"; -#endif - - -int initdevice(char *device, int tout) -{ - struct sockaddr s; - struct ifreq ifr; - int fd; - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, device, sizeof ifr.ifr_name); - - if ((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) - { - perror("socket(AF_INET, SOCK_RAW, IPPROTO_RAW)"); - return -1; - } - - if (ioctl(fd, SIOCGIFADDR, &ifr) == -1) - { - perror("ioctl SIOCGIFADDR"); - return -1; - } - - bzero((char *)&s, sizeof(s)); - s.sa_family = AF_INET; - bcopy(&ifr.ifr_addr, s.sa_data, 4); - if (bind(fd, &s, sizeof(s)) == -1) - perror("bind"); - return fd; -} - - -/* - * output an IP packet - */ -int sendip(int fd, char *pkt, int len) -{ - struct ether_header *eh; - struct sockaddr_in sin; - - eh = (struct ether_header *)pkt; - bzero((char *)&sin, sizeof(sin)); - sin.sin_family = AF_INET; - pkt += 14; - len -= 14; - bcopy(pkt + 12, (char *)&sin.sin_addr, 4); - - if (sendto(fd, pkt, len, 0, &sin, sizeof(sin)) == -1) - { - perror("send"); - return -1; - } - - return len; -} |