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