127837Sdavidn/* $FreeBSD: stable/11/contrib/ipfilter/ipsend/ipresend.c 369245 2021-02-09 13:47:46Z git2svn $ */ 250472Speter 327837Sdavidn/* 451231Ssheldonh * ipresend.c (C) 1995-1998 Darren Reed 527837Sdavidn * 627837Sdavidn * See the IPFILTER.LICENCE file for details on licencing. 727837Sdavidn * 827837Sdavidn */ 927837Sdavidn#if !defined(lint) 1027837Sdavidnstatic const char sccsid[] = "%W% %G% (C)1995 Darren Reed"; 1127837Sdavidnstatic const char rcsid[] = "@(#)$Id$"; 1227837Sdavidn#endif 1327837Sdavidn#include <sys/param.h> 1427837Sdavidn#include <sys/types.h> 1527837Sdavidn#include <sys/time.h> 1651231Ssheldonh#include <sys/socket.h> 1727837Sdavidn#include <netinet/in.h> 1851231Ssheldonh#include <arpa/inet.h> 1927837Sdavidn#include <netinet/in_systm.h> 2062640Stg#include <netinet/ip.h> 2162640Stg#include <netinet/ip_var.h> 2262640Stg#include <stdio.h> 2362640Stg#include <stdlib.h> 2462640Stg#include <unistd.h> 2562640Stg#include <netdb.h> 2662640Stg#include <string.h> 2762640Stg#include "ipsend.h" 2862640Stg 2963307Smarkm 3063307Smarkmextern char *optarg; 3163307Smarkmextern int optind; 3263307Smarkm#ifndef NO_IPF 3363307Smarkmextern struct ipread pcap, iphex, iptext; 3463307Smarkm#endif 3563311Ssheldonh 3663311Ssheldonhint opts = 0; 3763311Ssheldonh#ifndef DEFAULT_DEVICE 3863311Ssheldonh# ifdef sun 3963311Ssheldonhchar default_device[] = "le0"; 4063307Smarkm# else 4163307Smarkmchar default_device[] = "lan0"; 4263307Smarkm# endif 4353550Sdillon#else 4453550Sdillonchar default_device[] = DEFAULT_DEVICE; 4553550Sdillon#endif 4653550Sdillon 4753550Sdillon 4853550Sdillonstatic void usage(char *); 4953550Sdillonint main(int, char **); 5053550Sdillon 5153550Sdillon 5251231Ssheldonhstatic void usage(prog) 5327837Sdavidn char *prog; 5462640Stg{ 5562640Stg fprintf(stderr, "Usage: %s [options] <-r filename|-R filename>\n\ 5662640Stg\t\t-r filename\tsnoop data file to resend\n\ 5762640Stg\t\t-R filename\tlibpcap data file to resend\n\ 5862640Stg\toptions:\n\ 5962640Stg\t\t-d device\tSend out on this device\n\ 6062640Stg\t\t-g gateway\tIP gateway to use if non-local dest.\n\ 6162640Stg\t\t-m mtu\t\tfake MTU to use when sending out\n\ 6262640Stg", prog); 6362640Stg exit(1); 6462640Stg} 6562640Stg 6662640Stg 6762640Stgint main(argc, argv) 6862640Stg int argc; 6962640Stg char **argv; 7062640Stg{ 7162640Stg struct in_addr gwip; 7262640Stg struct ipread *ipr = NULL; 7327837Sdavidn char *name = argv[0], *gateway = NULL, *dev = NULL; 7462640Stg char *resend = NULL; 7527837Sdavidn int mtu = 1500, c; 7627837Sdavidn 7727837Sdavidn 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} 134