summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/ipsend
diff options
context:
space:
mode:
authordarrenr <darrenr@FreeBSD.org>2004-06-21 22:47:51 +0000
committerdarrenr <darrenr@FreeBSD.org>2004-06-21 22:47:51 +0000
commit590450fec65a8e72a8965117398bc8f14938b4a8 (patch)
tree699025ff2d567ed726a446a7ca5c3d916f5ca0a4 /contrib/ipfilter/ipsend
parent244f07541460d6bd022a1eea60585315231e9e1c (diff)
downloadFreeBSD-src-590450fec65a8e72a8965117398bc8f14938b4a8.zip
FreeBSD-src-590450fec65a8e72a8965117398bc8f14938b4a8.tar.gz
Import ipfilter 3.4.35 onto vendor branch
Diffstat (limited to 'contrib/ipfilter/ipsend')
-rw-r--r--contrib/ipfilter/ipsend/in_var.h2
-rw-r--r--contrib/ipfilter/ipsend/ipsend.12
-rw-r--r--contrib/ipfilter/ipsend/ipsend.510
-rw-r--r--contrib/ipfilter/ipsend/ipsend.c85
-rw-r--r--contrib/ipfilter/ipsend/ipsopt.c7
5 files changed, 80 insertions, 26 deletions
diff --git a/contrib/ipfilter/ipsend/in_var.h b/contrib/ipfilter/ipsend/in_var.h
index 63980ef..b935259 100644
--- a/contrib/ipfilter/ipsend/in_var.h
+++ b/contrib/ipfilter/ipsend/in_var.h
@@ -76,7 +76,7 @@ struct ifqueue ipintrq; /* ip packet input queue */
(ia) != NULL && (ia)->ia_ifp != (ifp); \
(ia) = (ia)->ia_next); \
}
-#endif KERNEL
+#endif /* KERNEL */
/*
* Per-interface router version information is kept in this list.
diff --git a/contrib/ipfilter/ipsend/ipsend.1 b/contrib/ipfilter/ipsend/ipsend.1
index 04d895d..f2f8066 100644
--- a/contrib/ipfilter/ipsend/ipsend.1
+++ b/contrib/ipfilter/ipsend/ipsend.1
@@ -51,7 +51,7 @@ enable debugging mode.
.TP
.BR \-f \0<offset>
The \fI-f\fP allows the IP offset field in the IP header to be set to an
-arbitrary value, which can be specified in decimal or hexidecimal.
+arbitrary value, which can be specified in decimal or hexadecimal.
.TP
.BR \-g \0<gateway>
Specify the hostname of the gateway through which to route packets. This
diff --git a/contrib/ipfilter/ipsend/ipsend.5 b/contrib/ipfilter/ipsend/ipsend.5
index 1e4e82e..f713147 100644
--- a/contrib/ipfilter/ipsend/ipsend.5
+++ b/contrib/ipfilter/ipsend/ipsend.5
@@ -102,7 +102,7 @@ route installed in the kernel.
is used to describe an IP (version 4) packet. IP header fields can be
specified, including options, followed by a data section which may contain
further protocol headers.
-.SH IPV4
+.SH IPv4
.TP
.B hl <number>
manually specifies the IP header length (automatically adjusts with the
@@ -116,7 +116,7 @@ set the type of service (TOS) field in the IP header. Default is 0.
.TP
.B len <number>
manually specifies the length of the IP packet. The length will automatically
-be adjusted to accomodate data or further protocol headers.
+be adjusted to accommodate data or further protocol headers.
.TP
.B off <number>
sets the fragment offset field of the IP packet. Default is 0.
@@ -158,7 +158,7 @@ is used to indicate the a ICMP protocol header is to follow. See the
is used to indicate that raw data is to be included in the IP packet. See the
\fBDATA\fP section for details on options available.
.SH "IPv4 Options"
-these keywords indicate that the releveant IP option should be added to the
+these keywords indicate that the relevant IP option should be added to the
IP header (the header length field will be adjusted appropriately).
.TP
.B nop
@@ -210,7 +210,7 @@ Strict Source Route [RFC 791].
Address Extension
.TP
.B visa
-Expermental Access Control.
+Experimental Access Control.
.TP
.B imitd
IMI Traffic Descriptor.
@@ -314,7 +314,7 @@ bytes with any particular data).
indicates that the string provided should be added to the current packet as
data. A string may be a consecutive list of characters and numbers (with
no white spaces) or bounded by "'s (may not contain them, even if \\'d).
-The \\ charcater is recognised with the appropriate C escaped values, including
+The \\ character is recognised with the appropriate C escaped values, including
octal numbers.
.TP
.B file <filename>
diff --git a/contrib/ipfilter/ipsend/ipsend.c b/contrib/ipfilter/ipsend/ipsend.c
index 4e3f050..cdf18a7 100644
--- a/contrib/ipfilter/ipsend/ipsend.c
+++ b/contrib/ipfilter/ipsend/ipsend.c
@@ -24,8 +24,10 @@
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
+#include <netinet/udp_var.h>
#include <netinet/ip_icmp.h>
#ifndef linux
#include <netinet/ip_var.h>
@@ -34,7 +36,7 @@
#if !defined(lint)
static const char sccsid[] = "@(#)ipsend.c 1.5 12/10/95 (C)1995 Darren Reed";
-static const char rcsid[] = "@(#)$Id: ipsend.c,v 2.2.2.6 2002/12/06 11:40:35 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id: ipsend.c,v 2.2.2.7 2004/04/10 11:50:52 darrenr Exp $";
#endif
@@ -69,6 +71,7 @@ char default_device[] = "lan0";
static void usage __P((char *));
static void do_icmp __P((ip_t *, char *));
+void udpcksum(ip_t *, struct udphdr *, int);
int main __P((int, char **));
@@ -168,6 +171,37 @@ struct in_addr gwip;
return send_packet(wfd, mtu, ip, gwip);
}
+void
+udpcksum(ip_t *ip, struct udphdr *udp, int len)
+{
+ union pseudoh {
+ struct hdr {
+ u_short len;
+ u_char ttl;
+ u_char proto;
+ u_32_t src;
+ u_32_t dst;
+ } h;
+ u_short w[6];
+ } ph;
+ u_32_t temp32;
+ u_short cksum, *opts;
+
+ ph.h.len = htons(len);
+ ph.h.ttl = 0;
+ ph.h.proto = IPPROTO_UDP;
+ ph.h.src = ip->ip_src.s_addr;
+ ph.h.dst = ip->ip_dst.s_addr;
+ temp32 = 0;
+ opts = &ph.w[0];
+ temp32 += opts[0] + opts[1] + opts[2] + opts[3] + opts[4] + opts[5];
+ temp32 = (temp32 >> 16) + (temp32 & 65535);
+ temp32 += (temp32 >> 16);
+ udp->uh_sum = temp32 & 65535;
+ udp->uh_sum = chksum((u_short *)udp, len);
+ if (udp->uh_sum == 0)
+ udp->uh_sum = 0xffff;
+}
int main(argc, argv)
int argc;
@@ -175,8 +209,10 @@ char **argv;
{
FILE *langfile = NULL;
struct tcpiphdr *ti;
+ struct udpiphdr *ui;
struct in_addr gwip;
tcphdr_t *tcp;
+ udphdr_t *udp;
ip_t *ip;
char *name = argv[0], host[MAXHOSTNAMELEN + 1];
char *gateway = NULL, *dev = NULL;
@@ -188,7 +224,10 @@ char **argv;
*/
ip = (ip_t *)calloc(1, 65536);
ti = (struct tcpiphdr *)ip;
+ ui = (struct udpiphdr *)ip;
tcp = (tcphdr_t *)&ti->ti_sport;
+ udp = (udphdr_t *)&ui->ui_sport;
+ ui->ui_ulen = htons(sizeof(*udp));
ip->ip_len = sizeof(*ip);
ip->ip_hl = sizeof(*ip) >> 2;
@@ -342,27 +381,35 @@ char **argv;
exit(2);
}
+ if (ip->ip_p != IPPROTO_TCP && ip->ip_p != IPPROTO_UDP) {
+ fprintf(stderr,"Unsupported protocol %d\n", ip->ip_p);
+ exit(2);
+ }
+
if (olen)
{
- caddr_t ipo = (caddr_t)ip;
+ int hlen;
+ char *p;
printf("Options: %d\n", olen);
- ti = (struct tcpiphdr *)malloc(olen + ip->ip_len);
- if(!ti)
+ hlen = sizeof(*ip) + olen;
+ ip->ip_hl = hlen >> 2;
+ ip->ip_len += olen;
+ p = (char *)malloc(65536);
+ if(!p)
{
fprintf(stderr,"malloc failed\n");
exit(2);
}
-
- bcopy((char *)ip, (char *)ti, sizeof(*ip));
- ip = (ip_t *)ti;
- ip->ip_hl = (olen >> 2);
- bcopy(options, (char *)(ip + 1), olen);
- bcopy((char *)tcp, (char *)(ip + 1) + olen, sizeof(*tcp));
- ip->ip_len += olen;
- bcopy((char *)ip, (char *)ipo, ip->ip_len);
- ip = (ip_t *)ipo;
- tcp = (tcphdr_t *)((char *)(ip + 1) + olen);
+ bcopy(ip, p, sizeof(*ip));
+ bcopy(options, p + sizeof(*ip), olen);
+ bcopy(ip + 1, p + hlen, ip->ip_len - hlen);
+ ip = (ip_t *)p;
+ if (ip->ip_p == IPPROTO_TCP) {
+ tcp = (tcphdr_t *)((char *)ip + hlen);
+ } else {
+ udp = (udphdr_t *)((char *)ip + hlen);
+ }
}
if (ip->ip_p == IPPROTO_TCP)
@@ -399,9 +446,13 @@ char **argv;
printf("Flags: %#x\n", tcp->th_flags);
printf("mtu: %d\n", mtu);
+ if (ip->ip_p == IPPROTO_UDP) {
+ udp->uh_sum = 0;
+ udpcksum(ip, udp, (ip->ip_len) - (ip->ip_hl << 2));
+ }
#ifdef DOSOCKET
- if (tcp->th_dport)
- return do_socket(dev, mtu, ti, gwip);
+ if (ip->ip_p == IPPROTO_TCP && tcp->th_dport)
+ return do_socket(dev, mtu, (struct tcpiphdr *)ip, gwip);
#endif
- return send_packets(dev, mtu, (ip_t *)ti, gwip);
+ return send_packets(dev, mtu, ip, gwip);
}
diff --git a/contrib/ipfilter/ipsend/ipsopt.c b/contrib/ipfilter/ipsend/ipsopt.c
index 5759bf9..144c86f 100644
--- a/contrib/ipfilter/ipsend/ipsopt.c
+++ b/contrib/ipfilter/ipsend/ipsopt.c
@@ -25,7 +25,7 @@
#if !defined(lint)
static const char sccsid[] = "@(#)ipsopt.c 1.2 1/11/96 (C)1995 Darren Reed";
-static const char rcsid[] = "@(#)$Id: ipsopt.c,v 2.1.4.4 2002/12/06 11:40:35 darrenr Exp $";
+static const char rcsid[] = "@(#)$Id: ipsopt.c,v 2.1.4.5 2004/04/10 11:50:52 darrenr Exp $";
#endif
@@ -98,7 +98,10 @@ char *class;
len += val;
} else
*op++ = io->on_siz;
- *op++ = IPOPT_MINOFF;
+ if (io->on_value == IPOPT_TS)
+ *op++ = IPOPT_MINOFF + 1;
+ else
+ *op++ = IPOPT_MINOFF;
while (class && *class) {
t = NULL;
OpenPOWER on IntegriCloud