]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/ipsend/ipresend.c
Fix a typo.
[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 #   ifdef       ultrix
42 char    default_device[] = "ln0";
43 #   else
44 #    ifdef      __bsdi__
45 char    default_device[] = "ef0";
46 #    else
47 char    default_device[] = "lan0";
48 #    endif
49 #   endif
50 #  endif
51 #else
52 char    default_device[] = DEFAULT_DEVICE;
53 #endif
54
55
56 static  void    usage __P((char *));
57 int     main __P((int, char **));
58
59
60 static void usage(prog)
61         char    *prog;
62 {
63         fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\
64 \t\t-r filename\tsnoop data file to resend\n\
65 \t\t-R filename\tlibpcap data file to resend\n\
66 \toptions:\n\
67 \t\t-d device\tSend out on this device\n\
68 \t\t-g gateway\tIP gateway to use if non-local dest.\n\
69 \t\t-m mtu\t\tfake MTU to use when sending out\n\
70 ", prog);
71         exit(1);
72 }
73
74
75 int main(argc, argv)
76         int     argc;
77         char    **argv;
78 {
79         struct  in_addr gwip;
80         struct  ipread  *ipr = NULL;
81         char    *name =  argv[0], *gateway = NULL, *dev = NULL;
82         char    *resend = NULL;
83         int     mtu = 1500, c;
84
85         while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1)
86                 switch (c)
87                 {
88                 case 'd' :
89                         dev = optarg;
90                         break;
91                 case 'g' :
92                         gateway = optarg;
93                         break;
94                 case 'm' :
95                         mtu = atoi(optarg);
96                         if (mtu < 28)
97                             {
98                                 fprintf(stderr, "mtu must be > 28\n");
99                                 exit(1);
100                             }
101                 case 'r' :
102                         resend = optarg;
103                         break;
104                 case 'R' :
105                         opts |= OPT_RAW;
106                         break;
107 #ifndef NO_IPF
108                 case 'H' :
109                         ipr = &iphex;
110                         break;
111                 case 'P' :
112                         ipr = &pcap;
113                         break;
114                 case 'X' :
115                         ipr = &iptext;
116                         break;
117 #endif
118                 default :
119                         fprintf(stderr, "Unknown option \"%c\"\n", c);
120                         usage(name);
121                 }
122
123         if (!ipr || !resend)
124                 usage(name);
125
126         gwip.s_addr = 0;
127         if (gateway && resolve(gateway, (char *)&gwip) == -1)
128             {
129                 fprintf(stderr,"Cant resolve %s\n", gateway);
130                 exit(2);
131             }
132
133         if (!dev)
134                 dev = default_device;
135
136         printf("Device:  %s\n", dev);
137         printf("Gateway: %s\n", inet_ntoa(gwip));
138         printf("mtu:     %d\n", mtu);
139
140         return ip_resend(dev, mtu, ipr, gwip, resend);
141 }