Deleted Added
full compact
ipresend.c (80486) ipresend.c (92686)
1/*
2 * ipresend.c (C) 1995-1998 Darren Reed
3 *
4 * This was written to test what size TCP fragments would get through
5 * various TCP/IP packet filters, as used in IP firewalls. In certain
6 * conditions, enough of the TCP header is missing for unpredictable
7 * results unless the filter is aware that this can happen.
8 *
9 * See the IPFILTER.LICENCE file for details on licencing.
10 */
1/*
2 * ipresend.c (C) 1995-1998 Darren Reed
3 *
4 * This was written to test what size TCP fragments would get through
5 * various TCP/IP packet filters, as used in IP firewalls. In certain
6 * conditions, enough of the TCP header is missing for unpredictable
7 * results unless the filter is aware that this can happen.
8 *
9 * See the IPFILTER.LICENCE file for details on licencing.
10 */
11#ifdef __sgi
12# include <sys/ptimers.h>
13#endif
11#include <stdio.h>
12#include <stdlib.h>
13#include <unistd.h>
14#include <netdb.h>
15#include <string.h>
16#include <sys/types.h>
14#include <stdio.h>
15#include <stdlib.h>
16#include <unistd.h>
17#include <netdb.h>
18#include <string.h>
19#include <sys/types.h>
20#include <sys/param.h>
17#include <sys/time.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <netinet/in_systm.h>
22#include <netinet/ip.h>
23#include <netinet/tcp.h>
24#include <netinet/udp.h>
25#include <netinet/ip_icmp.h>
26#ifndef linux
27#include <netinet/ip_var.h>
28#endif
29#include "ipsend.h"
30
31#if !defined(lint)
32static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
21#include <sys/time.h>
22#include <sys/socket.h>
23#include <netinet/in.h>
24#include <arpa/inet.h>
25#include <netinet/in_systm.h>
26#include <netinet/ip.h>
27#include <netinet/tcp.h>
28#include <netinet/udp.h>
29#include <netinet/ip_icmp.h>
30#ifndef linux
31#include <netinet/ip_var.h>
32#endif
33#include "ipsend.h"
34
35#if !defined(lint)
36static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
33static const char rcsid[] = "@(#)$Id: ipresend.c,v 2.1.4.2 2001/07/15 22:00:13 darrenr Exp $";
37static const char rcsid[] = "@(#)$Id: ipresend.c,v 2.1.4.3 2002/02/22 15:32:57 darrenr Exp $";
34#endif
35
36
37extern char *optarg;
38extern int optind;
39#ifndef NO_IPF
40extern struct ipread snoop, pcap, etherf, iphex, tcpd, iptext;
41#endif
42
43int opts = 0;
44#ifndef DEFAULT_DEVICE
45# ifdef linux
46char default_device[] = "eth0";
47# else
48# ifdef sun
49char default_device[] = "le0";
50# else
51# ifdef ultrix
52char default_device[] = "ln0";
53# else
54# ifdef __bsdi__
55char default_device[] = "ef0";
56# else
57# ifdef __sgi
58char default_device[] = "ec0";
59# else
60char default_device[] = "lan0";
61# endif
62# endif
63# endif
64# endif
65# endif
66#else
67char default_device[] = DEFAULT_DEVICE;
68#endif
69
70
71static void usage __P((char *));
72int main __P((int, char **));
73
74
75static void usage(prog)
76char *prog;
77{
78 fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\
79\t\t-r filename\tsnoop data file to resend\n\
80\t\t-R filename\tlibpcap data file to resend\n\
81\toptions:\n\
82\t\t-d device\tSend out on this device\n\
83\t\t-g gateway\tIP gateway to use if non-local dest.\n\
84\t\t-m mtu\t\tfake MTU to use when sending out\n\
85", prog);
86 exit(1);
87}
88
89
90int main(argc, argv)
91int argc;
92char **argv;
93{
94 struct in_addr gwip;
95 struct ipread *ipr = NULL;
96 char *name = argv[0], *gateway = NULL, *dev = NULL;
97 char *resend = NULL;
98 int mtu = 1500, c;
99
100 while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1)
101 switch (c)
102 {
103 case 'd' :
104 dev = optarg;
105 break;
106 case 'g' :
107 gateway = optarg;
108 break;
109 case 'm' :
110 mtu = atoi(optarg);
111 if (mtu < 28)
112 {
113 fprintf(stderr, "mtu must be > 28\n");
114 exit(1);
115 }
116 case 'r' :
117 resend = optarg;
118 break;
119 case 'R' :
120 opts |= OPT_RAW;
121 break;
122#ifndef NO_IPF
123 case 'E' :
124 ipr = &etherf;
125 break;
126 case 'H' :
127 ipr = &iphex;
128 break;
129 case 'P' :
130 ipr = &pcap;
131 break;
132 case 'S' :
133 ipr = &snoop;
134 break;
135 case 'T' :
136 ipr = &tcpd;
137 break;
138 case 'X' :
139 ipr = &iptext;
140 break;
141#endif
142 default :
143 fprintf(stderr, "Unknown option \"%c\"\n", c);
144 usage(name);
145 }
146
147 if (!ipr || !resend)
148 usage(name);
149
150 gwip.s_addr = 0;
151 if (gateway && resolve(gateway, (char *)&gwip) == -1)
152 {
153 fprintf(stderr,"Cant resolve %s\n", gateway);
154 exit(2);
155 }
156
157 if (!dev)
158 dev = default_device;
159
160 printf("Device: %s\n", dev);
161 printf("Gateway: %s\n", inet_ntoa(gwip));
162 printf("mtu: %d\n", mtu);
163
164 return ip_resend(dev, mtu, ipr, gwip, resend);
165}
38#endif
39
40
41extern char *optarg;
42extern int optind;
43#ifndef NO_IPF
44extern struct ipread snoop, pcap, etherf, iphex, tcpd, iptext;
45#endif
46
47int opts = 0;
48#ifndef DEFAULT_DEVICE
49# ifdef linux
50char default_device[] = "eth0";
51# else
52# ifdef sun
53char default_device[] = "le0";
54# else
55# ifdef ultrix
56char default_device[] = "ln0";
57# else
58# ifdef __bsdi__
59char default_device[] = "ef0";
60# else
61# ifdef __sgi
62char default_device[] = "ec0";
63# else
64char default_device[] = "lan0";
65# endif
66# endif
67# endif
68# endif
69# endif
70#else
71char default_device[] = DEFAULT_DEVICE;
72#endif
73
74
75static void usage __P((char *));
76int main __P((int, char **));
77
78
79static void usage(prog)
80char *prog;
81{
82 fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\
83\t\t-r filename\tsnoop data file to resend\n\
84\t\t-R filename\tlibpcap data file to resend\n\
85\toptions:\n\
86\t\t-d device\tSend out on this device\n\
87\t\t-g gateway\tIP gateway to use if non-local dest.\n\
88\t\t-m mtu\t\tfake MTU to use when sending out\n\
89", prog);
90 exit(1);
91}
92
93
94int main(argc, argv)
95int argc;
96char **argv;
97{
98 struct in_addr gwip;
99 struct ipread *ipr = NULL;
100 char *name = argv[0], *gateway = NULL, *dev = NULL;
101 char *resend = NULL;
102 int mtu = 1500, c;
103
104 while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1)
105 switch (c)
106 {
107 case 'd' :
108 dev = optarg;
109 break;
110 case 'g' :
111 gateway = optarg;
112 break;
113 case 'm' :
114 mtu = atoi(optarg);
115 if (mtu < 28)
116 {
117 fprintf(stderr, "mtu must be > 28\n");
118 exit(1);
119 }
120 case 'r' :
121 resend = optarg;
122 break;
123 case 'R' :
124 opts |= OPT_RAW;
125 break;
126#ifndef NO_IPF
127 case 'E' :
128 ipr = &etherf;
129 break;
130 case 'H' :
131 ipr = &iphex;
132 break;
133 case 'P' :
134 ipr = &pcap;
135 break;
136 case 'S' :
137 ipr = &snoop;
138 break;
139 case 'T' :
140 ipr = &tcpd;
141 break;
142 case 'X' :
143 ipr = &iptext;
144 break;
145#endif
146 default :
147 fprintf(stderr, "Unknown option \"%c\"\n", c);
148 usage(name);
149 }
150
151 if (!ipr || !resend)
152 usage(name);
153
154 gwip.s_addr = 0;
155 if (gateway && resolve(gateway, (char *)&gwip) == -1)
156 {
157 fprintf(stderr,"Cant resolve %s\n", gateway);
158 exit(2);
159 }
160
161 if (!dev)
162 dev = default_device;
163
164 printf("Device: %s\n", dev);
165 printf("Gateway: %s\n", inet_ntoa(gwip));
166 printf("mtu: %d\n", mtu);
167
168 return ip_resend(dev, mtu, ipr, gwip, resend);
169}