1
2 /*
3 * ipresend.c (C) 1995-1998 Darren Reed
4 *
5 * See the IPFILTER.LICENCE file for details on licencing.
6 *
7 */
8 #if !defined(lint)
9 static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
10 static const char rcsid[] = "@(#)$Id$";
11 #endif
12 #include <sys/param.h>
13 #include <sys/types.h>
14 #include <sys/time.h>
15 #include <sys/socket.h>
16 #include <netinet/in.h>
17 #include <arpa/inet.h>
18 #include <netinet/in_systm.h>
19 #include <netinet/ip.h>
20 #include <netinet/ip_var.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <netdb.h>
25 #include <string.h>
26 #include "ipsend.h"
27
28
29 extern char *optarg;
30 extern int optind;
31 #ifndef NO_IPF
32 extern struct ipread pcap, iphex, iptext;
33 #endif
34
35 int opts = 0;
36 #ifndef DEFAULT_DEVICE
37 # ifdef sun
38 char default_device[] = "le0";
39 # else
40 char default_device[] = "lan0";
41 # endif
42 #else
43 char default_device[] = DEFAULT_DEVICE;
44 #endif
45
46
47 static void usage(char *);
48 int main(int, char **);
49
50
usage(prog)51 static void usage(prog)
52 char *prog;
53 {
54 fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\
55 \t\t-r filename\tsnoop data file to resend\n\
56 \t\t-R filename\tlibpcap data file to resend\n\
57 \toptions:\n\
58 \t\t-d device\tSend out on this device\n\
59 \t\t-g gateway\tIP gateway to use if non-local dest.\n\
60 \t\t-m mtu\t\tfake MTU to use when sending out\n\
61 ", prog);
62 exit(1);
63 }
64
65
66 int
main(int argc,char ** argv)67 main(int argc, char **argv)
68 {
69 struct in_addr gwip;
70 struct ipread *ipr = NULL;
71 char *name = argv[0], *gateway = NULL, *dev = NULL;
72 char *resend = NULL;
73 int mtu = 1500, c;
74
75 while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1)
76 switch (c)
77 {
78 case 'd' :
79 dev = optarg;
80 break;
81 case 'g' :
82 gateway = optarg;
83 break;
84 case 'm' :
85 mtu = atoi(optarg);
86 if (mtu < 28)
87 {
88 fprintf(stderr, "mtu must be > 28\n");
89 exit(1);
90 }
91 case 'r' :
92 resend = optarg;
93 break;
94 case 'R' :
95 opts |= OPT_RAW;
96 break;
97 #ifndef NO_IPF
98 case 'H' :
99 ipr = &iphex;
100 break;
101 case 'P' :
102 ipr = &pcap;
103 break;
104 case 'X' :
105 ipr = &iptext;
106 break;
107 #endif
108 default :
109 fprintf(stderr, "Unknown option \"%c\"\n", c);
110 usage(name);
111 }
112
113 if (!ipr || !resend)
114 usage(name);
115
116 gwip.s_addr = 0;
117 if (gateway && resolve(gateway, (char *)&gwip) == -1)
118 {
119 fprintf(stderr,"Cant resolve %s\n", gateway);
120 exit(2);
121 }
122
123 if (!dev)
124 dev = default_device;
125
126 printf("Device: %s\n", dev);
127 printf("Gateway: %s\n", inet_ntoa(gwip));
128 printf("mtu: %d\n", mtu);
129
130 return (ip_resend(dev, mtu, ipr, gwip, resend));
131 }
132