4 * ipsend.c (C) 1995-1998 Darren Reed
6 * See the IPFILTER.LICENCE file for details on licencing.
10 static const char sccsid
[] = "%W% %G% (C)1995 Darren Reed";
11 static const char rcsid
[] = "@(#)Id: iptest.c,v 2.6 2004/01/08 13:34:31 darrenr Exp";
13 #include <sys/param.h>
14 #include <sys/types.h>
16 #include <sys/socket.h>
17 #include <netinet/in.h>
18 #include <arpa/inet.h>
19 #include <netinet/in_systm.h>
20 #include <netinet/ip.h>
22 #include <netinet/ip_var.h>
25 #include <linux/sockios.h>
40 char default_device
[] = "eth0";
43 char default_device
[] = "le0";
46 char default_device
[] = "ln0";
49 char default_device
[] = "ef0";
52 char default_device
[] = "ec0";
54 char default_device
[] = "lan0";
61 static void usage
__P((char *));
62 int main
__P((int, char **));
65 static void usage(prog
)
68 fprintf(stderr
, "Usage: %s [options] dest\n\
70 \t\t-d device\tSend out on this device\n\
71 \t\t-g gateway\tIP gateway to use if non-local dest.\n\
72 \t\t-m mtu\t\tfake MTU to use when sending out\n\
74 \t\t-s src\t\tsource address for IP packet\n\
75 \t\t-1 \t\tPerform test 1 (IP header)\n\
76 \t\t-2 \t\tPerform test 2 (IP options)\n\
77 \t\t-3 \t\tPerform test 3 (ICMP)\n\
78 \t\t-4 \t\tPerform test 4 (UDP)\n\
79 \t\t-5 \t\tPerform test 5 (TCP)\n\
80 \t\t-6 \t\tPerform test 6 (overlapping fragments)\n\
81 \t\t-7 \t\tPerform test 7 (random packets)\n\
94 char *name
= argv
[0], host
[MAXHOSTNAMELEN
+ 1];
95 char *gateway
= NULL
, *dev
= NULL
;
96 char *src
= NULL
, *dst
;
97 int mtu
= 1500, tests
= 0, pointtest
= 0, c
;
100 * 65535 is maximum packet size...you never know...
102 ip
= (ip_t
*)calloc(1, 65536);
103 ti
= (struct tcpiphdr
*)ip
;
104 ip
->ip_len
= sizeof(*ip
);
105 IP_HL_A(ip
, sizeof(*ip
) >> 2);
107 while ((c
= getopt(argc
, argv
, "1234567d:g:m:p:s:")) != -1)
129 fprintf(stderr
, "mtu must be > 28\n");
134 pointtest
= atoi(optarg
);
140 fprintf(stderr
, "Unknown option \"%c\"\n", c
);
144 if ((argc
<= optind
) || !argv
[optind
])
146 dst
= argv
[optind
++];
150 gethostname(host
, sizeof(host
));
151 host
[sizeof(host
) - 1] = '\0';
155 if (resolve(dst
, (char *)&ip
->ip_dst
) == -1)
157 fprintf(stderr
,"Cant resolve %s\n", dst
);
161 if (resolve(src
, (char *)&ip
->ip_src
) == -1)
163 fprintf(stderr
,"Cant resolve %s\n", src
);
169 else if (resolve(gateway
, (char *)&gwip
) == -1)
171 fprintf(stderr
,"Cant resolve %s\n", gateway
);
177 dev
= default_device
;
178 printf("Device: %s\n", dev
);
179 printf("Source: %s\n", inet_ntoa(ip
->ip_src
));
180 printf("Dest: %s\n", inet_ntoa(ip
->ip_dst
));
181 printf("Gateway: %s\n", inet_ntoa(gwip
));
182 printf("mtu: %d\n", mtu
);
187 ip_test1(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
190 ip_test2(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
193 ip_test3(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
196 ip_test4(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
199 ip_test5(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
202 ip_test6(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
205 ip_test7(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
208 ip_test1(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
209 ip_test2(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
210 ip_test3(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
211 ip_test4(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
212 ip_test5(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
213 ip_test6(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);
214 ip_test7(dev
, mtu
, (ip_t
*)ti
, gwip
, pointtest
);