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,892 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_build_ip.c,v 1.18 2004/03/16 18:40:59 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet
|
5
|
+
* libnet_build_ip.c - IP packet assembler
|
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
|
+
#if (!(_WIN32) || (__CYGWIN__))
|
37
|
+
#include "../include/libnet.h"
|
38
|
+
#else
|
39
|
+
#include "../include/win32/libnet.h"
|
40
|
+
#endif
|
41
|
+
|
42
|
+
|
43
|
+
libnet_ptag_t
|
44
|
+
libnet_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag,
|
45
|
+
u_int8_t ttl, u_int8_t prot, u_int16_t sum, u_int32_t src, u_int32_t dst,
|
46
|
+
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
|
47
|
+
{
|
48
|
+
int offset;
|
49
|
+
u_int32_t h, n, i, j;
|
50
|
+
libnet_pblock_t *p, *p_data, *p_temp;
|
51
|
+
struct libnet_ipv4_hdr ip_hdr;
|
52
|
+
libnet_ptag_t ptag_data, ptag_hold;
|
53
|
+
|
54
|
+
if (l == NULL)
|
55
|
+
{
|
56
|
+
return (-1);
|
57
|
+
}
|
58
|
+
|
59
|
+
n = LIBNET_IPV4_H; /* size of memory block */
|
60
|
+
h = len; /* header length */
|
61
|
+
ptag_data = 0; /* used if options are present */
|
62
|
+
|
63
|
+
if (h + payload_s > IP_MAXPACKET)
|
64
|
+
{
|
65
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
66
|
+
"%s(): IP packet too large\n", __func__);
|
67
|
+
return (-1);
|
68
|
+
}
|
69
|
+
|
70
|
+
/*
|
71
|
+
* Find the existing protocol block if a ptag is specified, or create
|
72
|
+
* a new one.
|
73
|
+
*/
|
74
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV4_H);
|
75
|
+
if (p == NULL)
|
76
|
+
{
|
77
|
+
return (-1);
|
78
|
+
}
|
79
|
+
|
80
|
+
memset(&ip_hdr, 0, sizeof(ip_hdr));
|
81
|
+
ip_hdr.ip_v = 4; /* version 4 */
|
82
|
+
ip_hdr.ip_hl = 5; /* 20 byte header */
|
83
|
+
|
84
|
+
/* check to see if there are IP options to include */
|
85
|
+
if (p->prev)
|
86
|
+
{
|
87
|
+
if (p->prev->type == LIBNET_PBLOCK_IPO_H)
|
88
|
+
{
|
89
|
+
/*
|
90
|
+
* Count up number of 32-bit words in options list, padding if
|
91
|
+
* neccessary.
|
92
|
+
*/
|
93
|
+
for (i = 0, j = 0; i < p->prev->b_len; i++)
|
94
|
+
{
|
95
|
+
(i % 4) ? j : j++;
|
96
|
+
}
|
97
|
+
ip_hdr.ip_hl += j;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
ip_hdr.ip_tos = tos; /* IP tos */
|
102
|
+
ip_hdr.ip_len = htons(h); /* total length */
|
103
|
+
ip_hdr.ip_id = htons(id); /* IP ID */
|
104
|
+
ip_hdr.ip_off = htons(frag); /* fragmentation flags */
|
105
|
+
ip_hdr.ip_ttl = ttl; /* time to live */
|
106
|
+
ip_hdr.ip_p = prot; /* transport protocol */
|
107
|
+
ip_hdr.ip_sum = (sum ? htons(sum) : 0); /* checksum */
|
108
|
+
ip_hdr.ip_src.s_addr = src; /* source ip */
|
109
|
+
ip_hdr.ip_dst.s_addr = dst; /* destination ip */
|
110
|
+
|
111
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV4_H);
|
112
|
+
if (n == -1)
|
113
|
+
{
|
114
|
+
goto bad;
|
115
|
+
}
|
116
|
+
|
117
|
+
/* save the original ptag value */
|
118
|
+
ptag_hold = ptag;
|
119
|
+
|
120
|
+
if (ptag == LIBNET_PTAG_INITIALIZER)
|
121
|
+
{
|
122
|
+
ptag = libnet_pblock_update(l, p, LIBNET_IPV4_H, LIBNET_PBLOCK_IPV4_H);
|
123
|
+
}
|
124
|
+
|
125
|
+
/* find and set the appropriate ptag, or else use the default of 0 */
|
126
|
+
offset = payload_s;
|
127
|
+
if (ptag_hold && p->prev)
|
128
|
+
{
|
129
|
+
p_temp = p->prev;
|
130
|
+
while (p_temp->prev &&
|
131
|
+
(p_temp->type != LIBNET_PBLOCK_IPDATA) &&
|
132
|
+
(p_temp->type != LIBNET_PBLOCK_IPV4_H))
|
133
|
+
{
|
134
|
+
p_temp = p_temp->prev;
|
135
|
+
}
|
136
|
+
|
137
|
+
if (p_temp->type == LIBNET_PBLOCK_IPDATA)
|
138
|
+
{
|
139
|
+
ptag_data = p_temp->ptag;
|
140
|
+
offset -= p_temp->b_len;
|
141
|
+
p->h_len += offset;
|
142
|
+
}
|
143
|
+
else
|
144
|
+
{
|
145
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
146
|
+
"%s(): IPv4 data pblock not found\n", __func__);
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
151
|
+
{
|
152
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
153
|
+
"%s(): payload inconsistency\n", __func__);
|
154
|
+
goto bad;
|
155
|
+
}
|
156
|
+
|
157
|
+
if (payload && payload_s)
|
158
|
+
{
|
159
|
+
/* update ptag_data with the new payload */
|
160
|
+
p_data = libnet_pblock_probe(l, ptag_data, payload_s,
|
161
|
+
LIBNET_PBLOCK_IPDATA);
|
162
|
+
if (p_data == NULL)
|
163
|
+
{
|
164
|
+
return (-1);
|
165
|
+
}
|
166
|
+
|
167
|
+
if (libnet_pblock_append(l, p_data, payload, payload_s) == -1)
|
168
|
+
{
|
169
|
+
goto bad;
|
170
|
+
}
|
171
|
+
|
172
|
+
if (ptag_data == LIBNET_PTAG_INITIALIZER)
|
173
|
+
{
|
174
|
+
if (p_data->prev->type == LIBNET_PBLOCK_IPV4_H)
|
175
|
+
{
|
176
|
+
libnet_pblock_update(l, p_data, payload_s,
|
177
|
+
LIBNET_PBLOCK_IPDATA);
|
178
|
+
/* swap pblocks to correct the protocol order */
|
179
|
+
libnet_pblock_swap(l, p->ptag, p_data->ptag);
|
180
|
+
}
|
181
|
+
else
|
182
|
+
{
|
183
|
+
/* update without setting this as the final pblock */
|
184
|
+
p_data->type = LIBNET_PBLOCK_IPDATA;
|
185
|
+
p_data->ptag = ++(l->ptag_state);
|
186
|
+
p_data->h_len = payload_s;
|
187
|
+
|
188
|
+
/* Adjust h_len for checksum. */
|
189
|
+
p->h_len += payload_s;
|
190
|
+
|
191
|
+
/* data was added after the initial construction */
|
192
|
+
for (p_temp = l->protocol_blocks;
|
193
|
+
p_temp->type == LIBNET_PBLOCK_IPV4_H ||
|
194
|
+
p_temp->type == LIBNET_PBLOCK_IPO_H;
|
195
|
+
p_temp = p_temp->next)
|
196
|
+
{
|
197
|
+
libnet_pblock_insert_before(l, p_temp->ptag, p_data->ptag);
|
198
|
+
break;
|
199
|
+
}
|
200
|
+
|
201
|
+
/* the end block needs to have its next pointer cleared */
|
202
|
+
l->pblock_end->next = NULL;
|
203
|
+
}
|
204
|
+
|
205
|
+
if (p_data->prev && p_data->prev->type == LIBNET_PBLOCK_IPO_H)
|
206
|
+
{
|
207
|
+
libnet_pblock_swap(l, p_data->prev->ptag, p_data->ptag);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
else
|
212
|
+
{
|
213
|
+
p_data = libnet_pblock_find(l, ptag_data);
|
214
|
+
if (p_data)
|
215
|
+
{
|
216
|
+
libnet_pblock_delete(l, p_data);
|
217
|
+
}
|
218
|
+
else
|
219
|
+
{
|
220
|
+
/*
|
221
|
+
* XXX - When this completes successfully, libnet errbuf contains
|
222
|
+
* an error message so to come correct, we'll clear it.
|
223
|
+
*/
|
224
|
+
memset(l->err_buf, 0, sizeof (l->err_buf));
|
225
|
+
}
|
226
|
+
}
|
227
|
+
if (sum == 0)
|
228
|
+
{
|
229
|
+
/*
|
230
|
+
* If checksum is zero, by default libnet will compute a checksum
|
231
|
+
* for the user. The programmer can override this by calling
|
232
|
+
* libnet_toggle_checksum(l, ptag, 1);
|
233
|
+
*/
|
234
|
+
libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
|
235
|
+
}
|
236
|
+
|
237
|
+
/*
|
238
|
+
* FREDRAYNAL: as we insert a new IP header, all checksums for headers
|
239
|
+
* placed after this one will refer to here.
|
240
|
+
*/
|
241
|
+
libnet_pblock_record_ip_offset(l, l->total_size);
|
242
|
+
|
243
|
+
return (ptag);
|
244
|
+
bad:
|
245
|
+
libnet_pblock_delete(l, p);
|
246
|
+
return (-1);
|
247
|
+
}
|
248
|
+
|
249
|
+
libnet_ptag_t
|
250
|
+
libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_int32_t dst, libnet_t *l)
|
251
|
+
{
|
252
|
+
u_int32_t n, i, j, src;
|
253
|
+
u_int16_t h;
|
254
|
+
libnet_pblock_t *p;
|
255
|
+
libnet_ptag_t ptag;
|
256
|
+
struct libnet_ipv4_hdr ip_hdr;
|
257
|
+
|
258
|
+
if (l == NULL)
|
259
|
+
{
|
260
|
+
return (-1);
|
261
|
+
}
|
262
|
+
|
263
|
+
n = LIBNET_IPV4_H; /* size of memory block */
|
264
|
+
h = len; /* header length */
|
265
|
+
ptag = LIBNET_PTAG_INITIALIZER;
|
266
|
+
src = libnet_get_ipaddr4(l);
|
267
|
+
if (src == -1)
|
268
|
+
{
|
269
|
+
/* err msg set in libnet_get_ipaddr() */
|
270
|
+
return (-1);
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
* Create a new pblock.
|
275
|
+
*/
|
276
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV4_H);
|
277
|
+
if (p == NULL)
|
278
|
+
{
|
279
|
+
return (-1);
|
280
|
+
}
|
281
|
+
|
282
|
+
memset(&ip_hdr, 0, sizeof(ip_hdr));
|
283
|
+
ip_hdr.ip_v = 4; /* version 4 */
|
284
|
+
ip_hdr.ip_hl = 5; /* 20 byte header */
|
285
|
+
|
286
|
+
/* check to see if there are IP options to include */
|
287
|
+
if (p->prev)
|
288
|
+
{
|
289
|
+
if (p->prev->type == LIBNET_PBLOCK_IPO_H)
|
290
|
+
{
|
291
|
+
/*
|
292
|
+
* Count up number of 32-bit words in options list, padding if
|
293
|
+
* neccessary.
|
294
|
+
*/
|
295
|
+
for (i = 0, j = 0; i < p->prev->b_len; i++)
|
296
|
+
{
|
297
|
+
(i % 4) ? j : j++;
|
298
|
+
}
|
299
|
+
ip_hdr.ip_hl += j;
|
300
|
+
}
|
301
|
+
}
|
302
|
+
|
303
|
+
ip_hdr.ip_tos = 0; /* IP tos */
|
304
|
+
ip_hdr.ip_len = htons(h); /* total length */
|
305
|
+
ip_hdr.ip_id = htons((l->ptag_state) & 0x0000ffff); /* IP ID */
|
306
|
+
ip_hdr.ip_off = 0; /* fragmentation flags */
|
307
|
+
ip_hdr.ip_ttl = 64; /* time to live */
|
308
|
+
ip_hdr.ip_p = prot; /* transport protocol */
|
309
|
+
ip_hdr.ip_sum = 0; /* checksum */
|
310
|
+
ip_hdr.ip_src.s_addr = src; /* source ip */
|
311
|
+
ip_hdr.ip_dst.s_addr = dst; /* destination ip */
|
312
|
+
|
313
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV4_H);
|
314
|
+
if (n == -1)
|
315
|
+
{
|
316
|
+
goto bad;
|
317
|
+
}
|
318
|
+
|
319
|
+
libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
|
320
|
+
ptag = libnet_pblock_update(l, p, LIBNET_IPV4_H, LIBNET_PBLOCK_IPV4_H);
|
321
|
+
|
322
|
+
/*
|
323
|
+
* FREDRAYNAL: as we insert a new IP header, all checksums for headers
|
324
|
+
* placed after this one will refer to here.
|
325
|
+
*/
|
326
|
+
libnet_pblock_record_ip_offset(l, l->total_size);
|
327
|
+
return (ptag);
|
328
|
+
|
329
|
+
bad:
|
330
|
+
libnet_pblock_delete(l, p);
|
331
|
+
return (-1);
|
332
|
+
}
|
333
|
+
|
334
|
+
libnet_ptag_t
|
335
|
+
libnet_build_ipv4_options(u_int8_t *options, u_int32_t options_s, libnet_t *l,
|
336
|
+
libnet_ptag_t ptag)
|
337
|
+
{
|
338
|
+
int offset, underflow;
|
339
|
+
u_int32_t i, j, n, adj_size;
|
340
|
+
libnet_pblock_t *p, *p_temp;
|
341
|
+
struct libnet_ipv4_hdr *ip_hdr;
|
342
|
+
|
343
|
+
if (l == NULL)
|
344
|
+
{
|
345
|
+
return (-1);
|
346
|
+
}
|
347
|
+
|
348
|
+
underflow = 0;
|
349
|
+
offset = 0;
|
350
|
+
|
351
|
+
/* check options list size */
|
352
|
+
if (options_s > LIBNET_MAXOPTION_SIZE)
|
353
|
+
{
|
354
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
355
|
+
"%s(): options list is too large %d\n", __func__, options_s);
|
356
|
+
return (-1);
|
357
|
+
}
|
358
|
+
|
359
|
+
adj_size = options_s;
|
360
|
+
if (adj_size % 4)
|
361
|
+
{
|
362
|
+
/* size of memory block with padding */
|
363
|
+
adj_size += 4 - (options_s % 4);
|
364
|
+
}
|
365
|
+
|
366
|
+
/* if this pblock already exists, determine if there is a size diff */
|
367
|
+
if (ptag)
|
368
|
+
{
|
369
|
+
p_temp = libnet_pblock_find(l, ptag);
|
370
|
+
if (p_temp)
|
371
|
+
{
|
372
|
+
if (adj_size >= p_temp->b_len)
|
373
|
+
{
|
374
|
+
offset = adj_size - p_temp->b_len;
|
375
|
+
}
|
376
|
+
else
|
377
|
+
{
|
378
|
+
offset = p_temp->b_len - adj_size;
|
379
|
+
underflow = 1;
|
380
|
+
}
|
381
|
+
}
|
382
|
+
else
|
383
|
+
{
|
384
|
+
/*
|
385
|
+
* XXX - When this completes successfully, libnet errbuf contains
|
386
|
+
* an error message so to come correct, we'll clear it.
|
387
|
+
*/
|
388
|
+
memset(l->err_buf, 0, sizeof (l->err_buf));
|
389
|
+
}
|
390
|
+
}
|
391
|
+
|
392
|
+
/*
|
393
|
+
* Find the existing protocol block if a ptag is specified, or create
|
394
|
+
* a new one.
|
395
|
+
*/
|
396
|
+
p = libnet_pblock_probe(l, ptag, adj_size, LIBNET_PBLOCK_IPO_H);
|
397
|
+
if (p == NULL)
|
398
|
+
{
|
399
|
+
return (-1);
|
400
|
+
}
|
401
|
+
|
402
|
+
/* append options */
|
403
|
+
n = libnet_pblock_append(l, p, options, options_s);
|
404
|
+
if (n == -1)
|
405
|
+
{
|
406
|
+
goto bad;
|
407
|
+
}
|
408
|
+
|
409
|
+
/* append padding */
|
410
|
+
n = libnet_pblock_append(l, p, "\0\0\0", adj_size - options_s);
|
411
|
+
if (n == -1)
|
412
|
+
{
|
413
|
+
goto bad;
|
414
|
+
}
|
415
|
+
|
416
|
+
if (ptag && p->next)
|
417
|
+
{
|
418
|
+
p_temp = p->next;
|
419
|
+
while ((p_temp->next) && (p_temp->type != LIBNET_PBLOCK_IPV4_H))
|
420
|
+
{
|
421
|
+
p_temp = p_temp->next;
|
422
|
+
}
|
423
|
+
|
424
|
+
/* fix the IP header size */
|
425
|
+
if (p_temp->type == LIBNET_PBLOCK_IPV4_H)
|
426
|
+
{
|
427
|
+
/*
|
428
|
+
* Count up number of 32-bit words in options list, padding if
|
429
|
+
* neccessary.
|
430
|
+
*/
|
431
|
+
for (i = 0, j = 0; i < p->b_len; i++)
|
432
|
+
{
|
433
|
+
(i % 4) ? j : j++;
|
434
|
+
}
|
435
|
+
ip_hdr = (struct libnet_ipv4_hdr *) p_temp->buf;
|
436
|
+
ip_hdr->ip_hl = j + 5;
|
437
|
+
|
438
|
+
if (!underflow)
|
439
|
+
{
|
440
|
+
p_temp->h_len += offset;
|
441
|
+
}
|
442
|
+
else
|
443
|
+
{
|
444
|
+
p_temp->h_len -= offset;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, adj_size,
|
450
|
+
LIBNET_PBLOCK_IPO_H));
|
451
|
+
bad:
|
452
|
+
libnet_pblock_delete(l, p);
|
453
|
+
return (-1);
|
454
|
+
}
|
455
|
+
|
456
|
+
libnet_ptag_t
|
457
|
+
libnet_build_ipv6(u_int8_t tc, u_int32_t fl, u_int16_t len, u_int8_t nh,
|
458
|
+
u_int8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst,
|
459
|
+
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
|
460
|
+
{
|
461
|
+
u_int32_t n;
|
462
|
+
libnet_pblock_t *p;
|
463
|
+
struct libnet_ipv6_hdr ip_hdr;
|
464
|
+
|
465
|
+
if (l == NULL)
|
466
|
+
{
|
467
|
+
return (-1);
|
468
|
+
}
|
469
|
+
|
470
|
+
n = LIBNET_IPV6_H + payload_s; /* size of memory block */
|
471
|
+
|
472
|
+
if (LIBNET_IPV6_H + payload_s > IP_MAXPACKET)
|
473
|
+
{
|
474
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
475
|
+
"%s(): IP packet too large\n", __func__);
|
476
|
+
return (-1);
|
477
|
+
}
|
478
|
+
|
479
|
+
/*
|
480
|
+
* Find the existing protocol block if a ptag is specified, or create
|
481
|
+
* a new one.
|
482
|
+
*/
|
483
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_H);
|
484
|
+
if (p == NULL)
|
485
|
+
{
|
486
|
+
return (-1);
|
487
|
+
}
|
488
|
+
|
489
|
+
memset(&ip_hdr, 0, sizeof(ip_hdr));
|
490
|
+
/* corey: pack 4 most significant bits of tc */
|
491
|
+
ip_hdr.ip_flags[0] = (0x06 << 4) | ((tc & 0xF0) >> 4);
|
492
|
+
/* corey: fix packing of fl field */
|
493
|
+
ip_hdr.ip_flags[1] = ((tc & 0x0F) << 4) | ((fl & 0x000F0000) >> 16);
|
494
|
+
ip_hdr.ip_flags[2] = (fl & 0x0000FF00) >> 8;
|
495
|
+
ip_hdr.ip_flags[3] = (fl & 0x000000FF);
|
496
|
+
ip_hdr.ip_len = htons(len);
|
497
|
+
ip_hdr.ip_nh = nh;
|
498
|
+
ip_hdr.ip_hl = hl;
|
499
|
+
ip_hdr.ip_src = src;
|
500
|
+
ip_hdr.ip_dst = dst;
|
501
|
+
|
502
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV6_H);
|
503
|
+
if (n == -1)
|
504
|
+
{
|
505
|
+
goto bad;
|
506
|
+
}
|
507
|
+
|
508
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
509
|
+
{
|
510
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
511
|
+
"%s(): payload inconsistency\n", __func__);
|
512
|
+
goto bad;
|
513
|
+
}
|
514
|
+
|
515
|
+
if (payload && payload_s)
|
516
|
+
{
|
517
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
518
|
+
if (n == -1)
|
519
|
+
{
|
520
|
+
goto bad;
|
521
|
+
}
|
522
|
+
}
|
523
|
+
|
524
|
+
/* corey: allow for checksums in upper layer protocols */
|
525
|
+
if (!ptag) {
|
526
|
+
ptag = libnet_pblock_update(l, p, LIBNET_IPV6_H,
|
527
|
+
LIBNET_PBLOCK_IPV6_H);
|
528
|
+
|
529
|
+
libnet_pblock_record_ip_offset(l, l->total_size);
|
530
|
+
}
|
531
|
+
|
532
|
+
/*
|
533
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, LIBNET_IPV6_H,
|
534
|
+
LIBNET_PBLOCK_IPV6_H));
|
535
|
+
*/
|
536
|
+
return ptag;
|
537
|
+
bad:
|
538
|
+
libnet_pblock_delete(l, p);
|
539
|
+
return (-1);
|
540
|
+
}
|
541
|
+
|
542
|
+
libnet_ptag_t
|
543
|
+
libnet_build_ipv6_frag(u_int8_t nh, u_int8_t reserved, u_int16_t frag,
|
544
|
+
u_int32_t id, u_int8_t *payload, u_int32_t payload_s, libnet_t *l,
|
545
|
+
libnet_ptag_t ptag)
|
546
|
+
{
|
547
|
+
u_int32_t n;
|
548
|
+
u_int16_t h;
|
549
|
+
libnet_pblock_t *p;
|
550
|
+
struct libnet_ipv6_frag_hdr ipv6_frag_hdr;
|
551
|
+
|
552
|
+
if (l == NULL)
|
553
|
+
{
|
554
|
+
return (-1);
|
555
|
+
}
|
556
|
+
|
557
|
+
n = LIBNET_IPV6_FRAG_H + payload_s;
|
558
|
+
h = 0;
|
559
|
+
|
560
|
+
if (LIBNET_IPV6_FRAG_H + payload_s > IP_MAXPACKET)
|
561
|
+
{
|
562
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
563
|
+
"%s(): IP packet too large\n", __func__);
|
564
|
+
return (-1);
|
565
|
+
}
|
566
|
+
|
567
|
+
/*
|
568
|
+
* Find the existing protocol block if a ptag is specified, or create
|
569
|
+
* a new one.
|
570
|
+
*/
|
571
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_FRAG_H);
|
572
|
+
if (p == NULL)
|
573
|
+
{
|
574
|
+
return (-1);
|
575
|
+
}
|
576
|
+
|
577
|
+
memset(&ipv6_frag_hdr, 0 , sizeof(ipv6_frag_hdr));
|
578
|
+
ipv6_frag_hdr.ip_nh = nh;
|
579
|
+
ipv6_frag_hdr.ip_reserved = reserved;
|
580
|
+
ipv6_frag_hdr.ip_frag = frag;
|
581
|
+
ipv6_frag_hdr.ip_id = id;
|
582
|
+
|
583
|
+
/*
|
584
|
+
* Appened the protocol unit to the list.
|
585
|
+
*/
|
586
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_frag_hdr,
|
587
|
+
LIBNET_IPV6_FRAG_H);
|
588
|
+
if (n == -1)
|
589
|
+
{
|
590
|
+
goto bad;
|
591
|
+
}
|
592
|
+
|
593
|
+
/*
|
594
|
+
* Sanity check the payload arguments.
|
595
|
+
*/
|
596
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
597
|
+
{
|
598
|
+
sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
|
599
|
+
goto bad;
|
600
|
+
}
|
601
|
+
|
602
|
+
/*
|
603
|
+
* Append the payload to the list if it exists.
|
604
|
+
*/
|
605
|
+
if (payload && payload_s)
|
606
|
+
{
|
607
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
608
|
+
if (n == -1)
|
609
|
+
{
|
610
|
+
goto bad;
|
611
|
+
}
|
612
|
+
}
|
613
|
+
|
614
|
+
/*
|
615
|
+
* Update the protocol block's meta information and return the protocol
|
616
|
+
* tag id of this pblock. This tag will be used to locate the pblock
|
617
|
+
* in order to modify the protocol header in subsequent calls.
|
618
|
+
*/
|
619
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, h,
|
620
|
+
LIBNET_PBLOCK_IPV6_FRAG_H));
|
621
|
+
bad:
|
622
|
+
libnet_pblock_delete(l, p);
|
623
|
+
return (-1);
|
624
|
+
}
|
625
|
+
|
626
|
+
libnet_ptag_t
|
627
|
+
libnet_build_ipv6_routing(u_int8_t nh, u_int8_t len, u_int8_t rtype,
|
628
|
+
u_int8_t segments, u_int8_t *payload, u_int32_t payload_s, libnet_t *l,
|
629
|
+
libnet_ptag_t ptag)
|
630
|
+
{
|
631
|
+
u_int32_t n;
|
632
|
+
u_int16_t h;
|
633
|
+
libnet_pblock_t *p;
|
634
|
+
struct libnet_ipv6_routing_hdr ipv6_routing_hdr;
|
635
|
+
|
636
|
+
if (l == NULL)
|
637
|
+
{
|
638
|
+
return (-1);
|
639
|
+
}
|
640
|
+
|
641
|
+
/* Important: IPv6 routing header routes are specified using the payload
|
642
|
+
* interface!
|
643
|
+
*/
|
644
|
+
n = LIBNET_IPV6_ROUTING_H + payload_s;
|
645
|
+
h = 0;
|
646
|
+
|
647
|
+
if (LIBNET_IPV6_ROUTING_H + payload_s > IP_MAXPACKET)
|
648
|
+
{
|
649
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
650
|
+
"%s(): IP packet too large\n", __func__);
|
651
|
+
return (-1);
|
652
|
+
}
|
653
|
+
|
654
|
+
/*
|
655
|
+
* Find the existing protocol block if a ptag is specified, or create
|
656
|
+
* a new one.
|
657
|
+
*/
|
658
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_ROUTING_H);
|
659
|
+
if (p == NULL)
|
660
|
+
{
|
661
|
+
return (-1);
|
662
|
+
}
|
663
|
+
|
664
|
+
memset(&ipv6_routing_hdr, 0 , sizeof(ipv6_routing_hdr));
|
665
|
+
ipv6_routing_hdr.ip_nh = nh;
|
666
|
+
ipv6_routing_hdr.ip_len = len;
|
667
|
+
ipv6_routing_hdr.ip_rtype = rtype;
|
668
|
+
ipv6_routing_hdr.ip_segments = segments;
|
669
|
+
|
670
|
+
/*
|
671
|
+
* Appened the protocol unit to the list.
|
672
|
+
*/
|
673
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_routing_hdr,
|
674
|
+
LIBNET_IPV6_ROUTING_H);
|
675
|
+
if (n == -1)
|
676
|
+
{
|
677
|
+
goto bad;
|
678
|
+
}
|
679
|
+
|
680
|
+
/*
|
681
|
+
* Sanity check the payload arguments.
|
682
|
+
*/
|
683
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
684
|
+
{
|
685
|
+
sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
|
686
|
+
goto bad;
|
687
|
+
}
|
688
|
+
|
689
|
+
/*
|
690
|
+
* Append the payload to the list if it exists.
|
691
|
+
*/
|
692
|
+
if (payload && payload_s)
|
693
|
+
{
|
694
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
695
|
+
if (n == -1)
|
696
|
+
{
|
697
|
+
goto bad;
|
698
|
+
}
|
699
|
+
}
|
700
|
+
|
701
|
+
/*
|
702
|
+
* Update the protocol block's meta information and return the protocol
|
703
|
+
* tag id of this pblock. This tag will be used to locate the pblock
|
704
|
+
* in order to modify the protocol header in subsequent calls.
|
705
|
+
*/
|
706
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, h,
|
707
|
+
LIBNET_PBLOCK_IPV6_ROUTING_H));
|
708
|
+
bad:
|
709
|
+
libnet_pblock_delete(l, p);
|
710
|
+
return (-1);
|
711
|
+
}
|
712
|
+
|
713
|
+
libnet_ptag_t
|
714
|
+
libnet_build_ipv6_destopts(u_int8_t nh, u_int8_t len, u_int8_t *payload,
|
715
|
+
u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
|
716
|
+
{
|
717
|
+
u_int32_t n;
|
718
|
+
u_int16_t h;
|
719
|
+
libnet_pblock_t *p;
|
720
|
+
struct libnet_ipv6_destopts_hdr ipv6_destopts_hdr;
|
721
|
+
|
722
|
+
if (l == NULL)
|
723
|
+
{
|
724
|
+
return (-1);
|
725
|
+
}
|
726
|
+
|
727
|
+
/* Important: IPv6 dest opts information is specified using the payload
|
728
|
+
* interface!
|
729
|
+
*/
|
730
|
+
n = LIBNET_IPV6_DESTOPTS_H + payload_s;
|
731
|
+
h = 0;
|
732
|
+
|
733
|
+
if (LIBNET_IPV6_DESTOPTS_H + payload_s > IP_MAXPACKET)
|
734
|
+
{
|
735
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
736
|
+
"%s(): IP packet too large\n", __func__);
|
737
|
+
return (-1);
|
738
|
+
}
|
739
|
+
|
740
|
+
/*
|
741
|
+
* Find the existing protocol block if a ptag is specified, or create
|
742
|
+
* a new one.
|
743
|
+
*/
|
744
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_DESTOPTS_H);
|
745
|
+
if (p == NULL)
|
746
|
+
{
|
747
|
+
return (-1);
|
748
|
+
}
|
749
|
+
|
750
|
+
memset(&ipv6_destopts_hdr, 0 , sizeof(ipv6_destopts_hdr));
|
751
|
+
ipv6_destopts_hdr.ip_nh = nh;
|
752
|
+
ipv6_destopts_hdr.ip_len = len;
|
753
|
+
|
754
|
+
/*
|
755
|
+
* Appened the protocol unit to the list.
|
756
|
+
*/
|
757
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_destopts_hdr,
|
758
|
+
LIBNET_IPV6_DESTOPTS_H);
|
759
|
+
if (n == -1)
|
760
|
+
{
|
761
|
+
goto bad;
|
762
|
+
}
|
763
|
+
|
764
|
+
/*
|
765
|
+
* Sanity check the payload arguments.
|
766
|
+
*/
|
767
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
768
|
+
{
|
769
|
+
sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
|
770
|
+
goto bad;
|
771
|
+
}
|
772
|
+
|
773
|
+
/*
|
774
|
+
* Append the payload to the list if it exists.
|
775
|
+
*/
|
776
|
+
if (payload && payload_s)
|
777
|
+
{
|
778
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
779
|
+
if (n == -1)
|
780
|
+
{
|
781
|
+
goto bad;
|
782
|
+
}
|
783
|
+
}
|
784
|
+
|
785
|
+
/*
|
786
|
+
* Update the protocol block's meta information and return the protocol
|
787
|
+
* tag id of this pblock. This tag will be used to locate the pblock
|
788
|
+
* in order to modify the protocol header in subsequent calls.
|
789
|
+
*/
|
790
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, h,
|
791
|
+
LIBNET_PBLOCK_IPV6_DESTOPTS_H));
|
792
|
+
bad:
|
793
|
+
libnet_pblock_delete(l, p);
|
794
|
+
return (-1);
|
795
|
+
}
|
796
|
+
|
797
|
+
libnet_ptag_t
|
798
|
+
libnet_build_ipv6_hbhopts(u_int8_t nh, u_int8_t len, u_int8_t *payload,
|
799
|
+
u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
|
800
|
+
{
|
801
|
+
u_int32_t n;
|
802
|
+
u_int16_t h;
|
803
|
+
libnet_pblock_t *p;
|
804
|
+
struct libnet_ipv6_hbhopts_hdr ipv6_hbhopts_hdr;
|
805
|
+
|
806
|
+
if (l == NULL)
|
807
|
+
{
|
808
|
+
return (-1);
|
809
|
+
}
|
810
|
+
|
811
|
+
/* Important: IPv6 hop by hop opts information is specified using the
|
812
|
+
* payload interface!
|
813
|
+
*/
|
814
|
+
n = LIBNET_IPV6_HBHOPTS_H + payload_s;
|
815
|
+
h = 0;
|
816
|
+
|
817
|
+
if (LIBNET_IPV6_HBHOPTS_H + payload_s > IP_MAXPACKET)
|
818
|
+
{
|
819
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
820
|
+
"%s(): IP packet too large\n", __func__);
|
821
|
+
return (-1);
|
822
|
+
}
|
823
|
+
|
824
|
+
/*
|
825
|
+
* Find the existing protocol block if a ptag is specified, or create
|
826
|
+
* a new one.
|
827
|
+
*/
|
828
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_HBHOPTS_H);
|
829
|
+
if (p == NULL)
|
830
|
+
{
|
831
|
+
return (-1);
|
832
|
+
}
|
833
|
+
|
834
|
+
memset(&ipv6_hbhopts_hdr, 0 , sizeof(ipv6_hbhopts_hdr));
|
835
|
+
ipv6_hbhopts_hdr.ip_nh = nh;
|
836
|
+
ipv6_hbhopts_hdr.ip_len = len;
|
837
|
+
|
838
|
+
/*
|
839
|
+
* Appened the protocol unit to the list.
|
840
|
+
*/
|
841
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_hbhopts_hdr,
|
842
|
+
LIBNET_IPV6_HBHOPTS_H);
|
843
|
+
if (n == -1)
|
844
|
+
{
|
845
|
+
goto bad;
|
846
|
+
}
|
847
|
+
|
848
|
+
/*
|
849
|
+
* Sanity check the payload arguments.
|
850
|
+
*/
|
851
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
852
|
+
{
|
853
|
+
sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
|
854
|
+
goto bad;
|
855
|
+
}
|
856
|
+
|
857
|
+
/*
|
858
|
+
* Append the payload to the list if it exists.
|
859
|
+
*/
|
860
|
+
if (payload && payload_s)
|
861
|
+
{
|
862
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
863
|
+
if (n == -1)
|
864
|
+
{
|
865
|
+
goto bad;
|
866
|
+
}
|
867
|
+
}
|
868
|
+
|
869
|
+
/*
|
870
|
+
* Update the protocol block's meta information and return the protocol
|
871
|
+
* tag id of this pblock. This tag will be used to locate the pblock
|
872
|
+
* in order to modify the protocol header in subsequent calls.
|
873
|
+
*/
|
874
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, h,
|
875
|
+
LIBNET_PBLOCK_IPV6_HBHOPTS_H));
|
876
|
+
bad:
|
877
|
+
libnet_pblock_delete(l, p);
|
878
|
+
return (-1);
|
879
|
+
}
|
880
|
+
|
881
|
+
libnet_ptag_t
|
882
|
+
libnet_autobuild_ipv6(u_int16_t len, u_int8_t nh, struct libnet_in6_addr dst,
|
883
|
+
libnet_t *l)
|
884
|
+
{
|
885
|
+
|
886
|
+
/* NYI */
|
887
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
888
|
+
"%s(): not yet implemented\n", __func__);
|
889
|
+
return (-1);
|
890
|
+
}
|
891
|
+
|
892
|
+
/* EOF */
|