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,310 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_internal.c,v 1.14 2004/03/16 18:40:59 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet
|
5
|
+
* libnet_internal.c - secret routines!
|
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
|
+
void
|
43
|
+
libnet_diag_dump_hex(u_int8_t *packet, u_int32_t len, int swap, FILE *stream)
|
44
|
+
{
|
45
|
+
int i, s_cnt;
|
46
|
+
u_int16_t *p;
|
47
|
+
|
48
|
+
p = (u_int16_t *)packet;
|
49
|
+
s_cnt = len / sizeof(u_int16_t);
|
50
|
+
|
51
|
+
fprintf(stream, "\t");
|
52
|
+
for (i = 0; --s_cnt >= 0; i++)
|
53
|
+
{
|
54
|
+
if ((!(i % 8)))
|
55
|
+
{
|
56
|
+
fprintf(stream, "\n%02x\t", (i * 2));
|
57
|
+
}
|
58
|
+
fprintf(stream, "%04x ", swap ? ntohs(*(p++)) : *(p++));
|
59
|
+
}
|
60
|
+
|
61
|
+
/*
|
62
|
+
* Mop up an odd byte.
|
63
|
+
*/
|
64
|
+
if (len & 1)
|
65
|
+
{
|
66
|
+
if ((!(i % 8)))
|
67
|
+
{
|
68
|
+
fprintf(stream, "\n%02x\t", (i * 2));
|
69
|
+
}
|
70
|
+
fprintf(stream, "%02x ", *(u_int8_t *)p);
|
71
|
+
}
|
72
|
+
fprintf(stream, "\n");
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
void
|
77
|
+
libnet_diag_dump_context(libnet_t *l)
|
78
|
+
{
|
79
|
+
if (l == NULL)
|
80
|
+
{
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
|
84
|
+
fprintf(stderr, "fd:\t\t%d\n", l->fd);
|
85
|
+
|
86
|
+
switch (l->injection_type)
|
87
|
+
{
|
88
|
+
case LIBNET_LINK:
|
89
|
+
fprintf(stderr, "injection type:\tLIBNET_LINK\n");
|
90
|
+
break;
|
91
|
+
case LIBNET_RAW4:
|
92
|
+
fprintf(stderr, "injection type:\tLIBNET_RAW4\n");
|
93
|
+
break;
|
94
|
+
case LIBNET_RAW6:
|
95
|
+
fprintf(stderr, "injection type:\tLIBNET_RAW6\n");
|
96
|
+
break;
|
97
|
+
case LIBNET_LINK_ADV:
|
98
|
+
fprintf(stderr, "injection type:\tLIBNET_LINK_ADV\n");
|
99
|
+
break;
|
100
|
+
case LIBNET_RAW4_ADV:
|
101
|
+
fprintf(stderr, "injection type:\tLIBNET_RAW4_ADV\n");
|
102
|
+
break;
|
103
|
+
case LIBNET_RAW6_ADV:
|
104
|
+
fprintf(stderr, "injection type:\tLIBNET_RAW6_ADV\n");
|
105
|
+
break;
|
106
|
+
default:
|
107
|
+
fprintf(stderr, "injection type:\tinvalid injection type %d\n",
|
108
|
+
l->injection_type);
|
109
|
+
break;
|
110
|
+
}
|
111
|
+
|
112
|
+
fprintf(stderr, "pblock start:\t%p\n", l->protocol_blocks);
|
113
|
+
fprintf(stderr, "pblock end:\t%p\n", l->pblock_end);
|
114
|
+
fprintf(stderr, "link type:\t%d\n", l->link_type);
|
115
|
+
fprintf(stderr, "link offset:\t%d\n", l->link_offset);
|
116
|
+
fprintf(stderr, "aligner:\t%d\n", l->aligner);
|
117
|
+
fprintf(stderr, "device:\t\t%s\n", l->device);
|
118
|
+
fprintf(stderr, "packets sent:\t%lld\n", l->stats.packets_sent);
|
119
|
+
fprintf(stderr, "packet errors:\t%lld\n", l->stats.packet_errors);
|
120
|
+
fprintf(stderr, "bytes written:\t%lld\n", l->stats.bytes_written);
|
121
|
+
fprintf(stderr, "ptag state:\t%d\n", l->ptag_state);
|
122
|
+
fprintf(stderr, "context label:\t%s\n", l->label);
|
123
|
+
fprintf(stderr, "last errbuf:\t%s\n", l->err_buf);
|
124
|
+
fprintf(stderr, "total size:\t%d\n", l->total_size);
|
125
|
+
}
|
126
|
+
|
127
|
+
void
|
128
|
+
libnet_diag_dump_pblock(libnet_t *l)
|
129
|
+
{
|
130
|
+
u_int32_t n;
|
131
|
+
libnet_pblock_t *p;
|
132
|
+
|
133
|
+
for (p = l->protocol_blocks; p; p = p->next)
|
134
|
+
{
|
135
|
+
fprintf(stderr, "pblock type:\t%s\n",
|
136
|
+
libnet_diag_dump_pblock_type(p->type));
|
137
|
+
fprintf(stderr, "ptag number:\t%d\n", p->ptag);
|
138
|
+
fprintf(stderr, "IP offset:\t%d\n", p->ip_offset);
|
139
|
+
fprintf(stderr, "pblock address:\t%p\n", p);
|
140
|
+
fprintf(stderr, "next pblock\t%p ", p->next);
|
141
|
+
if (p->next)
|
142
|
+
{
|
143
|
+
fprintf(stderr, "(%s)",
|
144
|
+
libnet_diag_dump_pblock_type(p->next->type));
|
145
|
+
}
|
146
|
+
fprintf(stderr, "\n");
|
147
|
+
fprintf(stderr, "prev pblock\t%p ", p->prev);
|
148
|
+
if (p->prev)
|
149
|
+
{
|
150
|
+
fprintf(stderr, "(%s)",
|
151
|
+
libnet_diag_dump_pblock_type(p->prev->type));
|
152
|
+
}
|
153
|
+
fprintf(stderr, "\n");
|
154
|
+
fprintf(stderr, "buf:\t\t");
|
155
|
+
for (n = 0; n < p->b_len; n++)
|
156
|
+
{
|
157
|
+
fprintf(stderr, "%02x", p->buf[n]);
|
158
|
+
}
|
159
|
+
fprintf(stderr, "\nbuffer length:\t%d\n", p->b_len);
|
160
|
+
if ((p->flags) & LIBNET_PBLOCK_DO_CHECKSUM)
|
161
|
+
{
|
162
|
+
fprintf(stderr, "checksum flag:\tYes\n");
|
163
|
+
fprintf(stderr, "chksum length:\t%d\n", p->h_len);
|
164
|
+
}
|
165
|
+
else
|
166
|
+
{
|
167
|
+
fprintf(stderr, "checksum flag:\tNo\n");
|
168
|
+
}
|
169
|
+
fprintf(stderr, "bytes copied:\t%d\n\n", p->copied);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
char *
|
174
|
+
libnet_diag_dump_pblock_type(u_int8_t type)
|
175
|
+
{
|
176
|
+
static int8_t buf[50];
|
177
|
+
switch (type)
|
178
|
+
{
|
179
|
+
case LIBNET_PBLOCK_ARP_H:
|
180
|
+
return ("arp header");
|
181
|
+
case LIBNET_PBLOCK_DHCPV4_H:
|
182
|
+
return ("dhcpv4 header");
|
183
|
+
case LIBNET_PBLOCK_DNSV4_H:
|
184
|
+
return ("dnsv4 header");
|
185
|
+
case LIBNET_PBLOCK_ETH_H:
|
186
|
+
return ("ethernet header");
|
187
|
+
case LIBNET_PBLOCK_ICMPV4_H:
|
188
|
+
return ("icmpv4 header");
|
189
|
+
case LIBNET_PBLOCK_ICMPV4_ECHO_H:
|
190
|
+
return ("icmpv4 echo header");
|
191
|
+
case LIBNET_PBLOCK_ICMPV4_MASK_H:
|
192
|
+
return ("icmpv4 mask header");
|
193
|
+
case LIBNET_PBLOCK_ICMPV4_UNREACH_H:
|
194
|
+
return ("icmpv4 unreachable header");
|
195
|
+
case LIBNET_PBLOCK_ICMPV4_TIMXCEED_H:
|
196
|
+
return ("icmpv4 time exceeded header");
|
197
|
+
case LIBNET_PBLOCK_ICMPV4_REDIRECT_H:
|
198
|
+
return ("icmpv4 redirect header");
|
199
|
+
case LIBNET_PBLOCK_ICMPV4_TS_H:
|
200
|
+
return ("icmpv4 timestamp header");
|
201
|
+
case LIBNET_PBLOCK_IGMP_H:
|
202
|
+
return ("igmp header");
|
203
|
+
case LIBNET_PBLOCK_IPV4_H:
|
204
|
+
return ("ipv4 header");
|
205
|
+
case LIBNET_PBLOCK_IPO_H:
|
206
|
+
return ("ip options header");
|
207
|
+
case LIBNET_PBLOCK_IPDATA:
|
208
|
+
return ("ip data");
|
209
|
+
case LIBNET_PBLOCK_OSPF_H:
|
210
|
+
return ("ospf header");
|
211
|
+
case LIBNET_PBLOCK_OSPF_HELLO_H:
|
212
|
+
return ("ospf hello header");
|
213
|
+
case LIBNET_PBLOCK_OSPF_DBD_H:
|
214
|
+
return ("ospf dbd header");
|
215
|
+
case LIBNET_PBLOCK_OSPF_LSR_H:
|
216
|
+
return ("ospf lsr header");
|
217
|
+
case LIBNET_PBLOCK_OSPF_LSU_H:
|
218
|
+
return ("ospf lsu header");
|
219
|
+
case LIBNET_PBLOCK_OSPF_LSA_H:
|
220
|
+
return ("ospf lsa header");
|
221
|
+
case LIBNET_PBLOCK_OSPF_AUTH_H:
|
222
|
+
return ("ospf authentication header");
|
223
|
+
case LIBNET_PBLOCK_OSPF_CKSUM:
|
224
|
+
return ("ospf checksum");
|
225
|
+
case LIBNET_PBLOCK_LS_RTR_H:
|
226
|
+
return ("ospf ls rtr header");
|
227
|
+
case LIBNET_PBLOCK_LS_NET_H:
|
228
|
+
return ("ospf ls net header");
|
229
|
+
case LIBNET_PBLOCK_LS_SUM_H:
|
230
|
+
return ("ospf ls sum header");
|
231
|
+
case LIBNET_PBLOCK_LS_AS_EXT_H:
|
232
|
+
return ("ospf ls as extension header");
|
233
|
+
case LIBNET_PBLOCK_NTP_H:
|
234
|
+
return ("ntp header");
|
235
|
+
case LIBNET_PBLOCK_RIP_H:
|
236
|
+
return ("rip header");
|
237
|
+
case LIBNET_PBLOCK_TCP_H:
|
238
|
+
return ("tcp header");
|
239
|
+
case LIBNET_PBLOCK_TCPO_H:
|
240
|
+
return ("tcp options header");
|
241
|
+
case LIBNET_PBLOCK_TCPDATA:
|
242
|
+
return ("tcp data");
|
243
|
+
case LIBNET_PBLOCK_UDP_H:
|
244
|
+
return ("udp header");
|
245
|
+
case LIBNET_PBLOCK_VRRP_H:
|
246
|
+
return ("vrrp header");
|
247
|
+
case LIBNET_PBLOCK_DATA_H:
|
248
|
+
return ("data");
|
249
|
+
case LIBNET_PBLOCK_CDP_H:
|
250
|
+
return ("cdp header");
|
251
|
+
case LIBNET_PBLOCK_IPSEC_ESP_HDR_H:
|
252
|
+
return ("ipsec esp header");
|
253
|
+
case LIBNET_PBLOCK_IPSEC_ESP_FTR_H:
|
254
|
+
return ("ipsec esp footer");
|
255
|
+
case LIBNET_PBLOCK_IPSEC_AH_H:
|
256
|
+
return ("ipsec authentication header");
|
257
|
+
case LIBNET_PBLOCK_802_1Q_H:
|
258
|
+
return ("802.1q header");
|
259
|
+
case LIBNET_PBLOCK_802_2_H:
|
260
|
+
return ("802.2 header");
|
261
|
+
case LIBNET_PBLOCK_802_2SNAP_H:
|
262
|
+
return ("802.2SNAP header");
|
263
|
+
case LIBNET_PBLOCK_802_3_H:
|
264
|
+
return ("802.3 header");
|
265
|
+
case LIBNET_PBLOCK_STP_CONF_H:
|
266
|
+
return ("stp configuration header");
|
267
|
+
case LIBNET_PBLOCK_STP_TCN_H:
|
268
|
+
return ("stp tcn header");
|
269
|
+
case LIBNET_PBLOCK_ISL_H:
|
270
|
+
return ("isl header");
|
271
|
+
case LIBNET_PBLOCK_IPV6_H:
|
272
|
+
return ("ipv6 header");
|
273
|
+
case LIBNET_PBLOCK_802_1X_H:
|
274
|
+
return ("802.1x header");
|
275
|
+
case LIBNET_PBLOCK_RPC_CALL_H:
|
276
|
+
return ("rpc call header");
|
277
|
+
case LIBNET_PBLOCK_MPLS_H:
|
278
|
+
return ("mlps header");
|
279
|
+
case LIBNET_PBLOCK_FDDI_H:
|
280
|
+
return ("fddi header");
|
281
|
+
case LIBNET_PBLOCK_TOKEN_RING_H:
|
282
|
+
return ("token ring header");
|
283
|
+
case LIBNET_PBLOCK_BGP4_HEADER_H:
|
284
|
+
return ("bgp header");
|
285
|
+
case LIBNET_PBLOCK_BGP4_OPEN_H:
|
286
|
+
return ("bgp open header");
|
287
|
+
case LIBNET_PBLOCK_BGP4_UPDATE_H:
|
288
|
+
return ("bgp update header");
|
289
|
+
case LIBNET_PBLOCK_BGP4_NOTIFICATION_H:
|
290
|
+
return ("bgp notification header");
|
291
|
+
case LIBNET_PBLOCK_GRE_H:
|
292
|
+
return ("gre header");
|
293
|
+
case LIBNET_PBLOCK_GRE_SRE_H:
|
294
|
+
return ("gre sre header");
|
295
|
+
case LIBNET_PBLOCK_IPV6_FRAG_H:
|
296
|
+
return ("ipv6 fragmentation header");
|
297
|
+
case LIBNET_PBLOCK_IPV6_ROUTING_H:
|
298
|
+
return ("ipv6 routing header");
|
299
|
+
case LIBNET_PBLOCK_IPV6_DESTOPTS_H:
|
300
|
+
return ("ipv6 destination options header");
|
301
|
+
case LIBNET_PBLOCK_IPV6_HBHOPTS_H:
|
302
|
+
return ("ipv6 hop by hop options header");
|
303
|
+
default:
|
304
|
+
snprintf(buf, sizeof(buf),
|
305
|
+
"%s(): unknown pblock type: %d", __func__, type);
|
306
|
+
return (buf);
|
307
|
+
}
|
308
|
+
return ("unreachable code");
|
309
|
+
}
|
310
|
+
/* EOF */
|
@@ -0,0 +1,348 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_link_bpf.c,v 1.6 2004/01/28 19:45:00 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet
|
5
|
+
* libnet_link_bpf.c - low-level bpf routines
|
6
|
+
*
|
7
|
+
* Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
|
8
|
+
* All rights reserved.
|
9
|
+
*
|
10
|
+
* Copyright (c) 1993, 1994, 1995, 1996, 1998
|
11
|
+
* The Regents of the University of California. All rights reserved.
|
12
|
+
*
|
13
|
+
* Redistribution and use in source and binary forms, with or without
|
14
|
+
* modification, are permitted provided that: (1) source code distributions
|
15
|
+
* retain the above copyright notice and this paragraph in its entirety, (2)
|
16
|
+
* distributions including binary code include the above copyright notice and
|
17
|
+
* this paragraph in its entirety in the documentation or other materials
|
18
|
+
* provided with the distribution, and (3) all advertising materials mentioning
|
19
|
+
* features or use of this software display the following acknowledgement:
|
20
|
+
* ``This product includes software developed by the University of California,
|
21
|
+
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
22
|
+
* the University nor the names of its contributors may be used to endorse
|
23
|
+
* or promote products derived from this software without specific prior
|
24
|
+
* written permission.
|
25
|
+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
26
|
+
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
27
|
+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
28
|
+
*/
|
29
|
+
|
30
|
+
#include <sys/param.h> /* optionally get BSD define */
|
31
|
+
#include <sys/timeb.h>
|
32
|
+
#include <sys/file.h>
|
33
|
+
#include <sys/ioctl.h>
|
34
|
+
|
35
|
+
#include <sys/types.h>
|
36
|
+
#include <sys/time.h>
|
37
|
+
#include <net/bpf.h>
|
38
|
+
|
39
|
+
#if (HAVE_CONFIG_H)
|
40
|
+
#include "../include/config.h"
|
41
|
+
#endif
|
42
|
+
#include "../include/libnet.h"
|
43
|
+
#include <sys/sysctl.h>
|
44
|
+
#include <net/route.h>
|
45
|
+
#include <net/if_dl.h>
|
46
|
+
#include "../include/gnuc.h"
|
47
|
+
#include "../include/bpf.h"
|
48
|
+
|
49
|
+
#ifdef HAVE_OS_PROTO_H
|
50
|
+
#include "../include/os-proto.h"
|
51
|
+
#endif
|
52
|
+
|
53
|
+
int
|
54
|
+
libnet_bpf_open(int8_t *err_buf)
|
55
|
+
{
|
56
|
+
int i, fd;
|
57
|
+
int8_t device[sizeof "/dev/bpf000"];
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Go through all the minors and find one that isn't in use.
|
61
|
+
*/
|
62
|
+
for (i = 0;;i++)
|
63
|
+
{
|
64
|
+
sprintf(device, "/dev/bpf%d", i);
|
65
|
+
|
66
|
+
fd = open(device, O_RDWR);
|
67
|
+
if (fd == -1 && errno == EBUSY)
|
68
|
+
{
|
69
|
+
/*
|
70
|
+
* Device is busy.
|
71
|
+
*/
|
72
|
+
continue;
|
73
|
+
}
|
74
|
+
else
|
75
|
+
{
|
76
|
+
/*
|
77
|
+
* Either we've got a valid file descriptor, or errno is not
|
78
|
+
* EBUSY meaning we've probably run out of devices.
|
79
|
+
*/
|
80
|
+
break;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
if (fd == -1)
|
85
|
+
{
|
86
|
+
snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): (%s): %s\n",
|
87
|
+
__func__, device, strerror(errno));
|
88
|
+
}
|
89
|
+
return (fd);
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
int
|
94
|
+
libnet_open_link(libnet_t *l)
|
95
|
+
{
|
96
|
+
struct ifreq ifr;
|
97
|
+
struct bpf_version bv;
|
98
|
+
u_int v;
|
99
|
+
|
100
|
+
#if defined(BIOCGHDRCMPLT) && defined(BIOCSHDRCMPLT) && !(__APPLE__)
|
101
|
+
u_int spoof_eth_src = 1;
|
102
|
+
#endif
|
103
|
+
|
104
|
+
if (l == NULL)
|
105
|
+
{
|
106
|
+
return (-1);
|
107
|
+
}
|
108
|
+
|
109
|
+
if (l->device == NULL)
|
110
|
+
{
|
111
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): NULL device\n",
|
112
|
+
__func__);
|
113
|
+
goto bad;
|
114
|
+
}
|
115
|
+
|
116
|
+
l->fd = libnet_bpf_open(l->err_buf);
|
117
|
+
if (l->fd == -1)
|
118
|
+
{
|
119
|
+
goto bad;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Get bpf version.
|
124
|
+
*/
|
125
|
+
if (ioctl(l->fd, BIOCVERSION, (caddr_t)&bv) < 0)
|
126
|
+
{
|
127
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCVERSION: %s\n",
|
128
|
+
__func__, strerror(errno));
|
129
|
+
goto bad;
|
130
|
+
}
|
131
|
+
|
132
|
+
if (bv.bv_major != BPF_MAJOR_VERSION || bv.bv_minor < BPF_MINOR_VERSION)
|
133
|
+
{
|
134
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
135
|
+
"%s(): kernel bpf filter out of date\n", __func__);
|
136
|
+
goto bad;
|
137
|
+
}
|
138
|
+
|
139
|
+
/*
|
140
|
+
* Attach network interface to bpf device.
|
141
|
+
*/
|
142
|
+
strncpy(ifr.ifr_name, l->device, sizeof(ifr.ifr_name) - 1);
|
143
|
+
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
|
144
|
+
|
145
|
+
if (ioctl(l->fd, BIOCSETIF, (caddr_t)&ifr) == -1)
|
146
|
+
{
|
147
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCSETIF: (%s): %s\n",
|
148
|
+
__func__, l->device, strerror(errno));
|
149
|
+
goto bad;
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Get the data link-layer type.
|
154
|
+
*/
|
155
|
+
if (ioctl(l->fd, BIOCGDLT, (caddr_t)&v) == -1)
|
156
|
+
{
|
157
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCGDLT: %s\n",
|
158
|
+
__func__, strerror(errno));
|
159
|
+
goto bad;
|
160
|
+
}
|
161
|
+
|
162
|
+
/*
|
163
|
+
* NetBSD and FreeBSD BPF have an ioctl for enabling/disabling
|
164
|
+
* automatic filling of the link level source address.
|
165
|
+
*/
|
166
|
+
#if defined(BIOCGHDRCMPLT) && defined(BIOCSHDRCMPLT) && !(__APPLE__)
|
167
|
+
if (ioctl(l->fd, BIOCSHDRCMPLT, &spoof_eth_src) == -1)
|
168
|
+
{
|
169
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): BIOCSHDRCMPLT: %s\n",
|
170
|
+
__func__, strerror(errno));
|
171
|
+
goto bad;
|
172
|
+
}
|
173
|
+
#endif
|
174
|
+
|
175
|
+
/*
|
176
|
+
* Assign link type and offset.
|
177
|
+
*/
|
178
|
+
switch (v)
|
179
|
+
{
|
180
|
+
case DLT_SLIP:
|
181
|
+
l->link_offset = 0x10;
|
182
|
+
break;
|
183
|
+
case DLT_RAW:
|
184
|
+
l->link_offset = 0x0;
|
185
|
+
break;
|
186
|
+
case DLT_PPP:
|
187
|
+
l->link_offset = 0x04;
|
188
|
+
break;
|
189
|
+
case DLT_EN10MB:
|
190
|
+
default:
|
191
|
+
l->link_offset = 0xe; /* default to ethernet */
|
192
|
+
break;
|
193
|
+
}
|
194
|
+
#if _BSDI_VERSION - 0 >= 199510
|
195
|
+
switch (v)
|
196
|
+
{
|
197
|
+
case DLT_SLIP:
|
198
|
+
v = DLT_SLIP_BSDOS;
|
199
|
+
l->link_offset = 0x10;
|
200
|
+
break;
|
201
|
+
case DLT_PPP:
|
202
|
+
v = DLT_PPP_BSDOS;
|
203
|
+
l->link_offset = 0x04;
|
204
|
+
break;
|
205
|
+
}
|
206
|
+
#endif
|
207
|
+
l->link_type = v;
|
208
|
+
|
209
|
+
return (1);
|
210
|
+
|
211
|
+
bad:
|
212
|
+
if (l->fd > 0)
|
213
|
+
{
|
214
|
+
close(l->fd); /* this can fail ok */
|
215
|
+
}
|
216
|
+
return (-1);
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
int
|
221
|
+
libnet_close_link(libnet_t *l)
|
222
|
+
{
|
223
|
+
if (close(l->fd) == 0)
|
224
|
+
{
|
225
|
+
return (1);
|
226
|
+
}
|
227
|
+
else
|
228
|
+
{
|
229
|
+
return (-1);
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
int
|
235
|
+
libnet_write_link(libnet_t *l, u_int8_t *packet, u_int32_t size)
|
236
|
+
{
|
237
|
+
int c;
|
238
|
+
|
239
|
+
/* corey: move check for UID/EUID of 0 from libnet_init() to here */
|
240
|
+
if (getuid() && geteuid())
|
241
|
+
{
|
242
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
243
|
+
"%s(): UID or EUID of 0 required\n", __func__);
|
244
|
+
return -1;
|
245
|
+
}
|
246
|
+
|
247
|
+
if (l == NULL)
|
248
|
+
{
|
249
|
+
return (-1);
|
250
|
+
}
|
251
|
+
|
252
|
+
/* corey: open socket if necessary */
|
253
|
+
if (l->fd == -1) {
|
254
|
+
if (libnet_open_socket(l) == -1) {
|
255
|
+
return -1;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
c = write(l->fd, packet, size);
|
260
|
+
if (c != size)
|
261
|
+
{
|
262
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
263
|
+
"%s(): %d bytes written (%s)\n", __func__, c, strerror(errno));
|
264
|
+
}
|
265
|
+
return (c);
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
struct libnet_ether_addr *
|
270
|
+
libnet_get_hwaddr(libnet_t *l)
|
271
|
+
{
|
272
|
+
int mib[6];
|
273
|
+
size_t len;
|
274
|
+
int8_t *buf, *next, *end;
|
275
|
+
struct if_msghdr *ifm;
|
276
|
+
struct sockaddr_dl *sdl;
|
277
|
+
struct libnet_ether_addr *ea = NULL;
|
278
|
+
|
279
|
+
mib[0] = CTL_NET;
|
280
|
+
mib[1] = AF_ROUTE;
|
281
|
+
mib[2] = 0;
|
282
|
+
mib[3] = AF_LINK;
|
283
|
+
mib[4] = NET_RT_IFLIST;
|
284
|
+
mib[5] = 0;
|
285
|
+
|
286
|
+
if (l == NULL)
|
287
|
+
{
|
288
|
+
return (NULL);
|
289
|
+
}
|
290
|
+
|
291
|
+
if (l->device == NULL)
|
292
|
+
{
|
293
|
+
if (libnet_select_device(l) == -1)
|
294
|
+
{
|
295
|
+
/* err msg set in libnet_select_device */
|
296
|
+
return (NULL);
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1)
|
301
|
+
{
|
302
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): sysctl(): %s\n",
|
303
|
+
__func__, strerror(errno));
|
304
|
+
return (NULL);
|
305
|
+
}
|
306
|
+
|
307
|
+
buf = (int8_t *)malloc(len);
|
308
|
+
if (buf == NULL)
|
309
|
+
{
|
310
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n",
|
311
|
+
__func__, strerror(errno));
|
312
|
+
return (NULL);
|
313
|
+
}
|
314
|
+
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0)
|
315
|
+
{
|
316
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): sysctl(): %s\n",
|
317
|
+
__func__, strerror(errno));
|
318
|
+
free(buf);
|
319
|
+
return (NULL);
|
320
|
+
}
|
321
|
+
end = buf + len;
|
322
|
+
|
323
|
+
for (next = buf ; next < end ; next += ifm->ifm_msglen)
|
324
|
+
{
|
325
|
+
ifm = (struct if_msghdr *)next;
|
326
|
+
if (ifm->ifm_type == RTM_IFINFO)
|
327
|
+
{
|
328
|
+
sdl = (struct sockaddr_dl *)(ifm + 1);
|
329
|
+
if (strncmp(&sdl->sdl_data[0], l->device, sdl->sdl_nlen) == 0)
|
330
|
+
{
|
331
|
+
if (!(ea = malloc(sizeof(struct libnet_ether_addr))))
|
332
|
+
{
|
333
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
334
|
+
"%s(): malloc(): %s", __func__, strerror(errno));
|
335
|
+
free(buf);
|
336
|
+
return (NULL);
|
337
|
+
}
|
338
|
+
memcpy(ea->ether_addr_octet, LLADDR(sdl), ETHER_ADDR_LEN);
|
339
|
+
break;
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
free(buf);
|
344
|
+
return (ea);
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
/* EOF */
|