Deleted Added
sdiff udiff text old ( 24583 ) new ( 31183 )
full compact
1/*
2 * resend.c (C) 1995 Darren Reed
3 *
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.
8 *
9 */
10#if !defined(lint) && defined(LIBC_SCCS)
11static char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
12#endif
13#include <stdio.h>
14#include <netdb.h>
15#include <string.h>
16#include <stdlib.h>
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/time.h>
20#include <sys/socket.h>
21#include <net/if.h>
22#include <netinet/in.h>
23#include <arpa/inet.h>
24#include <netinet/in_systm.h>
25#include <netinet/ip.h>
26#include <netinet/tcp.h>
27#include <netinet/udp.h>
28#include <netinet/ip_icmp.h>
29#ifndef linux
30#include
31#include
32#endif
33#include "ipsend.h"
34
35
36static u_char buf[65536]; /* 1 big packet */
37static void printpacket __P((ip_t *));
38
39
40static void printpacket(ip)
41ip_t *ip;
42{
43 tcphdr_t *t;
44 int i, j;
45
46 t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2));
47 if (ip->ip_tos)
48 printf("tos %#x ", ip->ip_tos);
49 if (ip->ip_off & 0x3fff)
50 printf("frag @%#x ", (ip->ip_off & 0x1fff) << 3);
51 printf("len %d id %d ", ip->ip_len, ip->ip_id);
52 printf("ttl %d p %d src %s", ip->ip_ttl, ip->ip_p,
53 inet_ntoa(ip->ip_src));
54 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
55 printf(",%d", t->th_sport);
56 printf(" dst %s", inet_ntoa(ip->ip_dst));
57 if (ip->ip_p == IPPROTO_TCP || ip->ip_p == IPPROTO_UDP)
58 printf(",%d", t->th_dport);
59 if (ip->ip_p == IPPROTO_TCP) {
60 printf(" seq %lu:%lu flags ",
61 (u_long)t->th_seq, (u_long)t->th_ack);
62 for (j = 0, i = 1; i < 256; i *= 2, j++)
63 if (t->th_flags & i)
64 printf("%c", "FSRPAU--"[j]);
65 }
66 putchar('\n');
67}
68
69
70int ip_resend(dev, mtu, r, gwip, datain)
71char *dev;
72int mtu;
73struct in_addr gwip;
74struct ipread *r;
75char *datain;
76{
77 ether_header_t *eh;
78 char dhost[6];
79 ip_t *ip;
80 int fd, wfd = initdevice(dev, 0, 5), len, i;
81
82 if (datain)
83 fd = (*r->r_open)(datain);
84 else
85 fd = (*r->r_open)("-");
86
87 if (fd < 0)
88 exit(-1);
89
90 ip = (struct ip *)buf;
91 eh = (ether_header_t *)malloc(sizeof(*eh));
92
93 bzero(&eh->ether_shost, sizeof(eh->ether_shost));
94 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
95 {
96 perror("arp");
97 return -2;
98 }
99
100 while ((i = (*r->r_readip)(buf, sizeof(buf), NULL, NULL)) > 0)
101 {
102 len = ntohs(ip->ip_len);
103 eh = (ether_header_t *)realloc((char *)eh, sizeof(*eh) + len);
104 eh->ether_type = htons((u_short)ETHERTYPE_IP);
105 if (!gwip.s_addr) {
106 if (arp((char *)&gwip,
107 (char *)&eh->ether_dhost) == -1) {
108 perror("arp");
109 continue;
110 }
111 } else
112 bcopy(dhost, (char *)&eh->ether_dhost, sizeof(dhost));
113 bcopy(ip, (char *)(eh + 1), len);
114 printpacket(ip);
115
116 if (sendip(wfd, (char *)eh, sizeof(*eh) + len) == -1)
117 {
118 perror("send_packet");
119 break;
120 }
121 }
122 (*r->r_close)();
123 return 0;
124}