Deleted Added
full compact
ipresend.c (145519) ipresend.c (153881)
1/* $FreeBSD: head/contrib/ipfilter/ipsend/ipresend.c 145519 2005-04-25 18:20:15Z darrenr $ */
1/* $FreeBSD: head/contrib/ipfilter/ipsend/ipresend.c 153881 2005-12-30 11:52:26Z guido $ */
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)
10static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
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)
10static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
11static const char rcsid[] = "@(#)Id: ipresend.c,v 2.4 2004/01/08 13:34:31 darrenr Exp";
11static const char rcsid[] = "@(#)$Id: ipresend.c,v 2.4 2004/01/08 13:34:31 darrenr Exp $";
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#ifndef linux
22#include <netinet/ip_var.h>
23#endif
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include <netdb.h>
28#include <string.h>
29#include "ipsend.h"
30
31
32extern char *optarg;
33extern int optind;
34#ifndef NO_IPF
35extern struct ipread snoop, pcap, etherf, iphex, tcpd, iptext;
36#endif
37
38int opts = 0;
39#ifndef DEFAULT_DEVICE
40# ifdef linux
41char default_device[] = "eth0";
42# else
43# ifdef sun
44char default_device[] = "le0";
45# else
46# ifdef ultrix
47char default_device[] = "ln0";
48# else
49# ifdef __bsdi__
50char default_device[] = "ef0";
51# else
52# ifdef __sgi
53char default_device[] = "ec0";
54# else
55char default_device[] = "lan0";
56# endif
57# endif
58# endif
59# endif
60# endif
61#else
62char default_device[] = DEFAULT_DEVICE;
63#endif
64
65
66static void usage __P((char *));
67int main __P((int, char **));
68
69
70static void usage(prog)
71char *prog;
72{
73 fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\
74\t\t-r filename\tsnoop data file to resend\n\
75\t\t-R filename\tlibpcap data file to resend\n\
76\toptions:\n\
77\t\t-d device\tSend out on this device\n\
78\t\t-g gateway\tIP gateway to use if non-local dest.\n\
79\t\t-m mtu\t\tfake MTU to use when sending out\n\
80", prog);
81 exit(1);
82}
83
84
85int main(argc, argv)
86int argc;
87char **argv;
88{
89 struct in_addr gwip;
90 struct ipread *ipr = NULL;
91 char *name = argv[0], *gateway = NULL, *dev = NULL;
92 char *resend = NULL;
93 int mtu = 1500, c;
94
95 while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1)
96 switch (c)
97 {
98 case 'd' :
99 dev = optarg;
100 break;
101 case 'g' :
102 gateway = optarg;
103 break;
104 case 'm' :
105 mtu = atoi(optarg);
106 if (mtu < 28)
107 {
108 fprintf(stderr, "mtu must be > 28\n");
109 exit(1);
110 }
111 case 'r' :
112 resend = optarg;
113 break;
114 case 'R' :
115 opts |= OPT_RAW;
116 break;
117#ifndef NO_IPF
118 case 'E' :
119 ipr = &etherf;
120 break;
121 case 'H' :
122 ipr = &iphex;
123 break;
124 case 'P' :
125 ipr = &pcap;
126 break;
127 case 'S' :
128 ipr = &snoop;
129 break;
130 case 'T' :
131 ipr = &tcpd;
132 break;
133 case 'X' :
134 ipr = &iptext;
135 break;
136#endif
137 default :
138 fprintf(stderr, "Unknown option \"%c\"\n", c);
139 usage(name);
140 }
141
142 if (!ipr || !resend)
143 usage(name);
144
145 gwip.s_addr = 0;
146 if (gateway && resolve(gateway, (char *)&gwip) == -1)
147 {
148 fprintf(stderr,"Cant resolve %s\n", gateway);
149 exit(2);
150 }
151
152 if (!dev)
153 dev = default_device;
154
155 printf("Device: %s\n", dev);
156 printf("Gateway: %s\n", inet_ntoa(gwip));
157 printf("mtu: %d\n", mtu);
158
159 return ip_resend(dev, mtu, ipr, gwip, resend);
160}
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#ifndef linux
22#include <netinet/ip_var.h>
23#endif
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include <netdb.h>
28#include <string.h>
29#include "ipsend.h"
30
31
32extern char *optarg;
33extern int optind;
34#ifndef NO_IPF
35extern struct ipread snoop, pcap, etherf, iphex, tcpd, iptext;
36#endif
37
38int opts = 0;
39#ifndef DEFAULT_DEVICE
40# ifdef linux
41char default_device[] = "eth0";
42# else
43# ifdef sun
44char default_device[] = "le0";
45# else
46# ifdef ultrix
47char default_device[] = "ln0";
48# else
49# ifdef __bsdi__
50char default_device[] = "ef0";
51# else
52# ifdef __sgi
53char default_device[] = "ec0";
54# else
55char default_device[] = "lan0";
56# endif
57# endif
58# endif
59# endif
60# endif
61#else
62char default_device[] = DEFAULT_DEVICE;
63#endif
64
65
66static void usage __P((char *));
67int main __P((int, char **));
68
69
70static void usage(prog)
71char *prog;
72{
73 fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\
74\t\t-r filename\tsnoop data file to resend\n\
75\t\t-R filename\tlibpcap data file to resend\n\
76\toptions:\n\
77\t\t-d device\tSend out on this device\n\
78\t\t-g gateway\tIP gateway to use if non-local dest.\n\
79\t\t-m mtu\t\tfake MTU to use when sending out\n\
80", prog);
81 exit(1);
82}
83
84
85int main(argc, argv)
86int argc;
87char **argv;
88{
89 struct in_addr gwip;
90 struct ipread *ipr = NULL;
91 char *name = argv[0], *gateway = NULL, *dev = NULL;
92 char *resend = NULL;
93 int mtu = 1500, c;
94
95 while ((c = getopt(argc, argv, "EHPRSTXd:g:m:r:")) != -1)
96 switch (c)
97 {
98 case 'd' :
99 dev = optarg;
100 break;
101 case 'g' :
102 gateway = optarg;
103 break;
104 case 'm' :
105 mtu = atoi(optarg);
106 if (mtu < 28)
107 {
108 fprintf(stderr, "mtu must be > 28\n");
109 exit(1);
110 }
111 case 'r' :
112 resend = optarg;
113 break;
114 case 'R' :
115 opts |= OPT_RAW;
116 break;
117#ifndef NO_IPF
118 case 'E' :
119 ipr = &etherf;
120 break;
121 case 'H' :
122 ipr = &iphex;
123 break;
124 case 'P' :
125 ipr = &pcap;
126 break;
127 case 'S' :
128 ipr = &snoop;
129 break;
130 case 'T' :
131 ipr = &tcpd;
132 break;
133 case 'X' :
134 ipr = &iptext;
135 break;
136#endif
137 default :
138 fprintf(stderr, "Unknown option \"%c\"\n", c);
139 usage(name);
140 }
141
142 if (!ipr || !resend)
143 usage(name);
144
145 gwip.s_addr = 0;
146 if (gateway && resolve(gateway, (char *)&gwip) == -1)
147 {
148 fprintf(stderr,"Cant resolve %s\n", gateway);
149 exit(2);
150 }
151
152 if (!dev)
153 dev = default_device;
154
155 printf("Device: %s\n", dev);
156 printf("Gateway: %s\n", inet_ntoa(gwip));
157 printf("mtu: %d\n", mtu);
158
159 return ip_resend(dev, mtu, ipr, gwip, resend);
160}