4 * resend.c (C) 1995-1998 Darren Reed
6 * See the IPFILTER.LICENCE file for details on licencing.
10 static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
11 static const char rcsid[] = "@(#)$Id: resend.c,v 2.8.2.3 2007/02/17 12:41:51 darrenr Exp $";
13 #include <sys/param.h>
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 # include "radix_ipf_local.h"
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23 #include <netinet/in_systm.h>
24 #include <netinet/ip.h>
26 # include <netinet/ip_var.h>
27 # include <netinet/if_ether.h>
28 # if __FreeBSD_version >= 300000
29 # include <net/if_var.h>
41 static u_char pbuf[65536]; /* 1 big packet */
42 void printpacket __P((ip_t *));
51 t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2));
53 printf("tos %#x ", ip->ip_tos);
54 if (ip->ip_off & 0x3fff)
55 printf("frag @%#x ", (ip->ip_off & 0x1fff) << 3);
56 printf("len %d id %d ", ip->ip_len, ip->ip_id);
57 printf("ttl %d p %d src %s", ip->ip_ttl, ip->ip_p,
58 inet_ntoa(ip->ip_src));
59 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
60 printf(",%d", t->th_sport);
61 printf(" dst %s", inet_ntoa(ip->ip_dst));
62 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
63 printf(",%d", t->th_dport);
64 if (ip->ip_p == IPPROTO_TCP) {
65 printf(" seq %lu:%lu flags ",
66 (u_long)t->th_seq, (u_long)t->th_ack);
67 for (j = 0, i = 1; i < 256; i *= 2, j++)
69 printf("%c", "FSRPAU--"[j]);
75 int ip_resend(dev, mtu, r, gwip, datain)
85 int fd, wfd = initdevice(dev, 5), len, i;
91 fd = (*r->r_open)(datain);
93 fd = (*r->r_open)("-");
98 ip = (struct ip *)pbuf;
99 eh = (ether_header_t *)malloc(sizeof(*eh));
102 perror("malloc failed");
106 bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost));
107 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
114 while ((i = (*r->r_readip)((char *)pbuf, sizeof(pbuf), NULL, NULL)) > 0)
116 if (!(opts & OPT_RAW)) {
117 len = ntohs(ip->ip_len);
118 eh = (ether_header_t *)realloc((char *)eh, sizeof(*eh) + len);
119 eh->ether_type = htons((u_short)ETHERTYPE_IP);
121 if (arp((char *)&gwip,
122 (char *)A_A eh->ether_dhost) == -1) {
127 bcopy(dhost, (char *)A_A eh->ether_dhost,
130 ip->ip_sum = chksum((u_short *)ip,
132 bcopy(ip, (char *)(eh + 1), len);
136 eh = (ether_header_t *)pbuf;
140 if (sendip(wfd, (char *)eh, len) == -1)
142 perror("send_packet");