2 * ipsend.c (C) 1995-1998 Darren Reed
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.
9 * See the IPFILTER.LICENCE file for details on licencing.
11 #if defined(__sgi) && (IRIX > 602)
12 # include <sys/ptimers.h>
19 #include <sys/param.h>
20 #include <sys/types.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>
31 #include <netinet/ip_var.h>
34 #include <linux/sockios.h>
39 static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
40 static const char rcsid[] = "@(#)$Id: iptest.c,v 2.2.2.4 2002/12/06 11:40:35 darrenr Exp $";
49 char default_device[] = "eth0";
52 char default_device[] = "le0";
55 char default_device[] = "ln0";
58 char default_device[] = "ef0";
61 char default_device[] = "ec0";
63 char default_device[] = "lan0";
70 static void usage __P((char *));
71 int main __P((int, char **));
74 static void usage(prog)
77 fprintf(stderr, "Usage: %s [options] dest\n\
79 \t\t-d device\tSend out on this device\n\
80 \t\t-g gateway\tIP gateway to use if non-local dest.\n\
81 \t\t-m mtu\t\tfake MTU to use when sending out\n\
83 \t\t-s src\t\tsource address for IP packet\n\
84 \t\t-1 \t\tPerform test 1 (IP header)\n\
85 \t\t-2 \t\tPerform test 2 (IP options)\n\
86 \t\t-3 \t\tPerform test 3 (ICMP)\n\
87 \t\t-4 \t\tPerform test 4 (UDP)\n\
88 \t\t-5 \t\tPerform test 5 (TCP)\n\
89 \t\t-6 \t\tPerform test 6 (overlapping fragments)\n\
90 \t\t-7 \t\tPerform test 7 (random packets)\n\
103 char *name = argv[0], host[MAXHOSTNAMELEN + 1];
104 char *gateway = NULL, *dev = NULL;
105 char *src = NULL, *dst;
106 int mtu = 1500, tests = 0, pointtest = 0, c;
109 * 65535 is maximum packet size...you never know...
111 ip = (ip_t *)calloc(1, 65536);
112 ti = (struct tcpiphdr *)ip;
113 ip->ip_len = sizeof(*ip);
114 ip->ip_hl = sizeof(*ip) >> 2;
116 while ((c = getopt(argc, argv, "1234567d:g:m:p:s:")) != -1)
138 fprintf(stderr, "mtu must be > 28\n");
143 pointtest = atoi(optarg);
149 fprintf(stderr, "Unknown option \"%c\"\n", c);
153 if ((argc <= optind) || !argv[optind])
155 dst = argv[optind++];
159 gethostname(host, sizeof(host));
160 host[sizeof(host) - 1] = '\0';
164 if (resolve(dst, (char *)&ip->ip_dst) == -1)
166 fprintf(stderr,"Cant resolve %s\n", dst);
170 if (resolve(src, (char *)&ip->ip_src) == -1)
172 fprintf(stderr,"Cant resolve %s\n", src);
178 else if (resolve(gateway, (char *)&gwip) == -1)
180 fprintf(stderr,"Cant resolve %s\n", gateway);
186 dev = default_device;
187 printf("Device: %s\n", dev);
188 printf("Source: %s\n", inet_ntoa(ip->ip_src));
189 printf("Dest: %s\n", inet_ntoa(ip->ip_dst));
190 printf("Gateway: %s\n", inet_ntoa(gwip));
191 printf("mtu: %d\n", mtu);
196 ip_test1(dev, mtu, (ip_t *)ti, gwip, pointtest);
199 ip_test2(dev, mtu, (ip_t *)ti, gwip, pointtest);
202 ip_test3(dev, mtu, (ip_t *)ti, gwip, pointtest);
205 ip_test4(dev, mtu, (ip_t *)ti, gwip, pointtest);
208 ip_test5(dev, mtu, (ip_t *)ti, gwip, pointtest);
211 ip_test6(dev, mtu, (ip_t *)ti, gwip, pointtest);
214 ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest);
217 ip_test1(dev, mtu, (ip_t *)ti, gwip, pointtest);
218 ip_test2(dev, mtu, (ip_t *)ti, gwip, pointtest);
219 ip_test3(dev, mtu, (ip_t *)ti, gwip, pointtest);
220 ip_test4(dev, mtu, (ip_t *)ti, gwip, pointtest);
221 ip_test5(dev, mtu, (ip_t *)ti, gwip, pointtest);
222 ip_test6(dev, mtu, (ip_t *)ti, gwip, pointtest);
223 ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest);