libnet4r 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +15 -0
- data/LICENSE +28 -0
- data/README +187 -0
- data/Rakefile +110 -0
- data/ext/extconf.rb +60 -0
- data/ext/libnet.c +705 -0
- data/ext/libnet_arp.c +152 -0
- data/ext/libnet_ethernet.c +115 -0
- data/ext/libnet_ipv4.c +140 -0
- data/ext/libnet_ipv6.c +138 -0
- data/ext/libnet_udp.c +112 -0
- data/ext/libnet_vlan.c +131 -0
- data/lib/libnet4r/header.rb +609 -0
- data/lib/libnet4r/helpers.rb +19 -0
- data/lib/libnet4r/libnet.rb +39 -0
- data/libnet/CVS/Entries +24 -0
- data/libnet/CVS/Repository +1 -0
- data/libnet/CVS/Root +1 -0
- data/libnet/Makefile.am +15 -0
- data/libnet/Makefile.am.common +10 -0
- data/libnet/Makefile.in +443 -0
- data/libnet/README +21 -0
- data/libnet/VERSION +1 -0
- data/libnet/acconfig.h +36 -0
- data/libnet/acinclude.m4 +463 -0
- data/libnet/aclocal.m4 +1337 -0
- data/libnet/autom4te.cache/CVS/Entries +1 -0
- data/libnet/autom4te.cache/CVS/Repository +1 -0
- data/libnet/autom4te.cache/CVS/Root +1 -0
- data/libnet/autom4te.cache/output.0 +6225 -0
- data/libnet/autom4te.cache/requests +111 -0
- data/libnet/autom4te.cache/traces.0 +272 -0
- data/libnet/config.guess +1314 -0
- data/libnet/config.sub +1410 -0
- data/libnet/configure +6225 -0
- data/libnet/configure.in +235 -0
- data/libnet/doc/BUGS +19 -0
- data/libnet/doc/CHANGELOG +527 -0
- data/libnet/doc/CONTRIB +53 -0
- data/libnet/doc/COPYING +31 -0
- data/libnet/doc/CVS/Entries +12 -0
- data/libnet/doc/CVS/Repository +1 -0
- data/libnet/doc/CVS/Root +1 -0
- data/libnet/doc/DESIGN_NOTES +134 -0
- data/libnet/doc/MIGRATION +172 -0
- data/libnet/doc/PACKET_BUILDING +161 -0
- data/libnet/doc/PORTED +45 -0
- data/libnet/doc/RAWSOCKET_NON_SEQUITUR +41 -0
- data/libnet/doc/TODO +96 -0
- data/libnet/doc/html/acconfig_8h-source.html +49 -0
- data/libnet/doc/html/annotated.html +17 -0
- data/libnet/doc/html/bpf_8h-source.html +277 -0
- data/libnet/doc/html/config_8h-source.html +125 -0
- data/libnet/doc/html/doxygen.css +169 -0
- data/libnet/doc/html/doxygen.png +0 -0
- data/libnet/doc/html/files.html +29 -0
- data/libnet/doc/html/functions.html +26 -0
- data/libnet/doc/html/functions_vars.html +26 -0
- data/libnet/doc/html/getopt_8h-source.html +97 -0
- data/libnet/doc/html/globals.html +219 -0
- data/libnet/doc/html/globals_defs.html +104 -0
- data/libnet/doc/html/globals_func.html +136 -0
- data/libnet/doc/html/gnuc_8h-source.html +56 -0
- data/libnet/doc/html/graph_legend.dot +22 -0
- data/libnet/doc/html/graph_legend.html +75 -0
- data/libnet/doc/html/ifaddrlist_8h-source.html +65 -0
- data/libnet/doc/html/in__systm_8h-source.html +90 -0
- data/libnet/doc/html/index.html +17 -0
- data/libnet/doc/html/libnet-asn1_8h-source.html +268 -0
- data/libnet/doc/html/libnet-functions_8h-source.html +742 -0
- data/libnet/doc/html/libnet-functions_8h.html +8844 -0
- data/libnet/doc/html/libnet-headers_8h-source.html +1655 -0
- data/libnet/doc/html/libnet-headers_8h.html +3053 -0
- data/libnet/doc/html/libnet-macros_8h-source.html +161 -0
- data/libnet/doc/html/libnet-macros_8h.html +358 -0
- data/libnet/doc/html/libnet-structures_8h-source.html +233 -0
- data/libnet/doc/html/libnet-types_8h-source.html +58 -0
- data/libnet/doc/html/libnet_8h-source.html +119 -0
- data/libnet/doc/html/libnet_8h.html +24 -0
- data/libnet/doc/html/structlibnet__802__1q__hdr.html +145 -0
- data/libnet/doc/html/structlibnet__802__1x__hdr.html +97 -0
- data/libnet/doc/libnet.doxygen.conf +1102 -0
- data/libnet/doc/man/CVS/Entries +1 -0
- data/libnet/doc/man/CVS/Repository +1 -0
- data/libnet/doc/man/CVS/Root +1 -0
- data/libnet/doc/man/man3/libnet-functions.h.3 +3136 -0
- data/libnet/doc/man/man3/libnet-headers.h.3 +1872 -0
- data/libnet/doc/man/man3/libnet-macros.h.3 +172 -0
- data/libnet/doc/man/man3/libnet.h.3 +17 -0
- data/libnet/doc/man/man3/libnet_802_1q_hdr.3 +53 -0
- data/libnet/doc/man/man3/libnet_802_1x_hdr.3 +41 -0
- data/libnet/include/CVS/Entries +10 -0
- data/libnet/include/CVS/Repository +1 -0
- data/libnet/include/CVS/Root +1 -0
- data/libnet/include/Makefile.am +7 -0
- data/libnet/include/Makefile.in +395 -0
- data/libnet/include/bpf.h +264 -0
- data/libnet/include/config.h.in +118 -0
- data/libnet/include/gnuc.h +43 -0
- data/libnet/include/ifaddrlist.h +52 -0
- data/libnet/include/libnet/CVS/Entries +9 -0
- data/libnet/include/libnet/CVS/Repository +1 -0
- data/libnet/include/libnet/CVS/Root +1 -0
- data/libnet/include/libnet/Makefile.am +12 -0
- data/libnet/include/libnet/Makefile.in +294 -0
- data/libnet/include/libnet/libnet-asn1.h +255 -0
- data/libnet/include/libnet/libnet-functions.h +2157 -0
- data/libnet/include/libnet/libnet-headers.h +1662 -0
- data/libnet/include/libnet/libnet-macros.h +186 -0
- data/libnet/include/libnet/libnet-structures.h +222 -0
- data/libnet/include/libnet/libnet-types.h +45 -0
- data/libnet/include/libnet.h.in +132 -0
- data/libnet/include/stamp-h.in +1 -0
- data/libnet/include/win32/CVS/Entries +5 -0
- data/libnet/include/win32/CVS/Repository +1 -0
- data/libnet/include/win32/CVS/Root +1 -0
- data/libnet/include/win32/config.h +112 -0
- data/libnet/include/win32/getopt.h +84 -0
- data/libnet/include/win32/in_systm.h +77 -0
- data/libnet/include/win32/libnet.h +106 -0
- data/libnet/install-sh +250 -0
- data/libnet/libnet-config.in +62 -0
- data/libnet/libnet.doxygen.conf +1102 -0
- data/libnet/man/CVS/Entries +1 -0
- data/libnet/man/CVS/Repository +1 -0
- data/libnet/man/CVS/Root +1 -0
- data/libnet/missing +283 -0
- data/libnet/mkinstalldirs +40 -0
- data/libnet/sample/CVS/Entries +47 -0
- data/libnet/sample/CVS/Repository +1 -0
- data/libnet/sample/CVS/Root +1 -0
- data/libnet/sample/Makefile.am +63 -0
- data/libnet/sample/Makefile.in +729 -0
- data/libnet/sample/arp-new.c +144 -0
- data/libnet/sample/arp.c +151 -0
- data/libnet/sample/bgp4_hdr.c +225 -0
- data/libnet/sample/bgp4_notification.c +242 -0
- data/libnet/sample/bgp4_open.c +266 -0
- data/libnet/sample/bgp4_update.c +337 -0
- data/libnet/sample/cdp.c +187 -0
- data/libnet/sample/dhcp_discover.c +257 -0
- data/libnet/sample/dns.c +260 -0
- data/libnet/sample/dot1x.c +113 -0
- data/libnet/sample/fddi_tcp1.c +213 -0
- data/libnet/sample/fddi_tcp2.c +209 -0
- data/libnet/sample/get_addr.c +112 -0
- data/libnet/sample/gre.c +410 -0
- data/libnet/sample/icmp6_echoreq.c +184 -0
- data/libnet/sample/icmp_echo_cq.c +201 -0
- data/libnet/sample/icmp_redirect.c +200 -0
- data/libnet/sample/icmp_timeexceed.c +190 -0
- data/libnet/sample/icmp_timestamp.c +157 -0
- data/libnet/sample/icmp_unreach.c +204 -0
- data/libnet/sample/ieee.c +177 -0
- data/libnet/sample/ip_link.c +201 -0
- data/libnet/sample/ip_raw.c +180 -0
- data/libnet/sample/isl.c +167 -0
- data/libnet/sample/libnet_test.h +60 -0
- data/libnet/sample/mpls.c +251 -0
- data/libnet/sample/ntp.c +193 -0
- data/libnet/sample/ospf_hello.c +179 -0
- data/libnet/sample/ospf_lsa.c +190 -0
- data/libnet/sample/ping_of_death.c +171 -0
- data/libnet/sample/rpc_tcp.c +214 -0
- data/libnet/sample/rpc_udp.c +213 -0
- data/libnet/sample/sebek.c +299 -0
- data/libnet/sample/smurf.c +194 -0
- data/libnet/sample/stp.c +227 -0
- data/libnet/sample/synflood.c +200 -0
- data/libnet/sample/synflood6.c +209 -0
- data/libnet/sample/synflood6_frag.c +234 -0
- data/libnet/sample/tcp1.c +227 -0
- data/libnet/sample/tcp2.c +192 -0
- data/libnet/sample/tftp.c +207 -0
- data/libnet/sample/tring_tcp1.c +214 -0
- data/libnet/sample/tring_tcp2.c +210 -0
- data/libnet/sample/udp1.c +223 -0
- data/libnet/sample/udp2.c +232 -0
- data/libnet/sample/win32/CVS/Entries +9 -0
- data/libnet/sample/win32/CVS/Repository +1 -0
- data/libnet/sample/win32/CVS/Root +1 -0
- data/libnet/sample/win32/arp/CVS/Entries +2 -0
- data/libnet/sample/win32/arp/CVS/Repository +1 -0
- data/libnet/sample/win32/arp/CVS/Root +1 -0
- data/libnet/sample/win32/arp/arp.vcproj +136 -0
- data/libnet/sample/win32/cdp/CVS/Entries +2 -0
- data/libnet/sample/win32/cdp/CVS/Repository +1 -0
- data/libnet/sample/win32/cdp/CVS/Root +1 -0
- data/libnet/sample/win32/cdp/cdp.vcproj +136 -0
- data/libnet/sample/win32/dhcp_discover/CVS/Entries +2 -0
- data/libnet/sample/win32/dhcp_discover/CVS/Repository +1 -0
- data/libnet/sample/win32/dhcp_discover/CVS/Root +1 -0
- data/libnet/sample/win32/dhcp_discover/dhcp_discover.vcproj +139 -0
- data/libnet/sample/win32/dns/CVS/Entries +2 -0
- data/libnet/sample/win32/dns/CVS/Repository +1 -0
- data/libnet/sample/win32/dns/CVS/Root +1 -0
- data/libnet/sample/win32/dns/dns.vcproj +139 -0
- data/libnet/sample/win32/get_addr/CVS/Entries +2 -0
- data/libnet/sample/win32/get_addr/CVS/Repository +1 -0
- data/libnet/sample/win32/get_addr/CVS/Root +1 -0
- data/libnet/sample/win32/get_addr/get_addr.vcproj +139 -0
- data/libnet/sample/win32/getopt.c +121 -0
- data/libnet/sample/win32/icmp_echo_cq/CVS/Entries +2 -0
- data/libnet/sample/win32/icmp_echo_cq/CVS/Repository +1 -0
- data/libnet/sample/win32/icmp_echo_cq/CVS/Root +1 -0
- data/libnet/sample/win32/icmp_echo_cq/icmp_echo_cq.vcproj +139 -0
- data/libnet/sample/win32/tcp1/CVS/Entries +2 -0
- data/libnet/sample/win32/tcp1/CVS/Repository +1 -0
- data/libnet/sample/win32/tcp1/CVS/Root +1 -0
- data/libnet/sample/win32/tcp1/tcp1.vcproj +142 -0
- data/libnet/sample/win32/udp1/CVS/Entries +3 -0
- data/libnet/sample/win32/udp1/CVS/Repository +1 -0
- data/libnet/sample/win32/udp1/CVS/Root +1 -0
- data/libnet/sample/win32/udp1/dns.vcproj +125 -0
- data/libnet/sample/win32/udp1/udp1.vcproj +139 -0
- data/libnet/src/CVS/Entries +60 -0
- data/libnet/src/CVS/Repository +1 -0
- data/libnet/src/CVS/Root +1 -0
- data/libnet/src/Makefile.am +71 -0
- data/libnet/src/Makefile.in +428 -0
- data/libnet/src/libnet_advanced.c +136 -0
- data/libnet/src/libnet_asn1.c +436 -0
- data/libnet/src/libnet_build_802.1q.c +115 -0
- data/libnet/src/libnet_build_802.1x.c +103 -0
- data/libnet/src/libnet_build_802.2.c +167 -0
- data/libnet/src/libnet_build_802.3.c +101 -0
- data/libnet/src/libnet_build_arp.c +169 -0
- data/libnet/src/libnet_build_bgp.c +350 -0
- data/libnet/src/libnet_build_cdp.c +191 -0
- data/libnet/src/libnet_build_data.c +90 -0
- data/libnet/src/libnet_build_dhcp.c +156 -0
- data/libnet/src/libnet_build_dns.c +129 -0
- data/libnet/src/libnet_build_ethernet.c +173 -0
- data/libnet/src/libnet_build_fddi.c +191 -0
- data/libnet/src/libnet_build_gre.c +427 -0
- data/libnet/src/libnet_build_icmp.c +437 -0
- data/libnet/src/libnet_build_igmp.c +112 -0
- data/libnet/src/libnet_build_ip.c +892 -0
- data/libnet/src/libnet_build_ipsec.c +232 -0
- data/libnet/src/libnet_build_isl.c +113 -0
- data/libnet/src/libnet_build_link.c +90 -0
- data/libnet/src/libnet_build_mpls.c +112 -0
- data/libnet/src/libnet_build_ntp.c +121 -0
- data/libnet/src/libnet_build_ospf.c +699 -0
- data/libnet/src/libnet_build_rip.c +108 -0
- data/libnet/src/libnet_build_rpc.c +138 -0
- data/libnet/src/libnet_build_sebek.c +108 -0
- data/libnet/src/libnet_build_snmp.c +52 -0
- data/libnet/src/libnet_build_stp.c +222 -0
- data/libnet/src/libnet_build_tcp.c +365 -0
- data/libnet/src/libnet_build_token_ring.c +193 -0
- data/libnet/src/libnet_build_udp.c +111 -0
- data/libnet/src/libnet_build_vrrp.c +117 -0
- data/libnet/src/libnet_checksum.c +376 -0
- data/libnet/src/libnet_cq.c +395 -0
- data/libnet/src/libnet_crc.c +113 -0
- data/libnet/src/libnet_dll.c +47 -0
- data/libnet/src/libnet_error.c +55 -0
- data/libnet/src/libnet_if_addr.c +415 -0
- data/libnet/src/libnet_init.c +234 -0
- data/libnet/src/libnet_internal.c +310 -0
- data/libnet/src/libnet_link_bpf.c +348 -0
- data/libnet/src/libnet_link_dlpi.c +785 -0
- data/libnet/src/libnet_link_linux.c +310 -0
- data/libnet/src/libnet_link_nit.c +125 -0
- data/libnet/src/libnet_link_none.c +66 -0
- data/libnet/src/libnet_link_pf.c +179 -0
- data/libnet/src/libnet_link_snit.c +149 -0
- data/libnet/src/libnet_link_snoop.c +166 -0
- data/libnet/src/libnet_link_win32.c +346 -0
- data/libnet/src/libnet_pblock.c +511 -0
- data/libnet/src/libnet_port_list.c +295 -0
- data/libnet/src/libnet_prand.c +106 -0
- data/libnet/src/libnet_raw.c +257 -0
- data/libnet/src/libnet_resolve.c +414 -0
- data/libnet/src/libnet_version.c +54 -0
- data/libnet/src/libnet_write.c +502 -0
- data/libnet/version.h.in +6 -0
- data/libnet/win32/CVS/Entries +15 -0
- data/libnet/win32/CVS/Repository +1 -0
- data/libnet/win32/CVS/Root +1 -0
- data/libnet/win32/Libnet-1.1.1-2002.sln +77 -0
- data/libnet/win32/Libnet-1.1.1-2003.ncb +0 -0
- data/libnet/win32/Libnet-1.1.1-2003.sln +84 -0
- data/libnet/win32/Libnet-1.1.1-2003.suo +0 -0
- data/libnet/win32/Libnet-1.1.1.vcproj +311 -0
- data/libnet/win32/Libnet-latest.ncb +0 -0
- data/libnet/win32/Libnet-latest.opt +0 -0
- data/libnet/win32/Libnet-latest.sln +77 -0
- data/libnet/win32/Libnet-latest.suo +0 -0
- data/libnet/win32/Libnet-latest.vcproj +311 -0
- data/libnet/win32/Libnet.dsp +337 -0
- data/libnet/win32/Libnet.dsw +32 -0
- data/libnet/win32/README.txt +57 -0
- data/libnet/win32/libnet_dll.def +164 -0
- data/test/tc_arp.rb +169 -0
- data/test/tc_class.rb +219 -0
- data/test/tc_ethernet.rb +97 -0
- data/test/tc_header.rb +163 -0
- data/test/tc_init.rb +25 -0
- data/test/tc_ipv4.rb +219 -0
- data/test/tc_ipv6.rb +235 -0
- data/test/tc_udp.rb +229 -0
- data/test/tc_vlan.rb +118 -0
- data/test/ts_all.rb +15 -0
- metadata +401 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: icmp_echo_cq.c,v 1.3 2004/01/03 20:31:01 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet 1.1
|
5
|
+
* Build ICMP_ECHO packets using the context queue interface.
|
6
|
+
*
|
7
|
+
* Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
|
8
|
+
* All rights reserved.
|
9
|
+
*
|
10
|
+
* Redistribution and use in source and binary forms, with or without
|
11
|
+
* modification, are permitted provided that the following conditions
|
12
|
+
* are met:
|
13
|
+
* 1. Redistributions of source code must retain the above copyright
|
14
|
+
* notice, this list of conditions and the following disclaimer.
|
15
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
16
|
+
* notice, this list of conditions and the following disclaimer in the
|
17
|
+
* documentation and/or other materials provided with the distribution.
|
18
|
+
*
|
19
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
20
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
21
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
22
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
23
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
24
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
25
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
26
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
27
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
28
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
29
|
+
* SUCH DAMAGE.
|
30
|
+
*
|
31
|
+
*/
|
32
|
+
|
33
|
+
#if (HAVE_CONFIG_H)
|
34
|
+
#include "../include/config.h"
|
35
|
+
#endif
|
36
|
+
#include "./libnet_test.h"
|
37
|
+
#ifdef __WIN32__
|
38
|
+
#include "../include/win32/getopt.h"
|
39
|
+
#endif
|
40
|
+
|
41
|
+
void usage(char *);
|
42
|
+
|
43
|
+
|
44
|
+
int
|
45
|
+
main(int argc, char **argv)
|
46
|
+
{
|
47
|
+
libnet_t *l = NULL;
|
48
|
+
u_long src_ip = 0, dst_ip = 0;
|
49
|
+
u_long count = 10;
|
50
|
+
int i, c;
|
51
|
+
libnet_ptag_t t;
|
52
|
+
char *payload = NULL;
|
53
|
+
u_short payload_s = 0;
|
54
|
+
|
55
|
+
char *device = NULL;
|
56
|
+
char *pDst = NULL, *pSrc = NULL;
|
57
|
+
char errbuf[LIBNET_ERRBUF_SIZE];
|
58
|
+
char label[LIBNET_LABEL_SIZE];
|
59
|
+
|
60
|
+
printf("libnet 1.1 packet shaping: ICMP[RAW using context queue]\n");
|
61
|
+
|
62
|
+
while((c = getopt(argc, argv, "d:s:i:c:p:")) != EOF)
|
63
|
+
{
|
64
|
+
switch (c)
|
65
|
+
{
|
66
|
+
case 'd':
|
67
|
+
pDst = optarg;
|
68
|
+
break;
|
69
|
+
case 's':
|
70
|
+
pSrc = optarg;
|
71
|
+
break;
|
72
|
+
case 'i':
|
73
|
+
device = optarg;
|
74
|
+
break;
|
75
|
+
case 'c':
|
76
|
+
count = strtoul(optarg, 0, 10);
|
77
|
+
break;
|
78
|
+
case 'p':
|
79
|
+
payload = optarg;
|
80
|
+
payload_s = strlen(payload);
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
if (!pSrc || !pDst)
|
86
|
+
{
|
87
|
+
usage(argv[0]);
|
88
|
+
exit(EXIT_FAILURE);
|
89
|
+
}
|
90
|
+
|
91
|
+
/*
|
92
|
+
* Fill the context queue with "count" packets, each with their own
|
93
|
+
* context.
|
94
|
+
*/
|
95
|
+
for (i = 0; i < count; i++)
|
96
|
+
{
|
97
|
+
l = libnet_init(
|
98
|
+
LIBNET_RAW4, /* injection type */
|
99
|
+
device, /* network interface */
|
100
|
+
errbuf); /* errbuf */
|
101
|
+
|
102
|
+
if (l == NULL)
|
103
|
+
{
|
104
|
+
/* we should run through the queue and free any stragglers */
|
105
|
+
fprintf(stderr, "libnet_init() failed: %s", errbuf);
|
106
|
+
exit(EXIT_FAILURE);
|
107
|
+
}
|
108
|
+
/*
|
109
|
+
* Since we need a libnet context for address resolution it is
|
110
|
+
* necessary to put this inside the loop.
|
111
|
+
*/
|
112
|
+
if (!dst_ip && (dst_ip = libnet_name2addr4(l, pDst,
|
113
|
+
LIBNET_RESOLVE)) == -1)
|
114
|
+
{
|
115
|
+
fprintf(stderr, "Bad destination IP address: %s\n", pDst);
|
116
|
+
exit(1);
|
117
|
+
}
|
118
|
+
if (!src_ip && (src_ip = libnet_name2addr4(l, pSrc,
|
119
|
+
LIBNET_RESOLVE)) == -1)
|
120
|
+
{
|
121
|
+
fprintf(stderr, "Bad source IP address: %s\n", pSrc);
|
122
|
+
exit(1);
|
123
|
+
}
|
124
|
+
|
125
|
+
t = libnet_build_icmpv4_echo(
|
126
|
+
ICMP_ECHO, /* type */
|
127
|
+
0, /* code */
|
128
|
+
0, /* checksum */
|
129
|
+
0x42, /* id */
|
130
|
+
0x42, /* sequence number */
|
131
|
+
NULL, /* payload */
|
132
|
+
0, /* payload size */
|
133
|
+
l, /* libnet handle */
|
134
|
+
0);
|
135
|
+
if (t == -1)
|
136
|
+
{
|
137
|
+
fprintf(stderr, "Can't build ICMP header: %s\n",
|
138
|
+
libnet_geterror(l));
|
139
|
+
goto bad;
|
140
|
+
}
|
141
|
+
|
142
|
+
t = libnet_build_ipv4(
|
143
|
+
LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H + payload_s, /* length */
|
144
|
+
0, /* TOS */
|
145
|
+
0x42, /* IP ID */
|
146
|
+
0, /* IP Frag */
|
147
|
+
64, /* TTL */
|
148
|
+
IPPROTO_ICMP, /* protocol */
|
149
|
+
0, /* checksum */
|
150
|
+
src_ip, /* source IP */
|
151
|
+
dst_ip, /* destination IP */
|
152
|
+
payload, /* payload */
|
153
|
+
payload_s, /* payload size */
|
154
|
+
l, /* libnet handle */
|
155
|
+
0);
|
156
|
+
if (t == -1)
|
157
|
+
{
|
158
|
+
fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
|
159
|
+
goto bad;
|
160
|
+
}
|
161
|
+
|
162
|
+
/* and finally, put it in the context queue */
|
163
|
+
snprintf(label, sizeof(label)-1, "echo %d", i);
|
164
|
+
if (libnet_cq_add(l, label) == -1)
|
165
|
+
{
|
166
|
+
fprintf(stderr, "add error: %s\n", libnet_geterror(l));
|
167
|
+
goto bad;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
for_each_context_in_cq(l)
|
172
|
+
{
|
173
|
+
c = libnet_write(l);
|
174
|
+
if (c == -1)
|
175
|
+
{
|
176
|
+
fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
|
177
|
+
goto bad;
|
178
|
+
}
|
179
|
+
else
|
180
|
+
{
|
181
|
+
fprintf(stderr, "Wrote %d byte ICMP packet from context \"%s\"; "
|
182
|
+
"check the wire.\n", c, libnet_cq_getlabel(l));
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
libnet_cq_destroy();
|
187
|
+
return (EXIT_SUCCESS);
|
188
|
+
bad:
|
189
|
+
libnet_cq_destroy();
|
190
|
+
libnet_destroy(l);
|
191
|
+
return (EXIT_FAILURE);
|
192
|
+
}
|
193
|
+
|
194
|
+
void
|
195
|
+
usage(char *name)
|
196
|
+
{
|
197
|
+
fprintf(stderr, "usage: %s -s source_ip -d destination_ip"
|
198
|
+
" [-i iface] [-c count = 10]\n ", name);
|
199
|
+
}
|
200
|
+
|
201
|
+
/* EOF */
|
@@ -0,0 +1,200 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: icmp_redirect.c,v 1.3 2004/03/16 18:40:58 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet 1.1
|
5
|
+
* Build an ICMP redirect packet
|
6
|
+
*
|
7
|
+
* Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
|
8
|
+
* Copyright (c) 2003 Alberto Ornaghi <alor@antifork.org>
|
9
|
+
* All rights reserved.
|
10
|
+
*
|
11
|
+
* Redistribution and use in source and binary forms, with or without
|
12
|
+
* modification, are permitted provided that the following conditions
|
13
|
+
* are met:
|
14
|
+
* 1. Redistributions of source code must retain the above copyright
|
15
|
+
* notice, this list of conditions and the following disclaimer.
|
16
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
17
|
+
* notice, this list of conditions and the following disclaimer in the
|
18
|
+
* documentation and/or other materials provided with the distribution.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
21
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
24
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
26
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
28
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
29
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
30
|
+
* SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#if (HAVE_CONFIG_H)
|
35
|
+
#include "../include/config.h"
|
36
|
+
#endif
|
37
|
+
#include "./libnet_test.h"
|
38
|
+
|
39
|
+
int
|
40
|
+
main(int argc, char **argv)
|
41
|
+
{
|
42
|
+
int c;
|
43
|
+
libnet_t *l;
|
44
|
+
libnet_ptag_t t;
|
45
|
+
u_long src_ip, dst_ip, gw_ip;
|
46
|
+
u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
|
47
|
+
u_long payload_s = 8;
|
48
|
+
char errbuf[LIBNET_ERRBUF_SIZE];
|
49
|
+
|
50
|
+
printf("libnet 1.1 packet shaping: ICMP redirect[link]\n");
|
51
|
+
|
52
|
+
/*
|
53
|
+
* Initialize the library. Root priviledges are required.
|
54
|
+
*/
|
55
|
+
l = libnet_init(
|
56
|
+
LIBNET_LINK, /* injection type */
|
57
|
+
NULL, /* network interface */
|
58
|
+
errbuf); /* errbuf */
|
59
|
+
|
60
|
+
if (l == NULL)
|
61
|
+
{
|
62
|
+
fprintf(stderr, "libnet_init() failed: %s", errbuf);
|
63
|
+
exit(EXIT_FAILURE);
|
64
|
+
}
|
65
|
+
|
66
|
+
src_ip = 0;
|
67
|
+
dst_ip = 0;
|
68
|
+
gw_ip = 0;
|
69
|
+
while((c = getopt(argc, argv, "d:s:g:")) != EOF)
|
70
|
+
{
|
71
|
+
switch (c)
|
72
|
+
{
|
73
|
+
case 'd':
|
74
|
+
if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
|
75
|
+
{
|
76
|
+
fprintf(stderr, "Bad destination IP address: %s\n", optarg);
|
77
|
+
exit(1);
|
78
|
+
}
|
79
|
+
break;
|
80
|
+
case 's':
|
81
|
+
if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
|
82
|
+
{
|
83
|
+
fprintf(stderr, "Bad source IP address: %s\n", optarg);
|
84
|
+
exit(1);
|
85
|
+
}
|
86
|
+
break;
|
87
|
+
case 'g':
|
88
|
+
if ((gw_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
|
89
|
+
{
|
90
|
+
fprintf(stderr, "Bad gateway IP address: %s\n", optarg);
|
91
|
+
exit(1);
|
92
|
+
}
|
93
|
+
break;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
if (!src_ip || !dst_ip || !gw_ip)
|
97
|
+
{
|
98
|
+
usage(argv[0]);
|
99
|
+
exit(EXIT_FAILURE);
|
100
|
+
}
|
101
|
+
|
102
|
+
t = libnet_build_ipv4(
|
103
|
+
LIBNET_IPV4_H + payload_s, /* length */
|
104
|
+
IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
|
105
|
+
0x42, /* IP ID */
|
106
|
+
0, /* IP Frag */
|
107
|
+
64, /* TTL */
|
108
|
+
IPPROTO_ICMP, /* protocol */
|
109
|
+
0, /* checksum */
|
110
|
+
dst_ip, /* source IP */
|
111
|
+
src_ip, /* destination IP */
|
112
|
+
payload, /* payload */
|
113
|
+
payload_s, /* payload size */
|
114
|
+
l, /* libnet handle */
|
115
|
+
0);
|
116
|
+
if (t == -1)
|
117
|
+
{
|
118
|
+
fprintf(stderr, "Can't build error IP header: %s\n",
|
119
|
+
libnet_geterror(l));
|
120
|
+
goto bad;
|
121
|
+
}
|
122
|
+
|
123
|
+
t = libnet_build_icmpv4_redirect(
|
124
|
+
ICMP_REDIRECT, /* type */
|
125
|
+
ICMP_REDIRECT_HOST, /* code */
|
126
|
+
0, /* checksum */
|
127
|
+
gw_ip,
|
128
|
+
NULL,
|
129
|
+
0,
|
130
|
+
l, /* libnet handle */
|
131
|
+
0); /* libnet id */
|
132
|
+
if (t == -1)
|
133
|
+
{
|
134
|
+
fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
|
135
|
+
goto bad;
|
136
|
+
}
|
137
|
+
|
138
|
+
t = libnet_build_ipv4(
|
139
|
+
LIBNET_IPV4_H + LIBNET_ICMPV4_REDIRECT_H +
|
140
|
+
LIBNET_IPV4_H + payload_s, /* length */
|
141
|
+
IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
|
142
|
+
0xee, /* IP ID */
|
143
|
+
0, /* IP Frag */
|
144
|
+
64, /* TTL */
|
145
|
+
IPPROTO_ICMP, /* protocol */
|
146
|
+
0, /* checksum */
|
147
|
+
src_ip, /* source IP */
|
148
|
+
dst_ip, /* destination IP */
|
149
|
+
NULL, /* payload */
|
150
|
+
0, /* payload size */
|
151
|
+
l, /* libnet handle */
|
152
|
+
0);
|
153
|
+
if (t == -1)
|
154
|
+
{
|
155
|
+
fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
|
156
|
+
goto bad;
|
157
|
+
}
|
158
|
+
|
159
|
+
t = libnet_build_ethernet(
|
160
|
+
enet_dst, /* ethernet destination */
|
161
|
+
enet_src, /* ethernet source */
|
162
|
+
ETHERTYPE_IP, /* protocol type */
|
163
|
+
NULL, /* payload */
|
164
|
+
0, /* payload size */
|
165
|
+
l, /* libnet handle */
|
166
|
+
0); /* libnet id */
|
167
|
+
if (t == -1)
|
168
|
+
{
|
169
|
+
fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
|
170
|
+
goto bad;
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
* Write it to the wire.
|
175
|
+
*/
|
176
|
+
c = libnet_write(l);
|
177
|
+
if (c == -1)
|
178
|
+
{
|
179
|
+
fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
|
180
|
+
goto bad;
|
181
|
+
}
|
182
|
+
else
|
183
|
+
{
|
184
|
+
fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
|
185
|
+
}
|
186
|
+
libnet_destroy(l);
|
187
|
+
return (EXIT_SUCCESS);
|
188
|
+
bad:
|
189
|
+
libnet_destroy(l);
|
190
|
+
return (EXIT_FAILURE);
|
191
|
+
}
|
192
|
+
|
193
|
+
|
194
|
+
void
|
195
|
+
usage(char *name)
|
196
|
+
{
|
197
|
+
fprintf(stderr, "usage: %s -s source_ip -d destination_ip -g gateway_ip\n ", name);
|
198
|
+
}
|
199
|
+
|
200
|
+
/* EOF */
|
@@ -0,0 +1,190 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: icmp_timeexceed.c,v 1.3 2004/03/16 18:40:58 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet 1.1
|
5
|
+
* Build an ICMP timeexceed packet
|
6
|
+
*
|
7
|
+
* Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
|
8
|
+
* Copyright (c) 2003 Fr�d�ric Raynal <pappy@security-labs.org>
|
9
|
+
* All rights reserved.
|
10
|
+
*
|
11
|
+
* Redistribution and use in source and binary forms, with or without
|
12
|
+
* modification, are permitted provided that the following conditions
|
13
|
+
* are met:
|
14
|
+
* 1. Redistributions of source code must retain the above copyright
|
15
|
+
* notice, this list of conditions and the following disclaimer.
|
16
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
17
|
+
* notice, this list of conditions and the following disclaimer in the
|
18
|
+
* documentation and/or other materials provided with the distribution.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
21
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
24
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
25
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
26
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
27
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
28
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
29
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
30
|
+
* SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#if (HAVE_CONFIG_H)
|
35
|
+
#include "../include/config.h"
|
36
|
+
#endif
|
37
|
+
#include "./libnet_test.h"
|
38
|
+
|
39
|
+
int
|
40
|
+
main(int argc, char **argv)
|
41
|
+
{
|
42
|
+
int c;
|
43
|
+
libnet_t *l;
|
44
|
+
libnet_ptag_t t;
|
45
|
+
u_long src_ip, dst_ip;
|
46
|
+
u_char payload[8] = {0x11, 0x11, 0x22, 0x22, 0x00, 0x08, 0xc6, 0xa5};
|
47
|
+
u_long payload_s = 8;
|
48
|
+
char errbuf[LIBNET_ERRBUF_SIZE];
|
49
|
+
|
50
|
+
printf("libnet 1.1 packet shaping: ICMP timeexceed[link]\n");
|
51
|
+
|
52
|
+
/*
|
53
|
+
* Initialize the library. Root priviledges are required.
|
54
|
+
*/
|
55
|
+
l = libnet_init(
|
56
|
+
LIBNET_LINK, /* injection type */
|
57
|
+
NULL, /* network interface */
|
58
|
+
errbuf); /* errbuf */
|
59
|
+
|
60
|
+
if (l == NULL)
|
61
|
+
{
|
62
|
+
fprintf(stderr, "libnet_init() failed: %s", errbuf);
|
63
|
+
exit(EXIT_FAILURE);
|
64
|
+
}
|
65
|
+
|
66
|
+
src_ip = 0;
|
67
|
+
dst_ip = 0;
|
68
|
+
while((c = getopt(argc, argv, "d:s:")) != EOF)
|
69
|
+
{
|
70
|
+
switch (c)
|
71
|
+
{
|
72
|
+
case 'd':
|
73
|
+
if ((dst_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
|
74
|
+
{
|
75
|
+
fprintf(stderr, "Bad destination IP address: %s\n", optarg);
|
76
|
+
exit(1);
|
77
|
+
}
|
78
|
+
break;
|
79
|
+
case 's':
|
80
|
+
if ((src_ip = libnet_name2addr4(l, optarg, LIBNET_RESOLVE)) == -1)
|
81
|
+
{
|
82
|
+
fprintf(stderr, "Bad source IP address: %s\n", optarg);
|
83
|
+
exit(1);
|
84
|
+
}
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
if (!src_ip || !dst_ip)
|
89
|
+
{
|
90
|
+
usage(argv[0]);
|
91
|
+
exit(EXIT_FAILURE);
|
92
|
+
}
|
93
|
+
t = libnet_build_ipv4(
|
94
|
+
LIBNET_IPV4_H + payload_s, /* length */
|
95
|
+
IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
|
96
|
+
0xee, /* IP ID */
|
97
|
+
0, /* IP Frag */
|
98
|
+
64, /* TTL */
|
99
|
+
IPPROTO_UDP, /* protocol */
|
100
|
+
0, /* checksum */
|
101
|
+
dst_ip, /* source IP */
|
102
|
+
src_ip, /* destination IP */
|
103
|
+
payload, /* payload */
|
104
|
+
payload_s, /* payload size */
|
105
|
+
l, /* libnet handle */
|
106
|
+
0);
|
107
|
+
if (t == -1)
|
108
|
+
{
|
109
|
+
fprintf(stderr, "Can't build error IP header: %s\n",
|
110
|
+
libnet_geterror(l));
|
111
|
+
goto bad;
|
112
|
+
}
|
113
|
+
|
114
|
+
t = libnet_build_icmpv4_timeexceed(
|
115
|
+
ICMP_TIMXCEED, /* type */
|
116
|
+
ICMP_TIMXCEED_INTRANS, /* code */
|
117
|
+
0, /* checksum */
|
118
|
+
NULL,
|
119
|
+
0,
|
120
|
+
l, /* libnet handle */
|
121
|
+
0);
|
122
|
+
if (t == -1)
|
123
|
+
{
|
124
|
+
fprintf(stderr, "Can't build ICMP header: %s\n", libnet_geterror(l));
|
125
|
+
goto bad;
|
126
|
+
}
|
127
|
+
|
128
|
+
t = libnet_build_ipv4(
|
129
|
+
LIBNET_IPV4_H + LIBNET_ICMPV4_TIMXCEED_H +
|
130
|
+
LIBNET_IPV4_H + payload_s, /* length */
|
131
|
+
IPTOS_LOWDELAY | IPTOS_THROUGHPUT, /* TOS */
|
132
|
+
0xee, /* IP ID */
|
133
|
+
0, /* IP Frag */
|
134
|
+
64, /* TTL */
|
135
|
+
IPPROTO_ICMP, /* protocol */
|
136
|
+
0, /* checksum */
|
137
|
+
src_ip, /* source IP */
|
138
|
+
dst_ip, /* destination IP */
|
139
|
+
NULL, /* payload */
|
140
|
+
0, /* payload size */
|
141
|
+
l, /* libnet handle */
|
142
|
+
0);
|
143
|
+
if (t == -1)
|
144
|
+
{
|
145
|
+
fprintf(stderr, "Can't build IP header: %s\n", libnet_geterror(l));
|
146
|
+
goto bad;
|
147
|
+
}
|
148
|
+
|
149
|
+
t = libnet_build_ethernet(
|
150
|
+
enet_dst, /* ethernet destination */
|
151
|
+
enet_src, /* ethernet source */
|
152
|
+
ETHERTYPE_IP, /* protocol type */
|
153
|
+
NULL, /* payload */
|
154
|
+
0, /* payload size */
|
155
|
+
l, /* libnet handle */
|
156
|
+
0); /* libnet id */
|
157
|
+
if (t == -1)
|
158
|
+
{
|
159
|
+
fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
|
160
|
+
goto bad;
|
161
|
+
}
|
162
|
+
|
163
|
+
/*
|
164
|
+
* Write it to the wire.
|
165
|
+
*/
|
166
|
+
c = libnet_write(l);
|
167
|
+
if (c == -1)
|
168
|
+
{
|
169
|
+
fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
|
170
|
+
goto bad;
|
171
|
+
}
|
172
|
+
else
|
173
|
+
{
|
174
|
+
fprintf(stderr, "Wrote %d byte ICMP packet; check the wire.\n", c);
|
175
|
+
}
|
176
|
+
libnet_destroy(l);
|
177
|
+
return (EXIT_SUCCESS);
|
178
|
+
bad:
|
179
|
+
libnet_destroy(l);
|
180
|
+
return (EXIT_FAILURE);
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
void
|
185
|
+
usage(char *name)
|
186
|
+
{
|
187
|
+
fprintf(stderr, "usage: %s -s source_ip -d destination_ip\n ", name);
|
188
|
+
}
|
189
|
+
|
190
|
+
/* EOF */
|