Deleted Added
full compact
resend.c (24583) resend.c (31183)
1/*
1/*
2 * resend.c (C) 1995 Darren Reed
2 * resend.c (C) 1995-1997 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 *
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 * Redistribution and use in source and binary forms are permitted
10 * provided that this notice is preserved and due credit is given
11 * to the original author and the contributors.
9 */
12 */
10#if !defined(lint) && defined(LIBC_SCCS)
11static char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
13#if !defined(lint)
14static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
15static const char rcsid[] = "@(#)$Id: resend.c,v 2.0.2.12 1997/10/23 11:42:46 darrenr Exp $";
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
16#endif
17#include <stdio.h>
18#include <netdb.h>
19#include <string.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <sys/types.h>
23#include <sys/time.h>
24#include <sys/socket.h>
25#include <net/if.h>
26#include <netinet/in.h>
27#include <arpa/inet.h>
28#include <netinet/in_systm.h>
29#include <netinet/ip.h>
30#include <netinet/tcp.h>
31#include <netinet/udp.h>
32#include <netinet/ip_icmp.h>
33#ifndef linux
30#include
31#include
34# include <netinet/ip_var.h>
35# include <netinet/if_ether.h>
36# if __FreeBSD_version >= 300000
37# include <net/if_var.h>
38# endif
32#endif
33#include "ipsend.h"
34
39#endif
40#include "ipsend.h"
41
42extern int opts;
35
36static u_char buf[65536]; /* 1 big packet */
43
44static u_char buf[65536]; /* 1 big packet */
37static void printpacket __P((ip_t *));
45void printpacket __P((ip_t *));
38
39
46
47
40static void printpacket(ip)
48void 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);

--- 36 unchanged lines hidden (view full) ---

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
49ip_t *ip;
50{
51 tcphdr_t *t;
52 int i, j;
53
54 t = (tcphdr_t *)((char *)ip + (ip->ip_hl << 2));
55 if (ip->ip_tos)
56 printf("tos %#x ", ip->ip_tos);

--- 36 unchanged lines hidden (view full) ---

93 fd = (*r->r_open)("-");
94
95 if (fd < 0)
96 exit(-1);
97
98 ip = (struct ip *)buf;
99 eh = (ether_header_t *)malloc(sizeof(*eh));
100
93 bzero(&eh->ether_shost, sizeof(eh->ether_shost));
101 bzero((char *)A_A 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 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
103 {
104 perror("arp");
105 return -2;
106 }
107
108 while ((i = (*r->r_readip)(buf, sizeof(buf), NULL, NULL)) > 0)
109 {
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);
110 if (!(opts & OPT_RAW)) {
111 len = ntohs(ip->ip_len);
112 eh = (ether_header_t *)realloc((char *)eh, sizeof(*eh) + len);
113 eh->ether_type = htons((u_short)ETHERTYPE_IP);
114 if (!gwip.s_addr) {
115 if (arp((char *)&gwip,
116 (char *)A_A eh->ether_dhost) == -1) {
117 perror("arp");
118 continue;
119 }
120 } else
121 bcopy(dhost, (char *)A_A eh->ether_dhost,
122 sizeof(dhost));
123 if (!ip->ip_sum)
124 ip->ip_sum = chksum((u_short *)ip,
125 ip->ip_hl << 2);
126 bcopy(ip, (char *)(eh + 1), len);
127 len += sizeof(*eh);
128 printpacket(ip);
129 } else {
130 eh = (ether_header_t *)buf;
131 len = i;
132 }
115
133
116 if (sendip(wfd, (char *)eh, sizeof(*eh) + len) == -1)
134 if (sendip(wfd, (char *)eh, len) == -1)
117 {
118 perror("send_packet");
119 break;
120 }
121 }
122 (*r->r_close)();
123 return 0;
124}
135 {
136 perror("send_packet");
137 break;
138 }
139 }
140 (*r->r_close)();
141 return 0;
142}