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
data/ext/libnet.c
ADDED
@@ -0,0 +1,705 @@
|
|
1
|
+
#include <arpa/inet.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include <stdlib.h>
|
4
|
+
#include <ruby.h>
|
5
|
+
#include <libnet.h>
|
6
|
+
|
7
|
+
VALUE cLibnet;
|
8
|
+
|
9
|
+
extern void define_ipv4_methods(void);
|
10
|
+
extern void define_ipv6_methods(void);
|
11
|
+
extern void define_udp_methods(void);
|
12
|
+
extern void define_ipv4_methods(void);
|
13
|
+
extern void define_ethernet_methods(void);
|
14
|
+
extern void define_vlan_methods(void);
|
15
|
+
extern void define_arp_methods(void);
|
16
|
+
|
17
|
+
/* call-seq:
|
18
|
+
* Libnet.new(injection_type=:raw4, device=nil) # -> a new Libnet object
|
19
|
+
*
|
20
|
+
* Creates a new Libnet object. The +injection_type+ parameter defines
|
21
|
+
* how the constructed packet get injected into the network.
|
22
|
+
*
|
23
|
+
* If +injection_type+ is <tt>:link</tt>, the packet gets injected at the data
|
24
|
+
* link layer (which provides more granular control over the IP layer). If
|
25
|
+
* +injection_type+ is <tt>:link</tt> and +device+ is not +nil+, Libnet
|
26
|
+
* attempts to use the specified network device for packet injection. The
|
27
|
+
* +device+ parameter is either a canonical string that references the device
|
28
|
+
* (such as "eth0" for a 100MB Ethernet card on Linux or "fxp0" for a 100MB
|
29
|
+
* Ethernet card on OpenBSD) or the dotted decimal representation of the
|
30
|
+
* device's IP address (e.g. 192.168.0.1). If +device+ is +nil+, Libnet
|
31
|
+
* attempts to find a suitable device to use.
|
32
|
+
*
|
33
|
+
* If +injection_type+ is <tt>:raw4</tt>, the packet gets injected using a raw
|
34
|
+
* socket interface.
|
35
|
+
*/
|
36
|
+
static VALUE net_s_new(int argc, VALUE *argv, VALUE self)
|
37
|
+
{
|
38
|
+
libnet_t *l;
|
39
|
+
VALUE obj;
|
40
|
+
char errbuf[LIBNET_ERRBUF_SIZE];
|
41
|
+
int inj_type = LIBNET_RAW4_ADV;
|
42
|
+
char *inj_str = NULL;
|
43
|
+
size_t inj_str_len = 0;
|
44
|
+
char *dev_str = NULL;
|
45
|
+
|
46
|
+
/* get the injection type */
|
47
|
+
if (argc > 0) {
|
48
|
+
switch (TYPE(argv[0])) {
|
49
|
+
case T_STRING:
|
50
|
+
inj_str = RSTRING(argv[0])->ptr;
|
51
|
+
inj_str_len = RSTRING(argv[0])->len;
|
52
|
+
break;
|
53
|
+
case T_SYMBOL:
|
54
|
+
inj_str = rb_id2name(SYM2ID(argv[0]));
|
55
|
+
inj_str_len = strlen(inj_str);
|
56
|
+
break;
|
57
|
+
default:
|
58
|
+
rb_raise(rb_eTypeError,
|
59
|
+
"invalid type, expecting a String or Symbol");
|
60
|
+
}
|
61
|
+
|
62
|
+
if (strncasecmp("raw", inj_str, inj_str_len) == 0 ||
|
63
|
+
strncasecmp("raw4", inj_str, inj_str_len) == 0) {
|
64
|
+
inj_type = LIBNET_RAW4_ADV;
|
65
|
+
}
|
66
|
+
else if (strncasecmp("raw6", inj_str, inj_str_len) == 0) {
|
67
|
+
inj_type = LIBNET_RAW6_ADV;
|
68
|
+
}
|
69
|
+
else if (strncasecmp("link", inj_str, inj_str_len) == 0) {
|
70
|
+
inj_type = LIBNET_LINK_ADV;
|
71
|
+
}
|
72
|
+
else {
|
73
|
+
rb_raise(rb_eArgError,
|
74
|
+
"%s is not a valid initialization type, should be one of: 'raw4', 'raw6', or 'link'",
|
75
|
+
inj_str);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
/* get the device string */
|
80
|
+
if (argc > 1) {
|
81
|
+
dev_str = StringValuePtr(argv[1]);
|
82
|
+
}
|
83
|
+
|
84
|
+
l = libnet_init(inj_type, dev_str, errbuf);
|
85
|
+
|
86
|
+
if (l == NULL) {
|
87
|
+
rb_raise(rb_eRuntimeError, errbuf);
|
88
|
+
}
|
89
|
+
|
90
|
+
obj = Data_Wrap_Struct(self, NULL, libnet_destroy, l);
|
91
|
+
|
92
|
+
/* set the injection type attribute */
|
93
|
+
switch (inj_type) {
|
94
|
+
case LIBNET_RAW4_ADV:
|
95
|
+
rb_iv_set(obj, "@injection_type", ID2SYM(rb_intern("raw4")));
|
96
|
+
break;
|
97
|
+
case LIBNET_RAW6_ADV:
|
98
|
+
rb_iv_set(obj, "@injection_type", ID2SYM(rb_intern("raw6")));
|
99
|
+
break;
|
100
|
+
case LIBNET_LINK_ADV:
|
101
|
+
rb_iv_set(obj, "@injection_type", ID2SYM(rb_intern("link")));
|
102
|
+
break;
|
103
|
+
default:
|
104
|
+
rb_bug("BUG: %d is an invalid injection type (this should not happen)",
|
105
|
+
inj_type);
|
106
|
+
}
|
107
|
+
|
108
|
+
|
109
|
+
return obj;
|
110
|
+
}
|
111
|
+
|
112
|
+
/* call-seq:
|
113
|
+
* Libnet.addr2name4(addr, do_dns_lookup=true) # -> DNS name or dotted decimal string
|
114
|
+
*
|
115
|
+
* Takes a network byte ordered IPv4 address and returns a string containing
|
116
|
+
* either the canonical DNS name (if it has one) or a dotted decimal
|
117
|
+
* respresentation of the IP address. This may incur a DNS lookup if the
|
118
|
+
* +do_dns_lookup+ parameter is set to true. If the +do_dns_lookup+
|
119
|
+
* parameter is set to false, no DNS lookup will be performed and the dotted
|
120
|
+
* decimal representation of the IP address will be returned.
|
121
|
+
*/
|
122
|
+
static VALUE net_s_addr2name4(int argc, VALUE *argv, VALUE self)
|
123
|
+
{
|
124
|
+
VALUE addr_v, use_name_v, name_v;
|
125
|
+
u_int32_t addr;
|
126
|
+
u_int8_t use_name = LIBNET_RESOLVE;
|
127
|
+
char *name = NULL;
|
128
|
+
|
129
|
+
rb_scan_args(argc, argv, "11", &addr_v, &use_name_v);
|
130
|
+
|
131
|
+
addr = NUM2ULONG(addr_v);
|
132
|
+
|
133
|
+
addr = htonl(addr);
|
134
|
+
|
135
|
+
if (!NIL_P(use_name_v) && use_name_v == Qfalse) {
|
136
|
+
use_name = LIBNET_DONT_RESOLVE;
|
137
|
+
}
|
138
|
+
|
139
|
+
name = libnet_addr2name4(addr, use_name);
|
140
|
+
|
141
|
+
name_v = rb_str_new2(name);
|
142
|
+
|
143
|
+
/* don't free the returned name here as its stored in a static buffer by
|
144
|
+
* libnet */
|
145
|
+
|
146
|
+
return name_v;
|
147
|
+
}
|
148
|
+
|
149
|
+
/* call-seq:
|
150
|
+
* Libnet.addr2name6(addr, do_dns_lookup=true) # -> DNS name or printable IPv6 string
|
151
|
+
*
|
152
|
+
* Takes a 16 byte IPv6 address and returns either the canonical DNS name (if
|
153
|
+
* it has one) or a printable representation of the address.
|
154
|
+
*/
|
155
|
+
static VALUE net_s_addr2name6(int argc, VALUE *argv, VALUE self)
|
156
|
+
{
|
157
|
+
VALUE addr_v, use_name_v, name_v;
|
158
|
+
struct libnet_in6_addr addr;
|
159
|
+
u_int8_t use_name = LIBNET_RESOLVE;
|
160
|
+
char name[100];
|
161
|
+
|
162
|
+
rb_scan_args(argc, argv, "11", &addr_v, &use_name_v);
|
163
|
+
|
164
|
+
if (RSTRING(addr_v)->len != 16) {
|
165
|
+
rb_raise(rb_eArgError, "invalid IPv6 address");
|
166
|
+
}
|
167
|
+
|
168
|
+
memcpy(addr.libnet_s6_addr, RSTRING(addr_v)->ptr, sizeof(addr.libnet_s6_addr));
|
169
|
+
|
170
|
+
if (!NIL_P(use_name_v) && use_name_v == Qfalse) {
|
171
|
+
use_name = LIBNET_DONT_RESOLVE;
|
172
|
+
}
|
173
|
+
|
174
|
+
libnet_addr2name6_r(addr, use_name, name, sizeof(name));
|
175
|
+
|
176
|
+
name_v = rb_str_new2(name);
|
177
|
+
|
178
|
+
return name_v;
|
179
|
+
}
|
180
|
+
|
181
|
+
/* call-seq:
|
182
|
+
* Libnet.hex_aton(string) # -> string
|
183
|
+
*
|
184
|
+
* Takes a colon separated hexidecimal address and returns a byte string
|
185
|
+
* suitable for use in a protocol builder method.
|
186
|
+
*/
|
187
|
+
static VALUE net_s_hex_aton(VALUE self, VALUE str)
|
188
|
+
{
|
189
|
+
u_int8_t *rv;
|
190
|
+
int len;
|
191
|
+
VALUE s;
|
192
|
+
|
193
|
+
rv = libnet_hex_aton((int8_t *)StringValuePtr(str), &len);
|
194
|
+
|
195
|
+
if (rv == NULL) {
|
196
|
+
rb_raise(rb_eArgError, "could not convert input string");
|
197
|
+
}
|
198
|
+
|
199
|
+
s = rb_str_new((char *)rv, len);
|
200
|
+
|
201
|
+
free(rv);
|
202
|
+
|
203
|
+
return s;
|
204
|
+
}
|
205
|
+
|
206
|
+
|
207
|
+
/* call-seq:
|
208
|
+
* Libnet.ipv4_aton(string) # -> integer
|
209
|
+
*
|
210
|
+
* Takes a dotted-decimal representation of an IPv4 address and returns a 4
|
211
|
+
* byte integer suitable for use in a header builder method.
|
212
|
+
*/
|
213
|
+
static VALUE net_s_ipv4_aton(VALUE self, VALUE str)
|
214
|
+
{
|
215
|
+
char *ip_s;
|
216
|
+
int len = RSTRING(str)->len;
|
217
|
+
unsigned long ipv4;
|
218
|
+
VALUE r;
|
219
|
+
|
220
|
+
ip_s = malloc(len + 1);
|
221
|
+
|
222
|
+
memcpy(ip_s, RSTRING(str)->ptr, len);
|
223
|
+
ip_s[len] = '\0';
|
224
|
+
|
225
|
+
if (inet_pton(AF_INET, ip_s, &ipv4) == 1) {
|
226
|
+
ipv4 = htonl(ipv4);
|
227
|
+
r = ULONG2NUM(ipv4);
|
228
|
+
}
|
229
|
+
else {
|
230
|
+
free(ip_s);
|
231
|
+
rb_raise(rb_eArgError, "invalid IPv4 address: %s\n", ip_s);
|
232
|
+
}
|
233
|
+
|
234
|
+
free(ip_s);
|
235
|
+
|
236
|
+
return r;
|
237
|
+
}
|
238
|
+
|
239
|
+
/* call-seq:
|
240
|
+
* Libnet.ipv6_aton(string) # -> integer
|
241
|
+
*
|
242
|
+
* Takes a string representation of an IPv6 address and returns a 16
|
243
|
+
* byte string suitable for use in a header builder method.
|
244
|
+
*/
|
245
|
+
static VALUE net_s_ipv6_aton(VALUE self, VALUE str)
|
246
|
+
{
|
247
|
+
char *ip_s;
|
248
|
+
int len = RSTRING(str)->len;
|
249
|
+
unsigned char ipv6[16];
|
250
|
+
VALUE r;
|
251
|
+
|
252
|
+
ip_s = malloc(len + 1);
|
253
|
+
|
254
|
+
memcpy(ip_s, RSTRING(str)->ptr, len);
|
255
|
+
ip_s[len] = '\0';
|
256
|
+
|
257
|
+
if (inet_pton(AF_INET6, ip_s, ipv6) == 1) {
|
258
|
+
r = rb_str_new(ipv6, sizeof(ipv6));
|
259
|
+
}
|
260
|
+
else {
|
261
|
+
free(ip_s);
|
262
|
+
rb_raise(rb_eArgError, "invalid IPv6 address: %s\n", ip_s);
|
263
|
+
}
|
264
|
+
|
265
|
+
free(ip_s);
|
266
|
+
|
267
|
+
return r;
|
268
|
+
}
|
269
|
+
|
270
|
+
/* call-seq:
|
271
|
+
* Libnet.ipv4_ntoa(integer) # -> string
|
272
|
+
*
|
273
|
+
* Takes a network formated IPv4 address and converts it to its dotted-decimal
|
274
|
+
* string representation.
|
275
|
+
*/
|
276
|
+
static VALUE net_s_ipv4_ntoa(VALUE self, VALUE integer)
|
277
|
+
{
|
278
|
+
unsigned long ipv4 = NUM2ULONG(integer);
|
279
|
+
char pbuf[100];
|
280
|
+
VALUE r;
|
281
|
+
|
282
|
+
ipv4 = htonl(ipv4);
|
283
|
+
|
284
|
+
if (inet_ntop(AF_INET, &ipv4, pbuf, sizeof(pbuf))) {
|
285
|
+
r = rb_str_new2(pbuf);
|
286
|
+
}
|
287
|
+
else {
|
288
|
+
rb_raise(rb_eArgError,
|
289
|
+
"could not convert integer value %#x to a printable IPv4 string",
|
290
|
+
ipv4);
|
291
|
+
}
|
292
|
+
|
293
|
+
return r;
|
294
|
+
}
|
295
|
+
|
296
|
+
/* call-seq:
|
297
|
+
* Libnet.ipv6_ntoa(string) # -> string
|
298
|
+
*
|
299
|
+
* Takes a network formated IPv6 address and converts it to its printable
|
300
|
+
* format.
|
301
|
+
*/
|
302
|
+
static VALUE net_s_ipv6_ntoa(VALUE self, VALUE str)
|
303
|
+
{
|
304
|
+
char *ip_s;
|
305
|
+
int len = RSTRING(str)->len;
|
306
|
+
char pbuf[100];
|
307
|
+
VALUE r;
|
308
|
+
|
309
|
+
if (len != 16) {
|
310
|
+
rb_raise(rb_eArgError, "invalid IPv6 address");
|
311
|
+
}
|
312
|
+
|
313
|
+
ip_s = malloc(len + 1);
|
314
|
+
|
315
|
+
memcpy(ip_s, RSTRING(str)->ptr, len);
|
316
|
+
ip_s[len] = '\0';
|
317
|
+
|
318
|
+
if (inet_ntop(AF_INET6, ip_s, pbuf, sizeof(pbuf))) {
|
319
|
+
r = rb_str_new2(pbuf);
|
320
|
+
}
|
321
|
+
else {
|
322
|
+
rb_raise(rb_eArgError,
|
323
|
+
"could not convert IPv6 address to a printable string");
|
324
|
+
}
|
325
|
+
|
326
|
+
return r;
|
327
|
+
}
|
328
|
+
|
329
|
+
/* call-seq:
|
330
|
+
* l.get_device # -> string
|
331
|
+
*
|
332
|
+
* Returns the canonical name of the device used for packet injection.
|
333
|
+
*/
|
334
|
+
static VALUE net_get_device(VALUE self)
|
335
|
+
{
|
336
|
+
libnet_t *l;
|
337
|
+
char *dev;
|
338
|
+
|
339
|
+
Data_Get_Struct(self, libnet_t, l);
|
340
|
+
|
341
|
+
dev = (char *)libnet_getdevice(l);
|
342
|
+
|
343
|
+
if (dev == NULL) {
|
344
|
+
dev = "";
|
345
|
+
}
|
346
|
+
|
347
|
+
return rb_str_new2(dev);
|
348
|
+
}
|
349
|
+
|
350
|
+
/* call-seq:
|
351
|
+
* l.write # -> num bytes written
|
352
|
+
*
|
353
|
+
* Writes a prebuilt packet to the network. The method assumes that a
|
354
|
+
* packet has been constructed inside the Libnet object via one or more
|
355
|
+
* Libnet#build_* methods and is ready to go. Depending on how this
|
356
|
+
* Libnet object was initialized, the method will write the packet to the
|
357
|
+
* wire either via the raw or link layer interface.
|
358
|
+
*
|
359
|
+
* Note: It is necessary for the UID or EUID of the process running this method
|
360
|
+
* to be 0.
|
361
|
+
*/
|
362
|
+
static VALUE net_write(VALUE self)
|
363
|
+
{
|
364
|
+
libnet_t *l;
|
365
|
+
int num_bytes;
|
366
|
+
|
367
|
+
Data_Get_Struct(self, libnet_t, l);
|
368
|
+
|
369
|
+
num_bytes = libnet_write(l);
|
370
|
+
|
371
|
+
if (num_bytes == -1) {
|
372
|
+
rb_raise(rb_eRuntimeError, libnet_geterror(l));
|
373
|
+
}
|
374
|
+
|
375
|
+
return INT2NUM(num_bytes);
|
376
|
+
}
|
377
|
+
|
378
|
+
/* call-seq:
|
379
|
+
* l.write_bytes(string) # -> num bytes written
|
380
|
+
*
|
381
|
+
* Writes a packet to the wire. This method is usedful to write a packet
|
382
|
+
* that has been constructed by hand or to write a packet that has been
|
383
|
+
* returned from Libnet#pack.
|
384
|
+
*
|
385
|
+
* Note: It is necessary for the UID or EUID of the process running this method
|
386
|
+
* to be 0.
|
387
|
+
*/
|
388
|
+
static VALUE net_write_bytes(VALUE self, VALUE bytes)
|
389
|
+
{
|
390
|
+
libnet_t *l;
|
391
|
+
int num_bytes;
|
392
|
+
VALUE str;
|
393
|
+
VALUE inj_type;
|
394
|
+
|
395
|
+
str = StringValue(bytes);
|
396
|
+
|
397
|
+
Data_Get_Struct(self, libnet_t, l);
|
398
|
+
|
399
|
+
inj_type = rb_iv_get(self, "@injection_type");
|
400
|
+
|
401
|
+
if (ID2SYM(rb_intern("raw4")) == inj_type) {
|
402
|
+
num_bytes = libnet_write_raw_ipv4(l, RSTRING(str)->ptr, RSTRING(str)->len);
|
403
|
+
}
|
404
|
+
else if (ID2SYM(rb_intern("raw6")) == inj_type) {
|
405
|
+
num_bytes = libnet_write_raw_ipv6(l, RSTRING(str)->ptr, RSTRING(str)->len);
|
406
|
+
}
|
407
|
+
else if (ID2SYM(rb_intern("link")) == inj_type) {
|
408
|
+
num_bytes = libnet_write_link(l, RSTRING(str)->ptr, RSTRING(str)->len);
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
rb_bug("BUG: invalid injection type found (this should not happen)");
|
412
|
+
}
|
413
|
+
|
414
|
+
if (num_bytes == -1) {
|
415
|
+
rb_raise(rb_eRuntimeError, libnet_geterror(l));
|
416
|
+
}
|
417
|
+
|
418
|
+
return INT2NUM(num_bytes);
|
419
|
+
}
|
420
|
+
|
421
|
+
/* call-seq:
|
422
|
+
* l.pack # -> string
|
423
|
+
*
|
424
|
+
* Yanks a prebuilt, wire-ready packet from the Libnet object.
|
425
|
+
*/
|
426
|
+
static VALUE net_pack(VALUE self)
|
427
|
+
{
|
428
|
+
libnet_t *l;
|
429
|
+
u_int8_t *packet;
|
430
|
+
u_int32_t packet_s;
|
431
|
+
VALUE str;
|
432
|
+
|
433
|
+
Data_Get_Struct(self, libnet_t, l);
|
434
|
+
|
435
|
+
if (libnet_pblock_coalesce(l, &packet, &packet_s) == -1) {
|
436
|
+
rb_raise(rb_eRuntimeError, libnet_geterror(l));
|
437
|
+
}
|
438
|
+
|
439
|
+
str = rb_str_new((char *)packet, packet_s);
|
440
|
+
|
441
|
+
libnet_adv_free_packet(l, packet);
|
442
|
+
|
443
|
+
return str;
|
444
|
+
}
|
445
|
+
|
446
|
+
/* call-seq:
|
447
|
+
* l.dump # -> nil
|
448
|
+
*
|
449
|
+
* Prints the contents of the Libnet object to STDOUT.
|
450
|
+
*/
|
451
|
+
static VALUE net_dump(VALUE self)
|
452
|
+
{
|
453
|
+
libnet_t *l;
|
454
|
+
|
455
|
+
Data_Get_Struct(self, libnet_t, l);
|
456
|
+
|
457
|
+
libnet_diag_dump_context(l);
|
458
|
+
|
459
|
+
return Qnil;
|
460
|
+
}
|
461
|
+
|
462
|
+
/* call-seq:
|
463
|
+
* l.clear # -> nil
|
464
|
+
*
|
465
|
+
* Clears the current packet inside the Libnet object. Should be called
|
466
|
+
* when the programmer wants to send a completely new packet of a different
|
467
|
+
* type using the same Libnet object.
|
468
|
+
*/
|
469
|
+
static VALUE net_clear(VALUE self)
|
470
|
+
{
|
471
|
+
libnet_t *l;
|
472
|
+
|
473
|
+
Data_Get_Struct(self, libnet_t, l);
|
474
|
+
|
475
|
+
libnet_clear_packet(l);
|
476
|
+
|
477
|
+
return Qnil;
|
478
|
+
}
|
479
|
+
|
480
|
+
/* call-seq:
|
481
|
+
* l.hwaddr # -> string
|
482
|
+
*
|
483
|
+
* Returns the MAC address for the device the Libnet object was initialized
|
484
|
+
* with. If the Libnet object was initialized without a device, the method
|
485
|
+
* will attempt to find one. If the method fails to find a device, a
|
486
|
+
* RuntimeError will be raised.
|
487
|
+
*/
|
488
|
+
static VALUE net_hwaddr(VALUE self)
|
489
|
+
{
|
490
|
+
libnet_t *l;
|
491
|
+
struct libnet_ether_addr *eth;
|
492
|
+
int i;
|
493
|
+
char eth_s[18];
|
494
|
+
char byte_s[3];
|
495
|
+
|
496
|
+
Data_Get_Struct(self, libnet_t, l);
|
497
|
+
|
498
|
+
eth = libnet_get_hwaddr(l);
|
499
|
+
|
500
|
+
if (eth == NULL) {
|
501
|
+
rb_raise(rb_eRuntimeError, libnet_geterror(l));
|
502
|
+
}
|
503
|
+
|
504
|
+
memset(eth_s, 0, sizeof(eth_s));
|
505
|
+
|
506
|
+
for (i = 0; i < 6; i++) {
|
507
|
+
snprintf(byte_s, sizeof(byte_s), "%02x", eth->ether_addr_octet[i]);
|
508
|
+
strcat(eth_s, byte_s);
|
509
|
+
|
510
|
+
if (i != 5) {
|
511
|
+
strcat(eth_s, ":");
|
512
|
+
}
|
513
|
+
}
|
514
|
+
|
515
|
+
return rb_str_new2(eth_s);
|
516
|
+
}
|
517
|
+
|
518
|
+
/* Ruby bindings for the Libnet[http://www.packetfactory.net/libnet/] Packet
|
519
|
+
* Construction Library.
|
520
|
+
*/
|
521
|
+
void Init_libnet4r()
|
522
|
+
{
|
523
|
+
cLibnet = rb_define_class("Libnet", rb_cObject);
|
524
|
+
|
525
|
+
/* libnet header length constants */
|
526
|
+
rb_define_const(cLibnet, "HL_802_1Q", INT2FIX(LIBNET_802_1Q_H));
|
527
|
+
rb_define_const(cLibnet, "HL_802_1X", INT2FIX(LIBNET_802_1X_H));
|
528
|
+
rb_define_const(cLibnet, "HL_802_2", INT2FIX(LIBNET_802_2_H));
|
529
|
+
rb_define_const(cLibnet, "HL_802_2SNAP", INT2FIX(LIBNET_802_2SNAP_H));
|
530
|
+
rb_define_const(cLibnet, "HL_802_3", INT2FIX(LIBNET_802_3_H));
|
531
|
+
rb_define_const(cLibnet, "HL_ARP", INT2FIX(LIBNET_ARP_H));
|
532
|
+
rb_define_const(cLibnet, "HL_ARP_ETH_IP", INT2FIX(LIBNET_ARP_ETH_IP_H));
|
533
|
+
rb_define_const(cLibnet, "HL_BGP4_HEADER", INT2FIX(LIBNET_BGP4_HEADER_H));
|
534
|
+
rb_define_const(cLibnet, "HL_BGP4_OPEN", INT2FIX(LIBNET_BGP4_OPEN_H));
|
535
|
+
rb_define_const(cLibnet, "HL_BGP4_UPDATE", INT2FIX(LIBNET_BGP4_UPDATE_H));
|
536
|
+
rb_define_const(cLibnet, "HL_BGP4_NOTIFICATION", INT2FIX(LIBNET_BGP4_NOTIFICATION_H));
|
537
|
+
rb_define_const(cLibnet, "HL_CDP", INT2FIX(LIBNET_CDP_H));
|
538
|
+
rb_define_const(cLibnet, "HL_DHCPV4", INT2FIX(LIBNET_DHCPV4_H));
|
539
|
+
rb_define_const(cLibnet, "HL_UDP_DNSV4", INT2FIX(LIBNET_UDP_DNSV4_H));
|
540
|
+
rb_define_const(cLibnet, "HL_TCP_DNSV4", INT2FIX(LIBNET_TCP_DNSV4_H));
|
541
|
+
rb_define_const(cLibnet, "HL_ETH", INT2FIX(LIBNET_ETH_H));
|
542
|
+
rb_define_const(cLibnet, "HL_FDDI", INT2FIX(LIBNET_FDDI_H));
|
543
|
+
rb_define_const(cLibnet, "HL_ICMPV4", INT2FIX(LIBNET_ICMPV4_H));
|
544
|
+
rb_define_const(cLibnet, "HL_ICMPV4_ECHO", INT2FIX(LIBNET_ICMPV4_ECHO_H));
|
545
|
+
rb_define_const(cLibnet, "HL_ICMPV4_MASK", INT2FIX(LIBNET_ICMPV4_MASK_H));
|
546
|
+
rb_define_const(cLibnet, "HL_ICMPV4_UNREACH", INT2FIX(LIBNET_ICMPV4_UNREACH_H));
|
547
|
+
rb_define_const(cLibnet, "HL_ICMPV4_TIMXCEED", INT2FIX(LIBNET_ICMPV4_TIMXCEED_H));
|
548
|
+
rb_define_const(cLibnet, "HL_ICMPV4_REDIRECT", INT2FIX(LIBNET_ICMPV4_REDIRECT_H));
|
549
|
+
rb_define_const(cLibnet, "HL_ICMPV4_TS", INT2FIX(LIBNET_ICMPV4_TS_H));
|
550
|
+
rb_define_const(cLibnet, "HL_ICMPV6", INT2FIX(LIBNET_ICMPV6_H));
|
551
|
+
rb_define_const(cLibnet, "HL_IGMP", INT2FIX(LIBNET_IGMP_H));
|
552
|
+
rb_define_const(cLibnet, "HL_IPV4", INT2FIX(LIBNET_IPV4_H));
|
553
|
+
rb_define_const(cLibnet, "HL_IPV6", INT2FIX(LIBNET_IPV6_H));
|
554
|
+
rb_define_const(cLibnet, "HL_IPV6_FRAG", INT2FIX(LIBNET_IPV6_FRAG_H));
|
555
|
+
rb_define_const(cLibnet, "HL_IPV6_ROUTING", INT2FIX(LIBNET_IPV6_ROUTING_H));
|
556
|
+
rb_define_const(cLibnet, "HL_IPV6_DESTOPTS", INT2FIX(LIBNET_IPV6_DESTOPTS_H));
|
557
|
+
rb_define_const(cLibnet, "HL_IPV6_HBHOPTS", INT2FIX(LIBNET_IPV6_HBHOPTS_H));
|
558
|
+
rb_define_const(cLibnet, "HL_IPSEC_ESP_HDR", INT2FIX(LIBNET_IPSEC_ESP_HDR_H));
|
559
|
+
rb_define_const(cLibnet, "HL_IPSEC_ESP_FTR", INT2FIX(LIBNET_IPSEC_ESP_FTR_H));
|
560
|
+
rb_define_const(cLibnet, "HL_IPSEC_AH", INT2FIX(LIBNET_IPSEC_AH_H));
|
561
|
+
rb_define_const(cLibnet, "HL_ISL", INT2FIX(LIBNET_ISL_H));
|
562
|
+
rb_define_const(cLibnet, "HL_GRE", INT2FIX(LIBNET_GRE_H));
|
563
|
+
rb_define_const(cLibnet, "HL_GRE_SRE", INT2FIX(LIBNET_GRE_SRE_H));
|
564
|
+
rb_define_const(cLibnet, "HL_MPLS", INT2FIX(LIBNET_MPLS_H));
|
565
|
+
rb_define_const(cLibnet, "HL_OSPF", INT2FIX(LIBNET_OSPF_H));
|
566
|
+
rb_define_const(cLibnet, "HL_OSPF_HELLO", INT2FIX(LIBNET_OSPF_HELLO_H));
|
567
|
+
rb_define_const(cLibnet, "HL_OSPF_DBD", INT2FIX(LIBNET_OSPF_DBD_H));
|
568
|
+
rb_define_const(cLibnet, "HL_OSPF_LSR", INT2FIX(LIBNET_OSPF_LSR_H));
|
569
|
+
rb_define_const(cLibnet, "HL_OSPF_LSU", INT2FIX(LIBNET_OSPF_LSU_H));
|
570
|
+
rb_define_const(cLibnet, "HL_OSPF_LSA", INT2FIX(LIBNET_OSPF_LSA_H));
|
571
|
+
rb_define_const(cLibnet, "HL_OSPF_AUTH", INT2FIX(LIBNET_OSPF_AUTH_H));
|
572
|
+
rb_define_const(cLibnet, "HL_OSPF_CKSUM", INT2FIX(LIBNET_OSPF_CKSUM));
|
573
|
+
rb_define_const(cLibnet, "HL_OSPF_LS_RTR", INT2FIX(LIBNET_OSPF_LS_RTR_H));
|
574
|
+
rb_define_const(cLibnet, "HL_OSPF_LS_NET", INT2FIX(LIBNET_OSPF_LS_NET_H));
|
575
|
+
rb_define_const(cLibnet, "HL_OSPF_LS_SUM", INT2FIX(LIBNET_OSPF_LS_SUM_H));
|
576
|
+
rb_define_const(cLibnet, "HL_OSPF_LS_AS_EXT", INT2FIX(LIBNET_OSPF_LS_AS_EXT_H));
|
577
|
+
rb_define_const(cLibnet, "HL_NTP", INT2FIX(LIBNET_NTP_H));
|
578
|
+
rb_define_const(cLibnet, "HL_RIP", INT2FIX(LIBNET_RIP_H));
|
579
|
+
rb_define_const(cLibnet, "HL_RPC_CALL", INT2FIX(LIBNET_RPC_CALL_H));
|
580
|
+
rb_define_const(cLibnet, "HL_RPC_CALL_TCP", INT2FIX(LIBNET_RPC_CALL_TCP_H));
|
581
|
+
rb_define_const(cLibnet, "HL_SEBEK", INT2FIX(LIBNET_SEBEK_H));
|
582
|
+
rb_define_const(cLibnet, "HL_STP_CONF", INT2FIX(LIBNET_STP_CONF_H));
|
583
|
+
rb_define_const(cLibnet, "HL_STP_TCN", INT2FIX(LIBNET_STP_TCN_H));
|
584
|
+
rb_define_const(cLibnet, "HL_TOKEN_RING", INT2FIX(LIBNET_TOKEN_RING_H));
|
585
|
+
rb_define_const(cLibnet, "HL_TCP", INT2FIX(LIBNET_TCP_H));
|
586
|
+
rb_define_const(cLibnet, "HL_UDP", INT2FIX(LIBNET_UDP_H));
|
587
|
+
rb_define_const(cLibnet, "HL_VRRP", INT2FIX(LIBNET_VRRP_H));
|
588
|
+
|
589
|
+
/* IP protocol constants */
|
590
|
+
#ifdef HAVE_IPPROTO_IP
|
591
|
+
rb_define_const(cLibnet, "IPPROTO_IP", INT2FIX(IPPROTO_IP));
|
592
|
+
#endif
|
593
|
+
#ifdef HAVE_IPPROTO_HOPOPTS
|
594
|
+
rb_define_const(cLibnet, "IPPROTO_HOPOPTS", INT2FIX(IPPROTO_HOPOPTS));
|
595
|
+
#endif
|
596
|
+
#ifdef HAVE_IPPROTO_ICMP
|
597
|
+
rb_define_const(cLibnet, "IPPROTO_ICMP", INT2FIX(IPPROTO_ICMP));
|
598
|
+
#endif
|
599
|
+
#ifdef HAVE_IPPROTO_IGMP
|
600
|
+
rb_define_const(cLibnet, "IPPROTO_IGMP", INT2FIX(IPPROTO_IGMP));
|
601
|
+
#endif
|
602
|
+
#ifdef HAVE_IPPROTO_GGP
|
603
|
+
rb_define_const(cLibnet, "IPPROTO_GGP", INT2FIX(IPPROTO_GGP));
|
604
|
+
#endif
|
605
|
+
#ifdef HAVE_IPPROTO_ENCAP
|
606
|
+
rb_define_const(cLibnet, "IPPROTO_ENCAP", INT2FIX(IPPROTO_ENCAP));
|
607
|
+
#endif
|
608
|
+
#ifdef HAVE_IPPROTO_TCP
|
609
|
+
rb_define_const(cLibnet, "IPPROTO_TCP", INT2FIX(IPPROTO_TCP));
|
610
|
+
#endif
|
611
|
+
#ifdef HAVE_IPPROTO_EGP
|
612
|
+
rb_define_const(cLibnet, "IPPROTO_EGP", INT2FIX(IPPROTO_EGP));
|
613
|
+
#endif
|
614
|
+
#ifdef HAVE_IPPROTO_PUP
|
615
|
+
rb_define_const(cLibnet, "IPPROTO_PUP", INT2FIX(IPPROTO_PUP));
|
616
|
+
#endif
|
617
|
+
#ifdef HAVE_IPPROTO_UDP
|
618
|
+
rb_define_const(cLibnet, "IPPROTO_UDP", INT2FIX(IPPROTO_UDP));
|
619
|
+
#endif
|
620
|
+
#ifdef HAVE_IPPROTO_IDP
|
621
|
+
rb_define_const(cLibnet, "IPPROTO_IDP", INT2FIX(IPPROTO_IDP));
|
622
|
+
#endif
|
623
|
+
#ifdef HAVE_IPPROTO_IPV6
|
624
|
+
rb_define_const(cLibnet, "IPPROTO_IPV6", INT2FIX(IPPROTO_IPV6));
|
625
|
+
#endif
|
626
|
+
#ifdef HAVE_IPPROTO_ROUTING
|
627
|
+
rb_define_const(cLibnet, "IPPROTO_ROUTING", INT2FIX(IPPROTO_ROUTING));
|
628
|
+
#endif
|
629
|
+
#ifdef HAVE_IPPROTO_FRAGMENT
|
630
|
+
rb_define_const(cLibnet, "IPPROTO_FRAGMENT", INT2FIX(IPPROTO_FRAGMENT));
|
631
|
+
#endif
|
632
|
+
#ifdef HAVE_IPPROTO_RSVP
|
633
|
+
rb_define_const(cLibnet, "IPPROTO_RSVP", INT2FIX(IPPROTO_RSVP));
|
634
|
+
#endif
|
635
|
+
#ifdef HAVE_IPPROTO_ESP
|
636
|
+
rb_define_const(cLibnet, "IPPROTO_ESP", INT2FIX(IPPROTO_ESP));
|
637
|
+
#endif
|
638
|
+
#ifdef HAVE_IPPROTO_AH
|
639
|
+
rb_define_const(cLibnet, "IPPROTO_AH", INT2FIX(IPPROTO_AH));
|
640
|
+
#endif
|
641
|
+
#ifdef HAVE_IPPROTO_ICMPV6
|
642
|
+
rb_define_const(cLibnet, "IPPROTO_ICMPV6", INT2FIX(IPPROTO_ICMPV6));
|
643
|
+
#endif
|
644
|
+
#ifdef HAVE_IPPROTO_NONE
|
645
|
+
rb_define_const(cLibnet, "IPPROTO_NONE", INT2FIX(IPPROTO_NONE));
|
646
|
+
#endif
|
647
|
+
#ifdef HAVE_IPPROTO_DSTOPTS
|
648
|
+
rb_define_const(cLibnet, "IPPROTO_DSTOPTS", INT2FIX(IPPROTO_DSTOPTS));
|
649
|
+
#endif
|
650
|
+
#ifdef HAVE_IPPROTO_HELLO
|
651
|
+
rb_define_const(cLibnet, "IPPROTO_HELLO", INT2FIX(IPPROTO_HELLO));
|
652
|
+
#endif
|
653
|
+
#ifdef HAVE_IPPROTO_ND
|
654
|
+
rb_define_const(cLibnet, "IPPROTO_ND", INT2FIX(IPPROTO_ND));
|
655
|
+
#endif
|
656
|
+
#ifdef HAVE_IPPROTO_EON
|
657
|
+
rb_define_const(cLibnet, "IPPROTO_EON", INT2FIX(IPPROTO_EON));
|
658
|
+
#endif
|
659
|
+
#ifdef HAVE_IPPROTO_PIM
|
660
|
+
rb_define_const(cLibnet, "IPPROTO_PIM", INT2FIX(IPPROTO_PIM));
|
661
|
+
#endif
|
662
|
+
#ifdef HAVE_IPPROTO_SCTP
|
663
|
+
rb_define_const(cLibnet, "IPPROTO_SCTP", INT2FIX(IPPROTO_SCTP));
|
664
|
+
#endif
|
665
|
+
#ifdef HAVE_IPPROTO_RAW
|
666
|
+
rb_define_const(cLibnet, "IPPROTO_RAW", INT2FIX(IPPROTO_RAW));
|
667
|
+
#endif
|
668
|
+
#ifdef HAVE_IPPROTO_MAX
|
669
|
+
rb_define_const(cLibnet, "IPPROTO_MAX", INT2FIX(IPPROTO_MAX));
|
670
|
+
#endif
|
671
|
+
|
672
|
+
/* require the pure ruby protocol classes */
|
673
|
+
rb_require("libnet4r/libnet.rb");
|
674
|
+
rb_require("libnet4r/helpers.rb");
|
675
|
+
rb_require("libnet4r/header.rb");
|
676
|
+
|
677
|
+
/* class methods */
|
678
|
+
rb_define_singleton_method(cLibnet, "new", net_s_new, -1);
|
679
|
+
rb_define_singleton_method(cLibnet, "addr2name4", net_s_addr2name4, -1);
|
680
|
+
rb_define_singleton_method(cLibnet, "addr2name6", net_s_addr2name6, -1);
|
681
|
+
rb_define_singleton_method(cLibnet, "hex_aton", net_s_hex_aton, 1);
|
682
|
+
rb_define_singleton_method(cLibnet, "ipv4_aton", net_s_ipv4_aton, 1);
|
683
|
+
rb_define_singleton_method(cLibnet, "ipv4_ntoa", net_s_ipv4_ntoa, 1);
|
684
|
+
rb_define_singleton_method(cLibnet, "ipv6_aton", net_s_ipv6_aton, 1);
|
685
|
+
rb_define_singleton_method(cLibnet, "ipv6_ntoa", net_s_ipv6_ntoa, 1);
|
686
|
+
|
687
|
+
/* instance methods */
|
688
|
+
rb_define_method(cLibnet, "device", net_get_device, 0);
|
689
|
+
rb_define_method(cLibnet, "write", net_write, 0);
|
690
|
+
rb_define_method(cLibnet, "write_bytes", net_write_bytes, 1);
|
691
|
+
rb_define_method(cLibnet, "cull_packet", net_pack, 0);
|
692
|
+
rb_define_method(cLibnet, "pack", net_pack, 0);
|
693
|
+
rb_define_method(cLibnet, "hwaddr", net_hwaddr, 0);
|
694
|
+
rb_define_method(cLibnet, "dump", net_dump, 0);
|
695
|
+
rb_define_method(cLibnet, "clear", net_clear, 0);
|
696
|
+
|
697
|
+
/* define the individual protocol methods */
|
698
|
+
define_udp_methods();
|
699
|
+
define_ipv4_methods();
|
700
|
+
define_ipv6_methods();
|
701
|
+
define_ethernet_methods();
|
702
|
+
define_vlan_methods();
|
703
|
+
define_arp_methods();
|
704
|
+
}
|
705
|
+
|