2 * resend.c (C) 1995-1998 Darren Reed
4 * This was written to test what size TCP fragments would get through
5 * various TCP/IP packet filters, as used in IP firewalls. In certain
6 * conditions, enough of the TCP header is missing for unpredictable
7 * results unless the filter is aware that this can happen.
9 * See the IPFILTER.LICENCE file for details on licencing.
11 #if defined(__sgi) && (IRIX > 602)
12 # include <sys/ptimers.h>
19 #include <sys/types.h>
21 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25 #include <netinet/in_systm.h>
26 #include <netinet/ip.h>
27 #include <netinet/tcp.h>
28 #include <netinet/udp.h>
29 #include <netinet/ip_icmp.h>
31 # include <netinet/ip_var.h>
32 # include <netinet/if_ether.h>
33 # if __FreeBSD_version >= 300000
34 # include <net/if_var.h>
40 static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
41 static const char rcsid[] = "@(#)$Id: resend.c,v 2.1.4.5 2002/12/06 11:40:36 darrenr Exp $";
47 static u_char pbuf[65536]; /* 1 big packet */
48 void printpacket __P((ip_t *));
57 t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2));
59 printf("tos %#x ", ip->ip_tos);
60 if (ip->ip_off & 0x3fff)
61 printf("frag @%#x ", (ip->ip_off & 0x1fff) << 3);
62 printf("len %d id %d ", ip->ip_len, ip->ip_id);
63 printf("ttl %d p %d src %s", ip->ip_ttl, ip->ip_p,
64 inet_ntoa(ip->ip_src));
65 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
66 printf(",%d", t->th_sport);
67 printf(" dst %s", inet_ntoa(ip->ip_dst));
68 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
69 printf(",%d", t->th_dport);
70 if (ip->ip_p == IPPROTO_TCP) {
71 printf(" seq %lu:%lu flags ",
72 (u_long)t->th_seq, (u_long)t->th_ack);
73 for (j = 0, i = 1; i < 256; i *= 2, j++)
75 printf("%c", "FSRPAU--"[j]);
81 int ip_resend(dev, mtu, r, gwip, datain)
91 int fd, wfd = initdevice(dev, 0, 5), len, i;
94 fd = (*r->r_open)(datain);
96 fd = (*r->r_open)("-");
101 ip = (struct ip *)pbuf;
102 eh = (ether_header_t *)malloc(sizeof(*eh));
105 perror("malloc failed");
109 bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost));
110 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
116 while ((i = (*r->r_readip)((char *)pbuf, sizeof(pbuf), NULL, NULL)) > 0)
118 if (!(opts & OPT_RAW)) {
119 len = ntohs(ip->ip_len);
120 eh = (ether_header_t *)realloc((char *)eh, sizeof(*eh) + len);
121 eh->ether_type = htons((u_short)ETHERTYPE_IP);
123 if (arp((char *)&gwip,
124 (char *)A_A eh->ether_dhost) == -1) {
129 bcopy(dhost, (char *)A_A eh->ether_dhost,
132 ip->ip_sum = chksum((u_short *)ip,
134 bcopy(ip, (char *)(eh + 1), len);
138 eh = (ether_header_t *)pbuf;
142 if (sendip(wfd, (char *)eh, len) == -1)
144 perror("send_packet");