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)
10static const char sccsid[] = "%W% %G% (C)1995 Darren Reed";
11static 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#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	pcap, iphex, 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)
71	char	*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)
86	int	argc;
87	char	**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 'H' :
119			ipr = &iphex;
120			break;
121		case 'P' :
122			ipr = &pcap;
123			break;
124		case 'X' :
125			ipr = &iptext;
126			break;
127#endif
128		default :
129			fprintf(stderr, "Unknown option \"%c\"\n", c);
130			usage(name);
131		}
132
133	if (!ipr || !resend)
134		usage(name);
135
136	gwip.s_addr = 0;
137	if (gateway && resolve(gateway, (char *)&gwip) == -1)
138	    {
139		fprintf(stderr,"Cant resolve %s\n", gateway);
140		exit(2);
141	    }
142
143	if (!dev)
144		dev = default_device;
145
146	printf("Device:  %s\n", dev);
147	printf("Gateway: %s\n", inet_ntoa(gwip));
148	printf("mtu:     %d\n", mtu);
149
150	return ip_resend(dev, mtu, ipr, gwip, resend);
151}
152