Deleted Added
full compact
resend.c (170268) resend.c (255332)
1/* $FreeBSD: head/contrib/ipfilter/ipsend/resend.c 170268 2007-06-04 02:54:36Z darrenr $ */
1/* $FreeBSD: head/contrib/ipfilter/ipsend/resend.c 255332 2013-09-06 23:11:19Z cy $ */
2
3/*
4 * resend.c (C) 1995-1998 Darren Reed
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 */
9#if !defined(lint)
10static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
2
3/*
4 * resend.c (C) 1995-1998 Darren Reed
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 */
9#if !defined(lint)
10static const char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
11static const char rcsid[] = "@(#)$Id: resend.c,v 2.8.2.3 2007/02/17 12:41:51 darrenr Exp $";
11static const char rcsid[] = "@(#)$Id$";
12#endif
13#include <sys/param.h>
14#include <sys/types.h>
15#include <sys/time.h>
16#include <sys/socket.h>
12#endif
13#include <sys/param.h>
14#include <sys/types.h>
15#include <sys/time.h>
16#include <sys/socket.h>
17#ifdef __osf__
18# include "radix_ipf_local.h"
19#endif
20#include <net/if.h>
21#include <netinet/in.h>
22#include <arpa/inet.h>
23#include <netinet/in_systm.h>
24#include <netinet/ip.h>
25#ifndef linux
26# include <netinet/ip_var.h>
27# include <netinet/if_ether.h>

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

33#include <netdb.h>
34#include <string.h>
35#include <stdlib.h>
36#include <unistd.h>
37#include "ipsend.h"
38
39extern int opts;
40
17#include <net/if.h>
18#include <netinet/in.h>
19#include <arpa/inet.h>
20#include <netinet/in_systm.h>
21#include <netinet/ip.h>
22#ifndef linux
23# include <netinet/ip_var.h>
24# include <netinet/if_ether.h>

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

30#include <netdb.h>
31#include <string.h>
32#include <stdlib.h>
33#include <unistd.h>
34#include "ipsend.h"
35
36extern int opts;
37
41static u_char pbuf[65536]; /* 1 big packet */
42void printpacket __P((ip_t *));
38void dumppacket __P((ip_t *));
43
44
39
40
45void printpacket(ip)
46ip_t *ip;
41void dumppacket(ip)
42 ip_t *ip;
47{
48 tcphdr_t *t;
49 int i, j;
50
51 t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2));
52 if (ip->ip_tos)
53 printf("tos %#x ", ip->ip_tos);
54 if (ip->ip_off & 0x3fff)

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

68 if (t->th_flags & i)
69 printf("%c", "FSRPAU--"[j]);
70 }
71 putchar('\n');
72}
73
74
75int ip_resend(dev, mtu, r, gwip, datain)
43{
44 tcphdr_t *t;
45 int i, j;
46
47 t = (tcphdr_t *)((char *)ip + (IP_HL(ip) << 2));
48 if (ip->ip_tos)
49 printf("tos %#x ", ip->ip_tos);
50 if (ip->ip_off & 0x3fff)

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

64 if (t->th_flags & i)
65 printf("%c", "FSRPAU--"[j]);
66 }
67 putchar('\n');
68}
69
70
71int ip_resend(dev, mtu, r, gwip, datain)
76char *dev;
77int mtu;
78struct in_addr gwip;
79struct ipread *r;
80char *datain;
72 char *dev;
73 int mtu;
74 struct in_addr gwip;
75 struct ipread *r;
76 char *datain;
81{
82 ether_header_t *eh;
83 char dhost[6];
84 ip_t *ip;
85 int fd, wfd = initdevice(dev, 5), len, i;
77{
78 ether_header_t *eh;
79 char dhost[6];
80 ip_t *ip;
81 int fd, wfd = initdevice(dev, 5), len, i;
82 mb_t mb;
86
87 if (wfd == -1)
88 return -1;
89
90 if (datain)
91 fd = (*r->r_open)(datain);
92 else
93 fd = (*r->r_open)("-");
94
95 if (fd < 0)
96 exit(-1);
97
83
84 if (wfd == -1)
85 return -1;
86
87 if (datain)
88 fd = (*r->r_open)(datain);
89 else
90 fd = (*r->r_open)("-");
91
92 if (fd < 0)
93 exit(-1);
94
98 ip = (struct ip *)pbuf;
95 ip = (struct ip *)mb.mb_buf;
99 eh = (ether_header_t *)malloc(sizeof(*eh));
100 if(!eh)
101 {
102 perror("malloc failed");
103 return -2;
104 }
105
106 bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost));
107 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
108 {
109 perror("arp");
110 free(eh);
111 return -2;
112 }
113
96 eh = (ether_header_t *)malloc(sizeof(*eh));
97 if(!eh)
98 {
99 perror("malloc failed");
100 return -2;
101 }
102
103 bzero((char *)A_A eh->ether_shost, sizeof(eh->ether_shost));
104 if (gwip.s_addr && (arp((char *)&gwip, dhost) == -1))
105 {
106 perror("arp");
107 free(eh);
108 return -2;
109 }
110
114 while ((i = (*r->r_readip)((char *)pbuf, sizeof(pbuf), NULL, NULL)) > 0)
111 while ((i = (*r->r_readip)(&mb, NULL, NULL)) > 0)
115 {
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);
120 if (!gwip.s_addr) {
121 if (arp((char *)&gwip,
122 (char *)A_A eh->ether_dhost) == -1) {
123 perror("arp");
124 continue;
125 }
126 } else
127 bcopy(dhost, (char *)A_A eh->ether_dhost,
128 sizeof(dhost));
129 if (!ip->ip_sum)
130 ip->ip_sum = chksum((u_short *)ip,
131 IP_HL(ip) << 2);
132 bcopy(ip, (char *)(eh + 1), len);
133 len += sizeof(*eh);
112 {
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);
117 if (!gwip.s_addr) {
118 if (arp((char *)&gwip,
119 (char *)A_A eh->ether_dhost) == -1) {
120 perror("arp");
121 continue;
122 }
123 } else
124 bcopy(dhost, (char *)A_A eh->ether_dhost,
125 sizeof(dhost));
126 if (!ip->ip_sum)
127 ip->ip_sum = chksum((u_short *)ip,
128 IP_HL(ip) << 2);
129 bcopy(ip, (char *)(eh + 1), len);
130 len += sizeof(*eh);
134 printpacket(ip);
131 dumppacket(ip);
135 } else {
132 } else {
136 eh = (ether_header_t *)pbuf;
133 eh = (ether_header_t *)mb.mb_buf;
137 len = i;
138 }
139
140 if (sendip(wfd, (char *)eh, len) == -1)
141 {
142 perror("send_packet");
143 break;
144 }
145 }
146 (*r->r_close)();
147 free(eh);
148 return 0;
149}
134 len = i;
135 }
136
137 if (sendip(wfd, (char *)eh, len) == -1)
138 {
139 perror("send_packet");
140 break;
141 }
142 }
143 (*r->r_close)();
144 free(eh);
145 return 0;
146}