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,785 @@
|
|
1
|
+
/*
|
2
|
+
* $Id: libnet_link_dlpi.c,v 1.8 2004/01/28 19:45:00 mike Exp $
|
3
|
+
*
|
4
|
+
* libnet
|
5
|
+
* libnet_dlpi.c - dlpi 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, 1997
|
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
|
+
* This code contributed by Atanu Ghosh (atanu@cs.ucl.ac.uk),
|
30
|
+
* University College London.
|
31
|
+
*/
|
32
|
+
|
33
|
+
|
34
|
+
#if (HAVE_CONFIG_H)
|
35
|
+
#include "../include/config.h"
|
36
|
+
#endif
|
37
|
+
#include <sys/types.h>
|
38
|
+
#include <sys/time.h>
|
39
|
+
#ifdef HAVE_SYS_BUFMOD_H
|
40
|
+
#include <sys/bufmod.h>
|
41
|
+
#endif
|
42
|
+
#include <sys/dlpi.h>
|
43
|
+
#ifdef HAVE_HPUX9
|
44
|
+
#include <sys/socket.h>
|
45
|
+
#endif
|
46
|
+
#ifdef DL_HP_PPA_ACK_OBS
|
47
|
+
#include <sys/stat.h>
|
48
|
+
#endif
|
49
|
+
#include <sys/stream.h>
|
50
|
+
#if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
|
51
|
+
#include <sys/systeminfo.h>
|
52
|
+
#endif
|
53
|
+
|
54
|
+
#ifdef HAVE_SYS_DLPI_EXT_H
|
55
|
+
#include <sys/dlpi_ext.h>
|
56
|
+
#endif
|
57
|
+
|
58
|
+
#ifdef HAVE_HPUX9
|
59
|
+
#include <net/if.h>
|
60
|
+
#endif
|
61
|
+
|
62
|
+
#include <ctype.h>
|
63
|
+
#ifdef HAVE_HPUX9
|
64
|
+
#include <nlist.h>
|
65
|
+
#include <dlpi_ext.h>
|
66
|
+
#endif
|
67
|
+
#include <errno.h>
|
68
|
+
#include <fcntl.h>
|
69
|
+
#include <memory.h>
|
70
|
+
#include <stdio.h>
|
71
|
+
#include <stdlib.h>
|
72
|
+
#include <string.h>
|
73
|
+
#include <stropts.h>
|
74
|
+
#include <unistd.h>
|
75
|
+
|
76
|
+
#include "../include/libnet.h"
|
77
|
+
#include "../include/bpf.h"
|
78
|
+
|
79
|
+
#include "../include/gnuc.h"
|
80
|
+
#ifdef HAVE_OS_PROTO_H
|
81
|
+
#include "../include/os-proto.h"
|
82
|
+
#endif
|
83
|
+
|
84
|
+
#ifndef DLPI_DEV_PREFIX
|
85
|
+
#define DLPI_DEV_PREFIX "/dev"
|
86
|
+
#endif
|
87
|
+
|
88
|
+
#define MAXDLBUF 8192
|
89
|
+
|
90
|
+
/* Forwards */
|
91
|
+
static int dlattachreq(int, bpf_u_int32, int8_t *);
|
92
|
+
static int dlbindack(int, int8_t *, int8_t *);
|
93
|
+
static int dlbindreq(int, bpf_u_int32, int8_t *);
|
94
|
+
static int dlinfoack(int, int8_t *, int8_t *);
|
95
|
+
static int dlinforeq(int, int8_t *);
|
96
|
+
static int dlokack(int, const int8_t *, int8_t *, int8_t *);
|
97
|
+
static int recv_ack(int, int, const int8_t *, int8_t *, int8_t *);
|
98
|
+
static int send_request(int, int8_t *, int, int8_t *, int8_t *, int);
|
99
|
+
#ifdef HAVE_SYS_BUFMOD_H
|
100
|
+
static int strioctl(int, int, int, int8_t *);
|
101
|
+
#endif
|
102
|
+
#ifdef HAVE_HPUX9
|
103
|
+
static int dlpi_kread(int, off_t, void *, u_int, int8_t *);
|
104
|
+
#endif
|
105
|
+
#ifdef HAVE_DEV_DLPI
|
106
|
+
static int get_dlpi_ppa(int, const int8_t *, int, int8_t *);
|
107
|
+
#endif
|
108
|
+
|
109
|
+
/* XXX Needed by HP-UX (at least) */
|
110
|
+
static bpf_u_int32 ctlbuf[MAXDLBUF];
|
111
|
+
|
112
|
+
|
113
|
+
int
|
114
|
+
libnet_open_link(libnet_t *l)
|
115
|
+
{
|
116
|
+
register int8_t *cp;
|
117
|
+
int8_t *eos;
|
118
|
+
register int ppa;
|
119
|
+
register dl_info_ack_t *infop;
|
120
|
+
bpf_u_int32 buf[MAXDLBUF];
|
121
|
+
int8_t dname[100];
|
122
|
+
#ifndef HAVE_DEV_DLPI
|
123
|
+
int8_t dname2[100];
|
124
|
+
#endif
|
125
|
+
|
126
|
+
if (l == NULL)
|
127
|
+
{
|
128
|
+
return (-1);
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
* Determine device and ppa
|
133
|
+
*/
|
134
|
+
cp = strpbrk(l->device, "0123456789");
|
135
|
+
if (cp == NULL)
|
136
|
+
{
|
137
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
138
|
+
"%s(): %s is missing unit number\n", __func__, l->device);
|
139
|
+
goto bad;
|
140
|
+
}
|
141
|
+
ppa = strtol(cp, &eos, 10);
|
142
|
+
if (*eos != '\0')
|
143
|
+
{
|
144
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
145
|
+
"%s(): %s bad unit number\n", __func__, l->device);
|
146
|
+
goto bad;
|
147
|
+
}
|
148
|
+
|
149
|
+
if (*(l->device) == '/')
|
150
|
+
{
|
151
|
+
memset(&dname, 0, sizeof(dname));
|
152
|
+
strncpy(dname, l->device, sizeof(dname) - 1);
|
153
|
+
dname[sizeof(dname) - 1] = '\0';
|
154
|
+
}
|
155
|
+
else
|
156
|
+
{
|
157
|
+
sprintf(dname, "%s/%s", DLPI_DEV_PREFIX, l->device);
|
158
|
+
}
|
159
|
+
#ifdef HAVE_DEV_DLPI
|
160
|
+
/*
|
161
|
+
* Map network device to /dev/dlpi unit
|
162
|
+
*/
|
163
|
+
cp = "/dev/dlpi";
|
164
|
+
|
165
|
+
l->fd = open(cp, O_RDWR);
|
166
|
+
if (l->fd == -1)
|
167
|
+
{
|
168
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s\n",
|
169
|
+
__func__, cp, strerror(errno));
|
170
|
+
goto bad;
|
171
|
+
}
|
172
|
+
|
173
|
+
/*
|
174
|
+
* Map network interface to /dev/dlpi unit
|
175
|
+
*/
|
176
|
+
ppa = get_dlpi_ppa(l->fd, dname, ppa, l->err_buf);
|
177
|
+
if (ppa < 0)
|
178
|
+
{
|
179
|
+
goto bad;
|
180
|
+
}
|
181
|
+
#else
|
182
|
+
/*
|
183
|
+
* Try device without unit number
|
184
|
+
*/
|
185
|
+
strcpy(dname2, dname);
|
186
|
+
cp = strchr(dname, *cp);
|
187
|
+
*cp = '\0';
|
188
|
+
|
189
|
+
l->fd = open(dname, O_RDWR);
|
190
|
+
if (l->fd == -1)
|
191
|
+
{
|
192
|
+
if (errno != ENOENT)
|
193
|
+
{
|
194
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s\n",
|
195
|
+
__func__, dname, strerror(errno));
|
196
|
+
goto bad;
|
197
|
+
}
|
198
|
+
|
199
|
+
/*
|
200
|
+
* Try again with unit number
|
201
|
+
*/
|
202
|
+
l->fd = open(dname2, O_RDWR);
|
203
|
+
if (l->fd == -1)
|
204
|
+
{
|
205
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): open(): %s: %s\n",
|
206
|
+
__func__, dname2, strerror(errno));
|
207
|
+
goto bad;
|
208
|
+
}
|
209
|
+
|
210
|
+
cp = dname2;
|
211
|
+
while (*cp && !isdigit((int)*cp))
|
212
|
+
{
|
213
|
+
cp++;
|
214
|
+
}
|
215
|
+
if (*cp)
|
216
|
+
{
|
217
|
+
ppa = atoi(cp);
|
218
|
+
}
|
219
|
+
else
|
220
|
+
/*
|
221
|
+
* XXX Assume unit zero
|
222
|
+
*/
|
223
|
+
ppa = 0;
|
224
|
+
}
|
225
|
+
#endif
|
226
|
+
/*
|
227
|
+
* Attach if "style 2" provider
|
228
|
+
*/
|
229
|
+
if (dlinforeq(l->fd, l->err_buf) < 0 ||
|
230
|
+
dlinfoack(l->fd, (int8_t *)buf, l->err_buf) < 0)
|
231
|
+
{
|
232
|
+
goto bad;
|
233
|
+
}
|
234
|
+
infop = &((union DL_primitives *)buf)->info_ack;
|
235
|
+
if (infop->dl_provider_style == DL_STYLE2 &&
|
236
|
+
(dlattachreq(l->fd, ppa, l->err_buf)
|
237
|
+
< 0 || dlokack(l->fd, "attach", (int8_t *)buf, l->err_buf) < 0))
|
238
|
+
{
|
239
|
+
goto bad;
|
240
|
+
}
|
241
|
+
|
242
|
+
/*
|
243
|
+
* Bind HP-UX 9 and HP-UX 10.20
|
244
|
+
*/
|
245
|
+
#if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20) || defined(HAVE_HPUX11) || defined(HAVE_SOLARIS)
|
246
|
+
if (dlbindreq(l->fd, 0, l->err_buf) < 0 ||
|
247
|
+
dlbindack(l->fd, (int8_t *)buf, l->err_buf) < 0)
|
248
|
+
{
|
249
|
+
goto bad;
|
250
|
+
}
|
251
|
+
#endif
|
252
|
+
|
253
|
+
/*
|
254
|
+
* Determine link type
|
255
|
+
*/
|
256
|
+
if (dlinforeq(l->fd, l->err_buf) < 0 ||
|
257
|
+
dlinfoack(l->fd, (int8_t *)buf, l->err_buf) < 0)
|
258
|
+
{
|
259
|
+
goto bad;
|
260
|
+
}
|
261
|
+
|
262
|
+
infop = &((union DL_primitives *)buf)->info_ack;
|
263
|
+
switch (infop->dl_mac_type)
|
264
|
+
{
|
265
|
+
case DL_CSMACD:
|
266
|
+
case DL_ETHER:
|
267
|
+
l->link_type = DLT_EN10MB;
|
268
|
+
l->link_offset = 0xe;
|
269
|
+
break;
|
270
|
+
case DL_FDDI:
|
271
|
+
l->link_type = DLT_FDDI;
|
272
|
+
l->link_offset = 0x15;
|
273
|
+
break;
|
274
|
+
case DL_TPR:
|
275
|
+
l->link_type = DLT_PRONET;
|
276
|
+
l->link_offset = 0x16;
|
277
|
+
break;
|
278
|
+
default:
|
279
|
+
sprintf(l->err_buf, "%s(): unknown mac type 0x%lu\n", __func__,
|
280
|
+
(u_int32_t) infop->dl_mac_type);
|
281
|
+
goto bad;
|
282
|
+
}
|
283
|
+
|
284
|
+
#ifdef DLIOCRAW
|
285
|
+
/*
|
286
|
+
* This is a non standard SunOS hack to get the ethernet header.
|
287
|
+
*/
|
288
|
+
if (strioctl(l->fd, DLIOCRAW, 0, NULL) < 0)
|
289
|
+
{
|
290
|
+
sprintf(l->err_buf, "%s(): DLIOCRAW: %s\n", __func__, strerror(errno));
|
291
|
+
goto bad;
|
292
|
+
}
|
293
|
+
#endif
|
294
|
+
|
295
|
+
return (1);
|
296
|
+
bad:
|
297
|
+
if (l->fd > 0)
|
298
|
+
{
|
299
|
+
close(l->fd); /* this can fail ok */
|
300
|
+
}
|
301
|
+
return (-1);
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
static int
|
306
|
+
send_request(int fd, int8_t *ptr, int len, int8_t *what, int8_t *ebuf,
|
307
|
+
int flags)
|
308
|
+
{
|
309
|
+
struct strbuf ctl;
|
310
|
+
|
311
|
+
ctl.maxlen = 0;
|
312
|
+
ctl.len = len;
|
313
|
+
ctl.buf = ptr;
|
314
|
+
|
315
|
+
if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0)
|
316
|
+
{
|
317
|
+
sprintf(ebuf, "%s(): putmsg \"%s\": %s\n", __func__, what,
|
318
|
+
strerror(errno));
|
319
|
+
return (-1);
|
320
|
+
}
|
321
|
+
return (0);
|
322
|
+
}
|
323
|
+
|
324
|
+
static int
|
325
|
+
recv_ack(int fd, int size, const int8_t *what, int8_t *bufp, int8_t *ebuf)
|
326
|
+
{
|
327
|
+
union DL_primitives *dlp;
|
328
|
+
struct strbuf ctl;
|
329
|
+
int flags;
|
330
|
+
|
331
|
+
ctl.maxlen = MAXDLBUF;
|
332
|
+
ctl.len = 0;
|
333
|
+
ctl.buf = bufp;
|
334
|
+
|
335
|
+
flags = 0;
|
336
|
+
if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0)
|
337
|
+
{
|
338
|
+
sprintf(ebuf, "%s(): %s getmsg: %s\n", __func__, what, strerror(errno));
|
339
|
+
return (-1);
|
340
|
+
}
|
341
|
+
|
342
|
+
dlp = (union DL_primitives *)ctl.buf;
|
343
|
+
switch (dlp->dl_primitive)
|
344
|
+
{
|
345
|
+
case DL_INFO_ACK:
|
346
|
+
case DL_PHYS_ADDR_ACK:
|
347
|
+
case DL_BIND_ACK:
|
348
|
+
case DL_OK_ACK:
|
349
|
+
#ifdef DL_HP_PPA_ACK
|
350
|
+
case DL_HP_PPA_ACK:
|
351
|
+
#endif
|
352
|
+
/*
|
353
|
+
* These are OK
|
354
|
+
*/
|
355
|
+
break;
|
356
|
+
|
357
|
+
case DL_ERROR_ACK:
|
358
|
+
switch (dlp->error_ack.dl_errno)
|
359
|
+
{
|
360
|
+
case DL_BADPPA:
|
361
|
+
sprintf(ebuf, "recv_ack: %s bad ppa (device unit)", what);
|
362
|
+
break;
|
363
|
+
case DL_SYSERR:
|
364
|
+
sprintf(ebuf, "recv_ack: %s: %s",
|
365
|
+
what, strerror(dlp->error_ack.dl_unix_errno));
|
366
|
+
break;
|
367
|
+
case DL_UNSUPPORTED:
|
368
|
+
sprintf(ebuf,
|
369
|
+
"recv_ack: %s: Service not supplied by provider", what);
|
370
|
+
break;
|
371
|
+
default:
|
372
|
+
sprintf(ebuf, "recv_ack: %s error 0x%x", what,
|
373
|
+
(bpf_u_int32)dlp->error_ack.dl_errno);
|
374
|
+
break;
|
375
|
+
}
|
376
|
+
return (-1);
|
377
|
+
|
378
|
+
default:
|
379
|
+
sprintf(ebuf, "recv_ack: %s unexpected primitive ack 0x%x ",
|
380
|
+
what, (bpf_u_int32)dlp->dl_primitive);
|
381
|
+
return (-1);
|
382
|
+
}
|
383
|
+
|
384
|
+
if (ctl.len < size)
|
385
|
+
{
|
386
|
+
sprintf(ebuf, "recv_ack: %s ack too small (%d < %d)",
|
387
|
+
what, ctl.len, size);
|
388
|
+
return (-1);
|
389
|
+
}
|
390
|
+
return (ctl.len);
|
391
|
+
}
|
392
|
+
|
393
|
+
static int
|
394
|
+
dlattachreq(int fd, bpf_u_int32 ppa, int8_t *ebuf)
|
395
|
+
{
|
396
|
+
dl_attach_req_t req;
|
397
|
+
|
398
|
+
req.dl_primitive = DL_ATTACH_REQ;
|
399
|
+
req.dl_ppa = ppa;
|
400
|
+
|
401
|
+
return (send_request(fd, (int8_t *)&req, sizeof(req), "attach", ebuf, 0));
|
402
|
+
}
|
403
|
+
|
404
|
+
static int
|
405
|
+
dlbindreq(int fd, bpf_u_int32 sap, int8_t *ebuf)
|
406
|
+
{
|
407
|
+
|
408
|
+
dl_bind_req_t req;
|
409
|
+
|
410
|
+
memset((int8_t *)&req, 0, sizeof(req));
|
411
|
+
req.dl_primitive = DL_BIND_REQ;
|
412
|
+
#ifdef DL_HP_RAWDLS
|
413
|
+
req.dl_max_conind = 1; /* XXX magic number */
|
414
|
+
/*
|
415
|
+
* 22 is INSAP as per the HP-UX DLPI Programmer's Guide
|
416
|
+
*/
|
417
|
+
req.dl_sap = 22;
|
418
|
+
req.dl_service_mode = DL_HP_RAWDLS;
|
419
|
+
#else
|
420
|
+
req.dl_sap = sap;
|
421
|
+
#ifdef DL_CLDLS
|
422
|
+
req.dl_service_mode = DL_CLDLS;
|
423
|
+
#endif
|
424
|
+
#endif
|
425
|
+
return (send_request(fd, (int8_t *)&req, sizeof(req), "bind", ebuf, 0));
|
426
|
+
}
|
427
|
+
|
428
|
+
static int
|
429
|
+
dlbindack(int fd, int8_t *bufp, int8_t *ebuf)
|
430
|
+
{
|
431
|
+
return (recv_ack(fd, DL_BIND_ACK_SIZE, "bind", bufp, ebuf));
|
432
|
+
}
|
433
|
+
|
434
|
+
static int
|
435
|
+
dlokack(int fd, const int8_t *what, int8_t *bufp, int8_t *ebuf)
|
436
|
+
{
|
437
|
+
return (recv_ack(fd, DL_OK_ACK_SIZE, what, bufp, ebuf));
|
438
|
+
}
|
439
|
+
|
440
|
+
static int
|
441
|
+
dlinforeq(int fd, int8_t *ebuf)
|
442
|
+
{
|
443
|
+
dl_info_req_t req;
|
444
|
+
|
445
|
+
req.dl_primitive = DL_INFO_REQ;
|
446
|
+
|
447
|
+
return (send_request(fd, (int8_t *)&req, sizeof(req), "info", ebuf,
|
448
|
+
RS_HIPRI));
|
449
|
+
}
|
450
|
+
|
451
|
+
static int
|
452
|
+
dlinfoack(int fd, int8_t *bufp, int8_t *ebuf)
|
453
|
+
{
|
454
|
+
return (recv_ack(fd, DL_INFO_ACK_SIZE, "info", bufp, ebuf));
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
#ifdef HAVE_SYS_BUFMOD_H
|
459
|
+
static int
|
460
|
+
strioctl(int fd, int cmd, int len, int8_t *dp)
|
461
|
+
{
|
462
|
+
struct strioctl str;
|
463
|
+
int rc;
|
464
|
+
|
465
|
+
str.ic_cmd = cmd;
|
466
|
+
str.ic_timout = -1;
|
467
|
+
str.ic_len = len;
|
468
|
+
str.ic_dp = dp;
|
469
|
+
|
470
|
+
rc = ioctl(fd, I_STR, &str);
|
471
|
+
if (rc < 0)
|
472
|
+
{
|
473
|
+
return (rc);
|
474
|
+
}
|
475
|
+
else
|
476
|
+
{
|
477
|
+
return (str.ic_len);
|
478
|
+
}
|
479
|
+
}
|
480
|
+
#endif
|
481
|
+
|
482
|
+
|
483
|
+
#if (defined(DL_HP_PPA_ACK_OBS) && !defined(HAVE_HPUX11))
|
484
|
+
/*
|
485
|
+
* Under HP-UX 10, we can ask for the ppa
|
486
|
+
*/
|
487
|
+
static int
|
488
|
+
get_dlpi_ppa(register int fd, register const int8_t *device, register int unit,
|
489
|
+
register int8_t *ebuf)
|
490
|
+
{
|
491
|
+
register dl_hp_ppa_ack_t *ap;
|
492
|
+
register dl_hp_ppa_info_t *ip;
|
493
|
+
register int i;
|
494
|
+
register u_int32_t majdev;
|
495
|
+
dl_hp_ppa_req_t req;
|
496
|
+
struct stat statbuf;
|
497
|
+
bpf_u_int32 buf[MAXDLBUF];
|
498
|
+
|
499
|
+
if (stat(device, &statbuf) < 0)
|
500
|
+
{
|
501
|
+
sprintf(ebuf, "stat: %s: %s", device, strerror(errno));
|
502
|
+
return (-1);
|
503
|
+
}
|
504
|
+
majdev = major(statbuf.st_rdev);
|
505
|
+
|
506
|
+
memset((int8_t *)&req, 0, sizeof(req));
|
507
|
+
req.dl_primitive = DL_HP_PPA_REQ;
|
508
|
+
|
509
|
+
memset((int8_t *)buf, 0, sizeof(buf));
|
510
|
+
if (send_request(fd, (int8_t *)&req, sizeof(req), "hpppa", ebuf, 0) < 0 ||
|
511
|
+
recv_ack(fd, DL_HP_PPA_ACK_SIZE, "hpppa", (int8_t *)buf, ebuf) < 0)
|
512
|
+
{
|
513
|
+
return (-1);
|
514
|
+
}
|
515
|
+
|
516
|
+
ap = (dl_hp_ppa_ack_t *)buf;
|
517
|
+
ip = (dl_hp_ppa_info_t *)((u_int8_t *)ap + ap->dl_offset);
|
518
|
+
|
519
|
+
for (i = 0; i < ap->dl_count; i++)
|
520
|
+
{
|
521
|
+
if (ip->dl_mjr_num == majdev && ip->dl_instance_num == unit)
|
522
|
+
break;
|
523
|
+
|
524
|
+
ip = (dl_hp_ppa_info_t *)((u_int8_t *)ip + ip->dl_next_offset);
|
525
|
+
}
|
526
|
+
|
527
|
+
if (i == ap->dl_count)
|
528
|
+
{
|
529
|
+
sprintf(ebuf, "can't find PPA for %s", device);
|
530
|
+
return (-1);
|
531
|
+
}
|
532
|
+
|
533
|
+
if (ip->dl_hdw_state == HDW_DEAD)
|
534
|
+
{
|
535
|
+
sprintf(ebuf, "%s: hardware state: DOWN\n", device);
|
536
|
+
return (-1);
|
537
|
+
}
|
538
|
+
return ((int)ip->dl_ppa);
|
539
|
+
}
|
540
|
+
#endif
|
541
|
+
|
542
|
+
#ifdef HAVE_HPUX9
|
543
|
+
/*
|
544
|
+
* Under HP-UX 9, there is no good way to determine the ppa.
|
545
|
+
* So punt and read it from /dev/kmem.
|
546
|
+
*/
|
547
|
+
static struct nlist nl[] =
|
548
|
+
{
|
549
|
+
#define NL_IFNET 0
|
550
|
+
{ "ifnet" },
|
551
|
+
{ "" }
|
552
|
+
};
|
553
|
+
|
554
|
+
static int8_t path_vmunix[] = "/hp-ux";
|
555
|
+
|
556
|
+
/*
|
557
|
+
* Determine ppa number that specifies ifname
|
558
|
+
*/
|
559
|
+
static int
|
560
|
+
get_dlpi_ppa(register int fd, register const int8_t *ifname, register int unit,
|
561
|
+
register int8_t *ebuf)
|
562
|
+
{
|
563
|
+
register const int8_t *cp;
|
564
|
+
register int kd;
|
565
|
+
void *addr;
|
566
|
+
struct ifnet ifnet;
|
567
|
+
int8_t if_name[sizeof(ifnet.if_name)], tifname[32];
|
568
|
+
|
569
|
+
cp = strrchr(ifname, '/');
|
570
|
+
if (cp != NULL)
|
571
|
+
{
|
572
|
+
ifname = cp + 1;
|
573
|
+
}
|
574
|
+
if (nlist(path_vmunix, &nl) < 0)
|
575
|
+
{
|
576
|
+
sprintf(ebuf, "nlist %s failed", path_vmunix);
|
577
|
+
return (-1);
|
578
|
+
}
|
579
|
+
|
580
|
+
if (nl[NL_IFNET].n_value == 0)
|
581
|
+
{
|
582
|
+
sprintf(ebuf, "could't find %s kernel symbol", nl[NL_IFNET].n_name);
|
583
|
+
return (-1);
|
584
|
+
}
|
585
|
+
|
586
|
+
kd = open("/dev/kmem", O_RDONLY);
|
587
|
+
if (kd < 0)
|
588
|
+
{
|
589
|
+
sprintf(ebuf, "kmem open: %s", strerror(errno));
|
590
|
+
return (-1);
|
591
|
+
}
|
592
|
+
|
593
|
+
if (dlpi_kread(kd, nl[NL_IFNET].n_value, &addr, sizeof(addr), ebuf) < 0)
|
594
|
+
{
|
595
|
+
close(kd);
|
596
|
+
return (-1);
|
597
|
+
}
|
598
|
+
for (; addr != NULL; addr = ifnet.if_next)
|
599
|
+
{
|
600
|
+
if (dlpi_kread(kd, (off_t)addr, &ifnet, sizeof(ifnet), ebuf) < 0 ||
|
601
|
+
dlpi_kread(kd, (off_t)ifnet.if_name,
|
602
|
+
if_name, sizeof(if_name), ebuf) < 0)
|
603
|
+
{
|
604
|
+
close(kd);
|
605
|
+
return (-1);
|
606
|
+
}
|
607
|
+
sprintf(tifname, "%.*s%d",
|
608
|
+
(int)sizeof(if_name), if_name, ifnet.if_unit);
|
609
|
+
if (strcmp(tifname, ifname) == 0)
|
610
|
+
{
|
611
|
+
return (ifnet.if_index);
|
612
|
+
}
|
613
|
+
}
|
614
|
+
|
615
|
+
sprintf(ebuf, "Can't find %s", ifname);
|
616
|
+
return (-1);
|
617
|
+
}
|
618
|
+
|
619
|
+
static int
|
620
|
+
dlpi_kread(register int fd, register off_t addr, register void *buf,
|
621
|
+
register u_int len, register int8_t *ebuf)
|
622
|
+
{
|
623
|
+
register int cc;
|
624
|
+
|
625
|
+
if (lseek(fd, addr, SEEK_SET) < 0)
|
626
|
+
{
|
627
|
+
sprintf(ebuf, "lseek: %s", strerror(errno));
|
628
|
+
return (-1);
|
629
|
+
}
|
630
|
+
cc = read(fd, buf, len);
|
631
|
+
if (cc < 0)
|
632
|
+
{
|
633
|
+
sprintf(ebuf, "read: %s", strerror(errno));
|
634
|
+
return (-1);
|
635
|
+
}
|
636
|
+
else if (cc != len)
|
637
|
+
{
|
638
|
+
sprintf(ebuf, "int16_t read (%d != %d)", cc, len);
|
639
|
+
return (-1);
|
640
|
+
}
|
641
|
+
return (cc);
|
642
|
+
}
|
643
|
+
#endif
|
644
|
+
|
645
|
+
#define ETHERADDRL 6
|
646
|
+
struct EnetHeaderInfo
|
647
|
+
{
|
648
|
+
struct libnet_ether_addr DestEtherAddr;
|
649
|
+
u_int16_t EtherFrameType;
|
650
|
+
};
|
651
|
+
|
652
|
+
|
653
|
+
int
|
654
|
+
libnet_close_link(libnet_t *l)
|
655
|
+
{
|
656
|
+
if (close(l->fd) == 0)
|
657
|
+
{
|
658
|
+
free(l);
|
659
|
+
return (1);
|
660
|
+
}
|
661
|
+
else
|
662
|
+
{
|
663
|
+
free(l);
|
664
|
+
return (-1);
|
665
|
+
}
|
666
|
+
}
|
667
|
+
|
668
|
+
#ifdef HAVE_HPUX11
|
669
|
+
int
|
670
|
+
libnet_write_link(libnet_t *l, u_int8_t *packet, u_int32_t size)
|
671
|
+
{
|
672
|
+
struct strbuf data, ctl;
|
673
|
+
dl_hp_rawdata_req_t *rdata;
|
674
|
+
int c;
|
675
|
+
|
676
|
+
/* corey: move check for UID/EUID of 0 from libnet_init() to here */
|
677
|
+
if (getuid() && geteuid())
|
678
|
+
{
|
679
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
680
|
+
"%s(): UID or EUID of 0 required\n", __func__);
|
681
|
+
return -1;
|
682
|
+
}
|
683
|
+
|
684
|
+
if (l == NULL)
|
685
|
+
{
|
686
|
+
return (-1);
|
687
|
+
}
|
688
|
+
|
689
|
+
/* corey: open socket if necessary */
|
690
|
+
if (l->fd == -1) {
|
691
|
+
if (libnet_open_socket(l) == -1) {
|
692
|
+
return -1;
|
693
|
+
}
|
694
|
+
}
|
695
|
+
|
696
|
+
rdata = (dl_hp_rawdata_req_t *)ctlbuf;
|
697
|
+
rdata->dl_primitive = DL_HP_RAWDATA_REQ;
|
698
|
+
|
699
|
+
/* send it */
|
700
|
+
ctl.len = sizeof(dl_hp_rawdata_req_t);
|
701
|
+
ctl.maxlen = sizeof(dl_hp_rawdata_req_t);
|
702
|
+
ctl.buf = (int8_t *)rdata;
|
703
|
+
|
704
|
+
data.maxlen = size;
|
705
|
+
data.len = size;
|
706
|
+
data.buf = packet;
|
707
|
+
|
708
|
+
c = putmsg(l->fd, &ctl, &data, 0);
|
709
|
+
if (c == -1)
|
710
|
+
{
|
711
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
712
|
+
"libnet_write_link(): %d bytes written (%s)\n", c,
|
713
|
+
strerror(errno));
|
714
|
+
return (-1);
|
715
|
+
}
|
716
|
+
else
|
717
|
+
{
|
718
|
+
return (size);
|
719
|
+
}
|
720
|
+
}
|
721
|
+
#else
|
722
|
+
int
|
723
|
+
libnet_write_link(libnet_t *l, u_int8_t *packet, u_int32_t size)
|
724
|
+
{
|
725
|
+
int c;
|
726
|
+
struct strbuf data;
|
727
|
+
|
728
|
+
if (l == NULL)
|
729
|
+
{
|
730
|
+
return (-1);
|
731
|
+
}
|
732
|
+
|
733
|
+
data.maxlen = size;
|
734
|
+
data.len = size;
|
735
|
+
data.buf = packet;
|
736
|
+
|
737
|
+
c = putmsg(l->fd, NULL, &data, 0);
|
738
|
+
if (c == -1)
|
739
|
+
{
|
740
|
+
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
|
741
|
+
"libnet_write_link: %d bytes written (%s)\n", c,
|
742
|
+
strerror(errno));
|
743
|
+
return (-1);
|
744
|
+
}
|
745
|
+
else
|
746
|
+
{
|
747
|
+
return (size);
|
748
|
+
}
|
749
|
+
}
|
750
|
+
#endif
|
751
|
+
|
752
|
+
struct libnet_ether_addr *
|
753
|
+
libnet_get_hwaddr(libnet_t *l)
|
754
|
+
{
|
755
|
+
int8_t buf[2048];
|
756
|
+
union DL_primitives *dlp;
|
757
|
+
struct libnet_ether_addr *eap;
|
758
|
+
|
759
|
+
if (l == NULL)
|
760
|
+
{
|
761
|
+
return (NULL);
|
762
|
+
}
|
763
|
+
|
764
|
+
dlp = (union DL_primitives *)buf;
|
765
|
+
|
766
|
+
dlp->physaddr_req.dl_primitive = DL_PHYS_ADDR_REQ;
|
767
|
+
dlp->physaddr_req.dl_addr_type = DL_CURR_PHYS_ADDR;
|
768
|
+
|
769
|
+
if (send_request(l->fd, (int8_t *)dlp, DL_PHYS_ADDR_REQ_SIZE, "physaddr",
|
770
|
+
l->err_buf, 0) < 0)
|
771
|
+
{
|
772
|
+
return (NULL);
|
773
|
+
}
|
774
|
+
if (recv_ack(l->fd, DL_PHYS_ADDR_ACK_SIZE, "physaddr", (int8_t *)dlp,
|
775
|
+
l->err_buf) < 0)
|
776
|
+
{
|
777
|
+
return (NULL);
|
778
|
+
}
|
779
|
+
|
780
|
+
eap = (struct libnet_ether_addr *)
|
781
|
+
((int8_t *) dlp + dlp->physaddr_ack.dl_addr_offset);
|
782
|
+
return (eap);
|
783
|
+
}
|
784
|
+
|
785
|
+
/* EOF */
|