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,436 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_asn1.c,v 1.5 2004/01/03 20:31:01 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet 1.1
|
5
|
+
* libnet_asn1.c - Abstract Syntax Notation One routines
|
6
|
+
*
|
7
|
+
* Abstract Syntax Notation One, ASN.1
|
8
|
+
* As defined in ISO/IS 8824 and ISO/IS 8825
|
9
|
+
* This implements a subset of the above International Standards that
|
10
|
+
* is sufficient to implement SNMP.
|
11
|
+
*
|
12
|
+
* Encodes abstract data types into a machine independent stream of bytes.
|
13
|
+
*
|
14
|
+
* Copyright 1988, 1989, 1991, 1992 by Carnegie Mellon University
|
15
|
+
* All rights reserved.
|
16
|
+
*
|
17
|
+
* Permission to use, copy, modify, and distribute this software and its
|
18
|
+
* documentation for any purpose and without fee is hereby granted,
|
19
|
+
* provided that the above copyright notice appear in all copies and that
|
20
|
+
* both that copyright notice and this permission notice appear in
|
21
|
+
* supporting documentation, and that the name of CMU not be
|
22
|
+
* used in advertising or publicity pertaining to distribution of the
|
23
|
+
* software without specific, written prior permission.
|
24
|
+
*
|
25
|
+
* CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
26
|
+
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
27
|
+
* CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
28
|
+
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
29
|
+
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
30
|
+
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
31
|
+
* SOFTWARE.
|
32
|
+
*
|
33
|
+
* Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
|
34
|
+
* All rights reserved.
|
35
|
+
*
|
36
|
+
* Copyright (c) 1993, 1994, 1995, 1996, 1998
|
37
|
+
* The Regents of the University of California. All rights reserved.
|
38
|
+
*
|
39
|
+
* Redistribution and use in source and binary forms, with or without
|
40
|
+
* modification, are permitted provided that: (1) source code distributions
|
41
|
+
* retain the above copyright notice and this paragraph in its entirety, (2)
|
42
|
+
* distributions including binary code include the above copyright notice and
|
43
|
+
* this paragraph in its entirety in the documentation or other materials
|
44
|
+
* provided with the distribution, and (3) all advertising materials mentioning
|
45
|
+
* features or use of this software display the following acknowledgement:
|
46
|
+
* ``This product includes software developed by the University of California,
|
47
|
+
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
48
|
+
* the University nor the names of its contributors may be used to endorse
|
49
|
+
* or promote products derived from this software without specific prior
|
50
|
+
* written permission.
|
51
|
+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
52
|
+
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
53
|
+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
54
|
+
*/
|
55
|
+
|
56
|
+
#if (HAVE_CONFIG_H)
|
57
|
+
#include "../include/config.h"
|
58
|
+
#endif
|
59
|
+
#if (!(_WIN32) || (__CYGWIN__))
|
60
|
+
#include "../include/libnet.h"
|
61
|
+
#else
|
62
|
+
#include "../include/win32/libnet.h"
|
63
|
+
#endif
|
64
|
+
|
65
|
+
u_int8_t *
|
66
|
+
libnet_build_asn1_int(u_int8_t *data, int *datalen, u_int8_t type, int32_t *int_p,
|
67
|
+
int int_s)
|
68
|
+
{
|
69
|
+
/*
|
70
|
+
* ASN.1 integer ::= 0x02 asnlength byte {byte}*
|
71
|
+
*/
|
72
|
+
register int32_t integer;
|
73
|
+
register u_int32_t mask;
|
74
|
+
|
75
|
+
if (int_s != sizeof (int32_t))
|
76
|
+
{
|
77
|
+
return (NULL);
|
78
|
+
}
|
79
|
+
integer = *int_p;
|
80
|
+
|
81
|
+
/*
|
82
|
+
* Truncate "unnecessary" bytes off of the most significant end of this
|
83
|
+
* 2's complement integer. There should be no sequence of 9 consecutive
|
84
|
+
* 1's or 0's at the most significant end of the integer.
|
85
|
+
*/
|
86
|
+
mask = ((u_int32_t) 0x1FF) << ((8 * (sizeof (int32_t) - 1)) - 1);
|
87
|
+
/* mask is 0xFF800000 on a big-endian machine */
|
88
|
+
|
89
|
+
while ((((integer & mask) == 0) || ((integer & mask) == mask)) && int_s > 1)
|
90
|
+
{
|
91
|
+
int_s--;
|
92
|
+
integer <<= 8;
|
93
|
+
}
|
94
|
+
|
95
|
+
data = libnet_build_asn1_header(data, datalen, type, int_s);
|
96
|
+
|
97
|
+
if (data == NULL || *datalen < int_s)
|
98
|
+
{
|
99
|
+
return (NULL);
|
100
|
+
}
|
101
|
+
|
102
|
+
*datalen -= int_s;
|
103
|
+
|
104
|
+
mask = ((u_int32_t) 0xFF) << (8 * (sizeof(int32_t) - 1));
|
105
|
+
/* mask is 0xFF000000 on a big-endian machine */
|
106
|
+
|
107
|
+
while (int_s--)
|
108
|
+
{
|
109
|
+
*data++ = (u_int8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1)));
|
110
|
+
integer <<= 8;
|
111
|
+
}
|
112
|
+
return (data);
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
u_int8_t *
|
117
|
+
libnet_build_asn1_uint(u_int8_t *data, int *datalen, u_int8_t type, u_int32_t *int_p,
|
118
|
+
int int_s)
|
119
|
+
{
|
120
|
+
/*
|
121
|
+
* ASN.1 integer ::= 0x02 asnlength byte {byte}*
|
122
|
+
*/
|
123
|
+
register u_int32_t integer;
|
124
|
+
register u_int32_t mask;
|
125
|
+
int add_null_byte = 0;
|
126
|
+
|
127
|
+
if (int_s != sizeof (int32_t))
|
128
|
+
{
|
129
|
+
return (NULL);
|
130
|
+
}
|
131
|
+
integer = *int_p;
|
132
|
+
|
133
|
+
mask = ((u_int32_t) 0xFF) << (8 * (sizeof (int32_t) - 1));
|
134
|
+
/* mask is 0xFF000000 on a big-endian machine */
|
135
|
+
|
136
|
+
if ((u_int8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1))) & 0x80)
|
137
|
+
{
|
138
|
+
/* if MSB is set */
|
139
|
+
add_null_byte = 1;
|
140
|
+
int_s++;
|
141
|
+
}
|
142
|
+
else
|
143
|
+
{
|
144
|
+
/*
|
145
|
+
* Truncate "unnecessary" bytes off of the most significant end of this
|
146
|
+
* 2's complement integer. There should be no sequence of 9
|
147
|
+
* consecutive 1's or 0's at the most significant end of the
|
148
|
+
* integer.
|
149
|
+
*/
|
150
|
+
mask = ((u_int32_t) 0x1FF) << ((8 * (sizeof(int32_t) - 1)) - 1);
|
151
|
+
/* mask is 0xFF800000 on a big-endian machine */
|
152
|
+
|
153
|
+
while (((integer & mask) == 0) && int_s > 1)
|
154
|
+
{
|
155
|
+
int_s--;
|
156
|
+
integer <<= 8;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
data = libnet_build_asn1_header(data, datalen, type, int_s);
|
161
|
+
|
162
|
+
if (data == NULL || *datalen < int_s)
|
163
|
+
{
|
164
|
+
return (NULL);
|
165
|
+
}
|
166
|
+
|
167
|
+
*datalen -= int_s;
|
168
|
+
|
169
|
+
if (add_null_byte == 1)
|
170
|
+
{
|
171
|
+
*data++ = '\0';
|
172
|
+
int_s--;
|
173
|
+
}
|
174
|
+
|
175
|
+
mask = ((u_int32_t) 0xFF) << (8 * (sizeof(int32_t) - 1));
|
176
|
+
/* mask is 0xFF000000 on a big-endian machine */
|
177
|
+
|
178
|
+
while (int_s--)
|
179
|
+
{
|
180
|
+
*data++ = (u_int8_t)((integer & mask) >> (8 * (sizeof (int32_t) - 1)));
|
181
|
+
integer <<= 8;
|
182
|
+
}
|
183
|
+
return (data);
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
u_int8_t *
|
188
|
+
libnet_build_asn1_string(u_int8_t *data, int *datalen, u_int8_t type,
|
189
|
+
u_int8_t *string, int str_s)
|
190
|
+
{
|
191
|
+
|
192
|
+
/*
|
193
|
+
* ASN.1 octet string ::= primstring | cmpdstring
|
194
|
+
* primstring ::= 0x04 asnlength byte {byte}*
|
195
|
+
* cmpdstring ::= 0x24 asnlength string {string}*
|
196
|
+
* This code will never send a compound string.
|
197
|
+
*/
|
198
|
+
data = libnet_build_asn1_header(data, datalen, type, str_s);
|
199
|
+
|
200
|
+
if (data == NULL || *datalen < str_s)
|
201
|
+
{
|
202
|
+
return (NULL);
|
203
|
+
}
|
204
|
+
memmove(data, string, str_s);
|
205
|
+
*datalen -= str_s;
|
206
|
+
|
207
|
+
return (data + str_s);
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
u_int8_t *
|
212
|
+
libnet_build_asn1_header(u_int8_t *data, int *datalen, u_int8_t type, int len)
|
213
|
+
{
|
214
|
+
if (*datalen < 1)
|
215
|
+
{
|
216
|
+
return (NULL);
|
217
|
+
}
|
218
|
+
*data++ = type;
|
219
|
+
(*datalen)--;
|
220
|
+
|
221
|
+
return (libnet_build_asn1_length(data, datalen, len));
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
u_int8_t *
|
226
|
+
libnet_build_asn1_sequence(u_int8_t *data, int *datalen, u_int8_t type, int len)
|
227
|
+
{
|
228
|
+
*datalen -= 4;
|
229
|
+
if (*datalen < 0)
|
230
|
+
{
|
231
|
+
*datalen += 4; /* fix up before punting */
|
232
|
+
return (NULL);
|
233
|
+
}
|
234
|
+
*data++ = type;
|
235
|
+
*data++ = (u_int8_t)(0x02 | ASN_LONG_LEN);
|
236
|
+
*data++ = (u_int8_t)((len >> 8) & 0xFF);
|
237
|
+
*data++ = (u_int8_t)(len & 0xFF);
|
238
|
+
return (data);
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
u_int8_t *
|
243
|
+
libnet_build_asn1_length(u_int8_t *data, int *datalen, int len)
|
244
|
+
{
|
245
|
+
u_int8_t *start_data = data;
|
246
|
+
|
247
|
+
/* no indefinite lengths sent */
|
248
|
+
if (len < 0x80)
|
249
|
+
{
|
250
|
+
if (*datalen < 1)
|
251
|
+
{
|
252
|
+
return (NULL);
|
253
|
+
}
|
254
|
+
*data++ = (u_int8_t)len;
|
255
|
+
}
|
256
|
+
else if (len <= 0xFF)
|
257
|
+
{
|
258
|
+
if (*datalen < 2)
|
259
|
+
{
|
260
|
+
return (NULL);
|
261
|
+
}
|
262
|
+
*data++ = (u_int8_t)(0x01 | ASN_LONG_LEN);
|
263
|
+
*data++ = (u_int8_t)len;
|
264
|
+
}
|
265
|
+
else /* 0xFF < len <= 0xFFFF */
|
266
|
+
{
|
267
|
+
if (*datalen < 3)
|
268
|
+
{
|
269
|
+
return (NULL);
|
270
|
+
}
|
271
|
+
*data++ = (u_int8_t)(0x02 | ASN_LONG_LEN);
|
272
|
+
*data++ = (u_int8_t)((len >> 8) & 0xFF);
|
273
|
+
*data++ = (u_int8_t)(len & 0xFF);
|
274
|
+
}
|
275
|
+
*datalen -= (data - start_data);
|
276
|
+
return (data);
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
u_int8_t *
|
281
|
+
libnet_build_asn1_objid(u_int8_t *data, int *datalen, u_int8_t type, oid *objid,
|
282
|
+
int objidlen)
|
283
|
+
{
|
284
|
+
/*
|
285
|
+
* ASN.1 objid ::= 0x06 asnlength subidentifier {subidentifier}*
|
286
|
+
* subidentifier ::= {leadingbyte}* lastbyte
|
287
|
+
* leadingbyte ::= 1 7bitvalue
|
288
|
+
* lastbyte ::= 0 7bitvalue
|
289
|
+
*/
|
290
|
+
int asnlen;
|
291
|
+
register oid *op = objid;
|
292
|
+
u_int8_t objid_size[MAX_OID_LEN];
|
293
|
+
register u_int32_t objid_val;
|
294
|
+
u_int32_t first_objid_val;
|
295
|
+
register int i;
|
296
|
+
|
297
|
+
/* check if there are at least 2 sub-identifiers */
|
298
|
+
if (objidlen < 2)
|
299
|
+
{
|
300
|
+
/* there are not, so make OID have two with value of zero */
|
301
|
+
objid_val = 0;
|
302
|
+
objidlen = 2;
|
303
|
+
}
|
304
|
+
else
|
305
|
+
{
|
306
|
+
/* combine the first two values */
|
307
|
+
objid_val = (op[0] * 40) + op[1];
|
308
|
+
op += 2;
|
309
|
+
}
|
310
|
+
first_objid_val = objid_val;
|
311
|
+
|
312
|
+
/* calculate the number of bytes needed to store the encoded value */
|
313
|
+
for (i = 1, asnlen = 0;;)
|
314
|
+
{
|
315
|
+
if (objid_val < (unsigned)0x80)
|
316
|
+
{
|
317
|
+
objid_size[i] = 1;
|
318
|
+
asnlen += 1;
|
319
|
+
}
|
320
|
+
else if (objid_val < (unsigned)0x4000)
|
321
|
+
{
|
322
|
+
objid_size[i] = 2;
|
323
|
+
asnlen += 2;
|
324
|
+
}
|
325
|
+
else if (objid_val < (unsigned)0x200000)
|
326
|
+
{
|
327
|
+
objid_size[i] = 3;
|
328
|
+
asnlen += 3;
|
329
|
+
}
|
330
|
+
else if (objid_val < (unsigned)0x10000000)
|
331
|
+
{
|
332
|
+
objid_size[i] = 4;
|
333
|
+
asnlen += 4;
|
334
|
+
}
|
335
|
+
else
|
336
|
+
{
|
337
|
+
objid_size[i] = 5;
|
338
|
+
asnlen += 5;
|
339
|
+
}
|
340
|
+
i++;
|
341
|
+
if (i >= objidlen)
|
342
|
+
{
|
343
|
+
break;
|
344
|
+
}
|
345
|
+
objid_val = *op++;
|
346
|
+
}
|
347
|
+
|
348
|
+
/* store the ASN.1 tag and length */
|
349
|
+
data = libnet_build_asn1_header(data, datalen, type, asnlen);
|
350
|
+
if (data == NULL || *datalen < asnlen)
|
351
|
+
{
|
352
|
+
return (NULL);
|
353
|
+
}
|
354
|
+
|
355
|
+
/* store the encoded OID value */
|
356
|
+
for (i = 1, objid_val = first_objid_val, op = objid + 2; i < objidlen; i++)
|
357
|
+
{
|
358
|
+
if (i != 1)
|
359
|
+
{
|
360
|
+
objid_val = *op++;
|
361
|
+
}
|
362
|
+
switch (objid_size[i])
|
363
|
+
{
|
364
|
+
case 1:
|
365
|
+
*data++ = (u_int8_t)objid_val;
|
366
|
+
break;
|
367
|
+
|
368
|
+
case 2:
|
369
|
+
*data++ = (u_int8_t)((objid_val >> 7) | 0x80);
|
370
|
+
*data++ = (u_int8_t)(objid_val & 0x07f);
|
371
|
+
break;
|
372
|
+
case 3:
|
373
|
+
*data++ = (u_int8_t)((objid_val >> 14) | 0x80);
|
374
|
+
*data++ = (u_int8_t)((objid_val >> 7 & 0x7f) | 0x80);
|
375
|
+
*data++ = (u_int8_t)(objid_val & 0x07f);
|
376
|
+
break;
|
377
|
+
|
378
|
+
case 4:
|
379
|
+
*data++ = (u_int8_t)((objid_val >> 21) | 0x80);
|
380
|
+
*data++ = (u_int8_t)((objid_val >> 14 & 0x7f) | 0x80);
|
381
|
+
*data++ = (u_int8_t)((objid_val >> 7 & 0x7f) | 0x80);
|
382
|
+
*data++ = (u_int8_t)(objid_val & 0x07f);
|
383
|
+
break;
|
384
|
+
|
385
|
+
case 5:
|
386
|
+
*data++ = (u_int8_t)((objid_val >> 28) | 0x80);
|
387
|
+
*data++ = (u_int8_t)((objid_val >> 21 & 0x7f) | 0x80);
|
388
|
+
*data++ = (u_int8_t)((objid_val >> 14 & 0x7f) | 0x80);
|
389
|
+
*data++ = (u_int8_t)((objid_val >> 7 & 0x7f) | 0x80);
|
390
|
+
*data++ = (u_int8_t)(objid_val & 0x07f);
|
391
|
+
break;
|
392
|
+
}
|
393
|
+
}
|
394
|
+
|
395
|
+
/* return the length and data ptagr */
|
396
|
+
*datalen -= asnlen;
|
397
|
+
return (data);
|
398
|
+
}
|
399
|
+
|
400
|
+
|
401
|
+
u_int8_t *
|
402
|
+
libnet_build_asn1_null(u_int8_t *data, int *datalen, u_int8_t type)
|
403
|
+
{
|
404
|
+
/*
|
405
|
+
* ASN.1 null ::= 0x05 0x00
|
406
|
+
*/
|
407
|
+
return (libnet_build_asn1_header(data, datalen, type, 0));
|
408
|
+
}
|
409
|
+
|
410
|
+
|
411
|
+
u_int8_t *
|
412
|
+
libnet_build_asn1_bitstring(u_int8_t *data, int *datalen, u_int8_t type,
|
413
|
+
u_int8_t *string, int str_s)
|
414
|
+
{
|
415
|
+
|
416
|
+
/*
|
417
|
+
* ASN.1 bit string ::= 0x03 asnlength unused {byte}*
|
418
|
+
*/
|
419
|
+
if (str_s < 1 || *string > 7)
|
420
|
+
{
|
421
|
+
return (NULL);
|
422
|
+
}
|
423
|
+
data = libnet_build_asn1_header(data, datalen, type, str_s);
|
424
|
+
|
425
|
+
if (data == NULL || *datalen < str_s)
|
426
|
+
{
|
427
|
+
return (NULL);
|
428
|
+
}
|
429
|
+
|
430
|
+
memmove(data, string, str_s);
|
431
|
+
*datalen -= str_s;
|
432
|
+
|
433
|
+
return (data + str_s);
|
434
|
+
}
|
435
|
+
|
436
|
+
/* EOF */
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_build_802.1q.c,v 1.10 2004/01/28 19:45:00 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet
|
5
|
+
* libnet_build_802.1q.c - 802.1q 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
|
+
libnet_ptag_t
|
43
|
+
libnet_build_802_1q(u_int8_t *dst, u_int8_t *src, u_int16_t tpi,
|
44
|
+
u_int8_t priority, u_int8_t cfi, u_int16_t vlan_id, u_int16_t len_proto,
|
45
|
+
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
|
46
|
+
{
|
47
|
+
u_int32_t n, h;
|
48
|
+
libnet_pblock_t *p;
|
49
|
+
struct libnet_802_1q_hdr _802_1q_hdr;
|
50
|
+
|
51
|
+
if (l == NULL)
|
52
|
+
{
|
53
|
+
return (-1);
|
54
|
+
}
|
55
|
+
|
56
|
+
n = LIBNET_802_1Q_H + payload_s;
|
57
|
+
h = 0;
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Find the existing protocol block if a ptag is specified, or create
|
61
|
+
* a new one.
|
62
|
+
*/
|
63
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_802_1Q_H);
|
64
|
+
if (p == NULL)
|
65
|
+
{
|
66
|
+
return (-1);
|
67
|
+
}
|
68
|
+
|
69
|
+
memset(&_802_1q_hdr, 0, sizeof(_802_1q_hdr));
|
70
|
+
memcpy(_802_1q_hdr.vlan_dhost, dst, ETHER_ADDR_LEN);
|
71
|
+
memcpy(_802_1q_hdr.vlan_shost, src, ETHER_ADDR_LEN);
|
72
|
+
_802_1q_hdr.vlan_tpi = htons(tpi);
|
73
|
+
_802_1q_hdr.vlan_priority_c_vid = htons((priority << 13) | (cfi << 12)
|
74
|
+
| (vlan_id & LIBNET_802_1Q_VIDMASK));
|
75
|
+
_802_1q_hdr.vlan_len = htons(len_proto);
|
76
|
+
|
77
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&_802_1q_hdr, LIBNET_802_1Q_H);
|
78
|
+
if (n == -1)
|
79
|
+
{
|
80
|
+
goto bad;
|
81
|
+
}
|
82
|
+
|
83
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
84
|
+
{
|
85
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
86
|
+
"%s(): payload inconsistency\n", __func__);
|
87
|
+
goto bad;
|
88
|
+
}
|
89
|
+
|
90
|
+
if (payload && payload_s)
|
91
|
+
{
|
92
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
93
|
+
if (n == -1)
|
94
|
+
{
|
95
|
+
goto bad;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
/*
|
100
|
+
* The link offset is actually 4 bytes further into the header than
|
101
|
+
* before (the VLAN header adds this 4 bytes). We need to update the
|
102
|
+
* link offset pointer. XXX - should we set this here?
|
103
|
+
* Probably not. We should make pblock_coalesce check the pblock type
|
104
|
+
* and adjust accordingly.
|
105
|
+
*/
|
106
|
+
l->link_offset += 4;
|
107
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, h,
|
108
|
+
LIBNET_PBLOCK_802_1Q_H));
|
109
|
+
bad:
|
110
|
+
libnet_pblock_delete(l, p);
|
111
|
+
return (-1);
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
/* EOF */
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_build_802.1x.c,v 1.11 2004/01/28 19:45:00 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet
|
5
|
+
* libnet_build_802.1x.c - 802.1x 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
|
+
libnet_ptag_t
|
43
|
+
libnet_build_802_1x(u_int8_t eap_ver, u_int8_t eap_type, u_int16_t length,
|
44
|
+
u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
|
45
|
+
{
|
46
|
+
u_int32_t n, h;
|
47
|
+
libnet_pblock_t *p;
|
48
|
+
struct libnet_802_1x_hdr dot1x_hdr;
|
49
|
+
|
50
|
+
if (l == NULL)
|
51
|
+
{
|
52
|
+
return (-1);
|
53
|
+
}
|
54
|
+
|
55
|
+
n = LIBNET_802_1X_H + payload_s;
|
56
|
+
h = 0;
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Find the existing protocol block if a ptag is specified, or create
|
60
|
+
* a new one.
|
61
|
+
*/
|
62
|
+
p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_802_1X_H);
|
63
|
+
if (p == NULL)
|
64
|
+
{
|
65
|
+
return (-1);
|
66
|
+
}
|
67
|
+
|
68
|
+
memset(&dot1x_hdr, 0, sizeof(dot1x_hdr));
|
69
|
+
dot1x_hdr.dot1x_version = eap_ver;
|
70
|
+
dot1x_hdr.dot1x_type = eap_type;
|
71
|
+
dot1x_hdr.dot1x_length = htons(length);
|
72
|
+
|
73
|
+
n = libnet_pblock_append(l, p, (u_int8_t *)&dot1x_hdr, LIBNET_802_1X_H);
|
74
|
+
if (n == -1)
|
75
|
+
{
|
76
|
+
goto bad;
|
77
|
+
}
|
78
|
+
|
79
|
+
if ((payload && !payload_s) || (!payload && payload_s))
|
80
|
+
{
|
81
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
82
|
+
"%s(): payload inconsistency\n", __func__);
|
83
|
+
goto bad;
|
84
|
+
}
|
85
|
+
|
86
|
+
if (payload && payload_s)
|
87
|
+
{
|
88
|
+
n = libnet_pblock_append(l, p, payload, payload_s);
|
89
|
+
if (n == -1)
|
90
|
+
{
|
91
|
+
goto bad;
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
return (ptag ? ptag : libnet_pblock_update(l, p, h,
|
96
|
+
LIBNET_PBLOCK_802_1X_H));
|
97
|
+
bad:
|
98
|
+
libnet_pblock_delete(l, p);
|
99
|
+
return (-1);
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
/* EOF */
|