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$";
13 #include <sys/param.h>
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <netinet/in_systm.h>
21 #include <netinet/ip.h>
23 # include <netinet/ip_var.h>
24 # include <netinet/if_ether.h>
25 # if __FreeBSD_version >= 300000
26 # include <net/if_var.h>
38 void dumppacket __P((ip_t *));
47 t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2));
49 printf("tos %#x ", ip->ip_tos);
50 if (ip->ip_off & 0x3fff)
51 printf("frag @%#x ", (ip->ip_off & 0x1fff) << 3);
52 printf("len %d id %d ", ip->ip_len, ip->ip_id);
53 printf("ttl %d p %d src %s", ip->ip_ttl, ip->ip_p,
54 inet_ntoa(ip->ip_src));
55 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
56 printf(",%d", t->th_sport);
57 printf(" dst %s", inet_ntoa(ip->ip_dst));
58 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
59 printf(",%d", t->th_dport);
60 if (ip->ip_p == IPPROTO_TCP) {
61 printf(" seq %lu:%lu flags ",
62 (u_long)t->th_seq, (u_long)t->th_ack);
63 for (j = 0, i = 1; i < 256; i *= 2, j++)
65 printf("%c", "FSRPAU--"[j]);
71 int ip_resend(dev, mtu, r, gwip, datain)
81 int fd, wfd = initdevice(dev, 5), len, i;
88 fd = (*r->r_open)(datain);
90 fd = (*r->r_open)("-");
95 ip = (struct ip *)mb.mb_buf;
96 eh = (ether_header_t *)malloc(sizeof(*eh));
99 perror("malloc failed");
103 bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost));
104 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
111 while ((i = (*r->r_readip)(&mb, NULL, NULL)) > 0)
113 if (!(opts & OPT_RAW)) {
114 len = ntohs(ip->ip_len);
115 eh = (ether_header_t *)realloc((char *)eh, sizeof(*eh) + len);
116 eh->ether_type = htons((u_short)ETHERTYPE_IP);
118 if (arp((char *)&gwip,
119 (char *)A_A eh->ether_dhost) == -1) {
124 bcopy(dhost, (char *)A_A eh->ether_dhost,
127 ip->ip_sum = chksum((u_short *)ip,
129 bcopy(ip, (char *)(eh + 1), len);
133 eh = (ether_header_t *)mb.mb_buf;
137 if (sendip(wfd, (char *)eh, len) == -1)
139 perror("send_packet");