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.
Files changed (306) hide show
  1. data/CHANGELOG +15 -0
  2. data/LICENSE +28 -0
  3. data/README +187 -0
  4. data/Rakefile +110 -0
  5. data/ext/extconf.rb +60 -0
  6. data/ext/libnet.c +705 -0
  7. data/ext/libnet_arp.c +152 -0
  8. data/ext/libnet_ethernet.c +115 -0
  9. data/ext/libnet_ipv4.c +140 -0
  10. data/ext/libnet_ipv6.c +138 -0
  11. data/ext/libnet_udp.c +112 -0
  12. data/ext/libnet_vlan.c +131 -0
  13. data/lib/libnet4r/header.rb +609 -0
  14. data/lib/libnet4r/helpers.rb +19 -0
  15. data/lib/libnet4r/libnet.rb +39 -0
  16. data/libnet/CVS/Entries +24 -0
  17. data/libnet/CVS/Repository +1 -0
  18. data/libnet/CVS/Root +1 -0
  19. data/libnet/Makefile.am +15 -0
  20. data/libnet/Makefile.am.common +10 -0
  21. data/libnet/Makefile.in +443 -0
  22. data/libnet/README +21 -0
  23. data/libnet/VERSION +1 -0
  24. data/libnet/acconfig.h +36 -0
  25. data/libnet/acinclude.m4 +463 -0
  26. data/libnet/aclocal.m4 +1337 -0
  27. data/libnet/autom4te.cache/CVS/Entries +1 -0
  28. data/libnet/autom4te.cache/CVS/Repository +1 -0
  29. data/libnet/autom4te.cache/CVS/Root +1 -0
  30. data/libnet/autom4te.cache/output.0 +6225 -0
  31. data/libnet/autom4te.cache/requests +111 -0
  32. data/libnet/autom4te.cache/traces.0 +272 -0
  33. data/libnet/config.guess +1314 -0
  34. data/libnet/config.sub +1410 -0
  35. data/libnet/configure +6225 -0
  36. data/libnet/configure.in +235 -0
  37. data/libnet/doc/BUGS +19 -0
  38. data/libnet/doc/CHANGELOG +527 -0
  39. data/libnet/doc/CONTRIB +53 -0
  40. data/libnet/doc/COPYING +31 -0
  41. data/libnet/doc/CVS/Entries +12 -0
  42. data/libnet/doc/CVS/Repository +1 -0
  43. data/libnet/doc/CVS/Root +1 -0
  44. data/libnet/doc/DESIGN_NOTES +134 -0
  45. data/libnet/doc/MIGRATION +172 -0
  46. data/libnet/doc/PACKET_BUILDING +161 -0
  47. data/libnet/doc/PORTED +45 -0
  48. data/libnet/doc/RAWSOCKET_NON_SEQUITUR +41 -0
  49. data/libnet/doc/TODO +96 -0
  50. data/libnet/doc/html/acconfig_8h-source.html +49 -0
  51. data/libnet/doc/html/annotated.html +17 -0
  52. data/libnet/doc/html/bpf_8h-source.html +277 -0
  53. data/libnet/doc/html/config_8h-source.html +125 -0
  54. data/libnet/doc/html/doxygen.css +169 -0
  55. data/libnet/doc/html/doxygen.png +0 -0
  56. data/libnet/doc/html/files.html +29 -0
  57. data/libnet/doc/html/functions.html +26 -0
  58. data/libnet/doc/html/functions_vars.html +26 -0
  59. data/libnet/doc/html/getopt_8h-source.html +97 -0
  60. data/libnet/doc/html/globals.html +219 -0
  61. data/libnet/doc/html/globals_defs.html +104 -0
  62. data/libnet/doc/html/globals_func.html +136 -0
  63. data/libnet/doc/html/gnuc_8h-source.html +56 -0
  64. data/libnet/doc/html/graph_legend.dot +22 -0
  65. data/libnet/doc/html/graph_legend.html +75 -0
  66. data/libnet/doc/html/ifaddrlist_8h-source.html +65 -0
  67. data/libnet/doc/html/in__systm_8h-source.html +90 -0
  68. data/libnet/doc/html/index.html +17 -0
  69. data/libnet/doc/html/libnet-asn1_8h-source.html +268 -0
  70. data/libnet/doc/html/libnet-functions_8h-source.html +742 -0
  71. data/libnet/doc/html/libnet-functions_8h.html +8844 -0
  72. data/libnet/doc/html/libnet-headers_8h-source.html +1655 -0
  73. data/libnet/doc/html/libnet-headers_8h.html +3053 -0
  74. data/libnet/doc/html/libnet-macros_8h-source.html +161 -0
  75. data/libnet/doc/html/libnet-macros_8h.html +358 -0
  76. data/libnet/doc/html/libnet-structures_8h-source.html +233 -0
  77. data/libnet/doc/html/libnet-types_8h-source.html +58 -0
  78. data/libnet/doc/html/libnet_8h-source.html +119 -0
  79. data/libnet/doc/html/libnet_8h.html +24 -0
  80. data/libnet/doc/html/structlibnet__802__1q__hdr.html +145 -0
  81. data/libnet/doc/html/structlibnet__802__1x__hdr.html +97 -0
  82. data/libnet/doc/libnet.doxygen.conf +1102 -0
  83. data/libnet/doc/man/CVS/Entries +1 -0
  84. data/libnet/doc/man/CVS/Repository +1 -0
  85. data/libnet/doc/man/CVS/Root +1 -0
  86. data/libnet/doc/man/man3/libnet-functions.h.3 +3136 -0
  87. data/libnet/doc/man/man3/libnet-headers.h.3 +1872 -0
  88. data/libnet/doc/man/man3/libnet-macros.h.3 +172 -0
  89. data/libnet/doc/man/man3/libnet.h.3 +17 -0
  90. data/libnet/doc/man/man3/libnet_802_1q_hdr.3 +53 -0
  91. data/libnet/doc/man/man3/libnet_802_1x_hdr.3 +41 -0
  92. data/libnet/include/CVS/Entries +10 -0
  93. data/libnet/include/CVS/Repository +1 -0
  94. data/libnet/include/CVS/Root +1 -0
  95. data/libnet/include/Makefile.am +7 -0
  96. data/libnet/include/Makefile.in +395 -0
  97. data/libnet/include/bpf.h +264 -0
  98. data/libnet/include/config.h.in +118 -0
  99. data/libnet/include/gnuc.h +43 -0
  100. data/libnet/include/ifaddrlist.h +52 -0
  101. data/libnet/include/libnet/CVS/Entries +9 -0
  102. data/libnet/include/libnet/CVS/Repository +1 -0
  103. data/libnet/include/libnet/CVS/Root +1 -0
  104. data/libnet/include/libnet/Makefile.am +12 -0
  105. data/libnet/include/libnet/Makefile.in +294 -0
  106. data/libnet/include/libnet/libnet-asn1.h +255 -0
  107. data/libnet/include/libnet/libnet-functions.h +2157 -0
  108. data/libnet/include/libnet/libnet-headers.h +1662 -0
  109. data/libnet/include/libnet/libnet-macros.h +186 -0
  110. data/libnet/include/libnet/libnet-structures.h +222 -0
  111. data/libnet/include/libnet/libnet-types.h +45 -0
  112. data/libnet/include/libnet.h.in +132 -0
  113. data/libnet/include/stamp-h.in +1 -0
  114. data/libnet/include/win32/CVS/Entries +5 -0
  115. data/libnet/include/win32/CVS/Repository +1 -0
  116. data/libnet/include/win32/CVS/Root +1 -0
  117. data/libnet/include/win32/config.h +112 -0
  118. data/libnet/include/win32/getopt.h +84 -0
  119. data/libnet/include/win32/in_systm.h +77 -0
  120. data/libnet/include/win32/libnet.h +106 -0
  121. data/libnet/install-sh +250 -0
  122. data/libnet/libnet-config.in +62 -0
  123. data/libnet/libnet.doxygen.conf +1102 -0
  124. data/libnet/man/CVS/Entries +1 -0
  125. data/libnet/man/CVS/Repository +1 -0
  126. data/libnet/man/CVS/Root +1 -0
  127. data/libnet/missing +283 -0
  128. data/libnet/mkinstalldirs +40 -0
  129. data/libnet/sample/CVS/Entries +47 -0
  130. data/libnet/sample/CVS/Repository +1 -0
  131. data/libnet/sample/CVS/Root +1 -0
  132. data/libnet/sample/Makefile.am +63 -0
  133. data/libnet/sample/Makefile.in +729 -0
  134. data/libnet/sample/arp-new.c +144 -0
  135. data/libnet/sample/arp.c +151 -0
  136. data/libnet/sample/bgp4_hdr.c +225 -0
  137. data/libnet/sample/bgp4_notification.c +242 -0
  138. data/libnet/sample/bgp4_open.c +266 -0
  139. data/libnet/sample/bgp4_update.c +337 -0
  140. data/libnet/sample/cdp.c +187 -0
  141. data/libnet/sample/dhcp_discover.c +257 -0
  142. data/libnet/sample/dns.c +260 -0
  143. data/libnet/sample/dot1x.c +113 -0
  144. data/libnet/sample/fddi_tcp1.c +213 -0
  145. data/libnet/sample/fddi_tcp2.c +209 -0
  146. data/libnet/sample/get_addr.c +112 -0
  147. data/libnet/sample/gre.c +410 -0
  148. data/libnet/sample/icmp6_echoreq.c +184 -0
  149. data/libnet/sample/icmp_echo_cq.c +201 -0
  150. data/libnet/sample/icmp_redirect.c +200 -0
  151. data/libnet/sample/icmp_timeexceed.c +190 -0
  152. data/libnet/sample/icmp_timestamp.c +157 -0
  153. data/libnet/sample/icmp_unreach.c +204 -0
  154. data/libnet/sample/ieee.c +177 -0
  155. data/libnet/sample/ip_link.c +201 -0
  156. data/libnet/sample/ip_raw.c +180 -0
  157. data/libnet/sample/isl.c +167 -0
  158. data/libnet/sample/libnet_test.h +60 -0
  159. data/libnet/sample/mpls.c +251 -0
  160. data/libnet/sample/ntp.c +193 -0
  161. data/libnet/sample/ospf_hello.c +179 -0
  162. data/libnet/sample/ospf_lsa.c +190 -0
  163. data/libnet/sample/ping_of_death.c +171 -0
  164. data/libnet/sample/rpc_tcp.c +214 -0
  165. data/libnet/sample/rpc_udp.c +213 -0
  166. data/libnet/sample/sebek.c +299 -0
  167. data/libnet/sample/smurf.c +194 -0
  168. data/libnet/sample/stp.c +227 -0
  169. data/libnet/sample/synflood.c +200 -0
  170. data/libnet/sample/synflood6.c +209 -0
  171. data/libnet/sample/synflood6_frag.c +234 -0
  172. data/libnet/sample/tcp1.c +227 -0
  173. data/libnet/sample/tcp2.c +192 -0
  174. data/libnet/sample/tftp.c +207 -0
  175. data/libnet/sample/tring_tcp1.c +214 -0
  176. data/libnet/sample/tring_tcp2.c +210 -0
  177. data/libnet/sample/udp1.c +223 -0
  178. data/libnet/sample/udp2.c +232 -0
  179. data/libnet/sample/win32/CVS/Entries +9 -0
  180. data/libnet/sample/win32/CVS/Repository +1 -0
  181. data/libnet/sample/win32/CVS/Root +1 -0
  182. data/libnet/sample/win32/arp/CVS/Entries +2 -0
  183. data/libnet/sample/win32/arp/CVS/Repository +1 -0
  184. data/libnet/sample/win32/arp/CVS/Root +1 -0
  185. data/libnet/sample/win32/arp/arp.vcproj +136 -0
  186. data/libnet/sample/win32/cdp/CVS/Entries +2 -0
  187. data/libnet/sample/win32/cdp/CVS/Repository +1 -0
  188. data/libnet/sample/win32/cdp/CVS/Root +1 -0
  189. data/libnet/sample/win32/cdp/cdp.vcproj +136 -0
  190. data/libnet/sample/win32/dhcp_discover/CVS/Entries +2 -0
  191. data/libnet/sample/win32/dhcp_discover/CVS/Repository +1 -0
  192. data/libnet/sample/win32/dhcp_discover/CVS/Root +1 -0
  193. data/libnet/sample/win32/dhcp_discover/dhcp_discover.vcproj +139 -0
  194. data/libnet/sample/win32/dns/CVS/Entries +2 -0
  195. data/libnet/sample/win32/dns/CVS/Repository +1 -0
  196. data/libnet/sample/win32/dns/CVS/Root +1 -0
  197. data/libnet/sample/win32/dns/dns.vcproj +139 -0
  198. data/libnet/sample/win32/get_addr/CVS/Entries +2 -0
  199. data/libnet/sample/win32/get_addr/CVS/Repository +1 -0
  200. data/libnet/sample/win32/get_addr/CVS/Root +1 -0
  201. data/libnet/sample/win32/get_addr/get_addr.vcproj +139 -0
  202. data/libnet/sample/win32/getopt.c +121 -0
  203. data/libnet/sample/win32/icmp_echo_cq/CVS/Entries +2 -0
  204. data/libnet/sample/win32/icmp_echo_cq/CVS/Repository +1 -0
  205. data/libnet/sample/win32/icmp_echo_cq/CVS/Root +1 -0
  206. data/libnet/sample/win32/icmp_echo_cq/icmp_echo_cq.vcproj +139 -0
  207. data/libnet/sample/win32/tcp1/CVS/Entries +2 -0
  208. data/libnet/sample/win32/tcp1/CVS/Repository +1 -0
  209. data/libnet/sample/win32/tcp1/CVS/Root +1 -0
  210. data/libnet/sample/win32/tcp1/tcp1.vcproj +142 -0
  211. data/libnet/sample/win32/udp1/CVS/Entries +3 -0
  212. data/libnet/sample/win32/udp1/CVS/Repository +1 -0
  213. data/libnet/sample/win32/udp1/CVS/Root +1 -0
  214. data/libnet/sample/win32/udp1/dns.vcproj +125 -0
  215. data/libnet/sample/win32/udp1/udp1.vcproj +139 -0
  216. data/libnet/src/CVS/Entries +60 -0
  217. data/libnet/src/CVS/Repository +1 -0
  218. data/libnet/src/CVS/Root +1 -0
  219. data/libnet/src/Makefile.am +71 -0
  220. data/libnet/src/Makefile.in +428 -0
  221. data/libnet/src/libnet_advanced.c +136 -0
  222. data/libnet/src/libnet_asn1.c +436 -0
  223. data/libnet/src/libnet_build_802.1q.c +115 -0
  224. data/libnet/src/libnet_build_802.1x.c +103 -0
  225. data/libnet/src/libnet_build_802.2.c +167 -0
  226. data/libnet/src/libnet_build_802.3.c +101 -0
  227. data/libnet/src/libnet_build_arp.c +169 -0
  228. data/libnet/src/libnet_build_bgp.c +350 -0
  229. data/libnet/src/libnet_build_cdp.c +191 -0
  230. data/libnet/src/libnet_build_data.c +90 -0
  231. data/libnet/src/libnet_build_dhcp.c +156 -0
  232. data/libnet/src/libnet_build_dns.c +129 -0
  233. data/libnet/src/libnet_build_ethernet.c +173 -0
  234. data/libnet/src/libnet_build_fddi.c +191 -0
  235. data/libnet/src/libnet_build_gre.c +427 -0
  236. data/libnet/src/libnet_build_icmp.c +437 -0
  237. data/libnet/src/libnet_build_igmp.c +112 -0
  238. data/libnet/src/libnet_build_ip.c +892 -0
  239. data/libnet/src/libnet_build_ipsec.c +232 -0
  240. data/libnet/src/libnet_build_isl.c +113 -0
  241. data/libnet/src/libnet_build_link.c +90 -0
  242. data/libnet/src/libnet_build_mpls.c +112 -0
  243. data/libnet/src/libnet_build_ntp.c +121 -0
  244. data/libnet/src/libnet_build_ospf.c +699 -0
  245. data/libnet/src/libnet_build_rip.c +108 -0
  246. data/libnet/src/libnet_build_rpc.c +138 -0
  247. data/libnet/src/libnet_build_sebek.c +108 -0
  248. data/libnet/src/libnet_build_snmp.c +52 -0
  249. data/libnet/src/libnet_build_stp.c +222 -0
  250. data/libnet/src/libnet_build_tcp.c +365 -0
  251. data/libnet/src/libnet_build_token_ring.c +193 -0
  252. data/libnet/src/libnet_build_udp.c +111 -0
  253. data/libnet/src/libnet_build_vrrp.c +117 -0
  254. data/libnet/src/libnet_checksum.c +376 -0
  255. data/libnet/src/libnet_cq.c +395 -0
  256. data/libnet/src/libnet_crc.c +113 -0
  257. data/libnet/src/libnet_dll.c +47 -0
  258. data/libnet/src/libnet_error.c +55 -0
  259. data/libnet/src/libnet_if_addr.c +415 -0
  260. data/libnet/src/libnet_init.c +234 -0
  261. data/libnet/src/libnet_internal.c +310 -0
  262. data/libnet/src/libnet_link_bpf.c +348 -0
  263. data/libnet/src/libnet_link_dlpi.c +785 -0
  264. data/libnet/src/libnet_link_linux.c +310 -0
  265. data/libnet/src/libnet_link_nit.c +125 -0
  266. data/libnet/src/libnet_link_none.c +66 -0
  267. data/libnet/src/libnet_link_pf.c +179 -0
  268. data/libnet/src/libnet_link_snit.c +149 -0
  269. data/libnet/src/libnet_link_snoop.c +166 -0
  270. data/libnet/src/libnet_link_win32.c +346 -0
  271. data/libnet/src/libnet_pblock.c +511 -0
  272. data/libnet/src/libnet_port_list.c +295 -0
  273. data/libnet/src/libnet_prand.c +106 -0
  274. data/libnet/src/libnet_raw.c +257 -0
  275. data/libnet/src/libnet_resolve.c +414 -0
  276. data/libnet/src/libnet_version.c +54 -0
  277. data/libnet/src/libnet_write.c +502 -0
  278. data/libnet/version.h.in +6 -0
  279. data/libnet/win32/CVS/Entries +15 -0
  280. data/libnet/win32/CVS/Repository +1 -0
  281. data/libnet/win32/CVS/Root +1 -0
  282. data/libnet/win32/Libnet-1.1.1-2002.sln +77 -0
  283. data/libnet/win32/Libnet-1.1.1-2003.ncb +0 -0
  284. data/libnet/win32/Libnet-1.1.1-2003.sln +84 -0
  285. data/libnet/win32/Libnet-1.1.1-2003.suo +0 -0
  286. data/libnet/win32/Libnet-1.1.1.vcproj +311 -0
  287. data/libnet/win32/Libnet-latest.ncb +0 -0
  288. data/libnet/win32/Libnet-latest.opt +0 -0
  289. data/libnet/win32/Libnet-latest.sln +77 -0
  290. data/libnet/win32/Libnet-latest.suo +0 -0
  291. data/libnet/win32/Libnet-latest.vcproj +311 -0
  292. data/libnet/win32/Libnet.dsp +337 -0
  293. data/libnet/win32/Libnet.dsw +32 -0
  294. data/libnet/win32/README.txt +57 -0
  295. data/libnet/win32/libnet_dll.def +164 -0
  296. data/test/tc_arp.rb +169 -0
  297. data/test/tc_class.rb +219 -0
  298. data/test/tc_ethernet.rb +97 -0
  299. data/test/tc_header.rb +163 -0
  300. data/test/tc_init.rb +25 -0
  301. data/test/tc_ipv4.rb +219 -0
  302. data/test/tc_ipv6.rb +235 -0
  303. data/test/tc_udp.rb +229 -0
  304. data/test/tc_vlan.rb +118 -0
  305. data/test/ts_all.rb +15 -0
  306. metadata +401 -0
@@ -0,0 +1,609 @@
1
+ require 'active_support'
2
+
3
+ class Libnet
4
+ class Header # :nodoc:
5
+ include Helpers
6
+
7
+ HWADDR_RE = /^[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}$/
8
+ IPADDR_RE = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
9
+ DEFAULT_OPTS = {
10
+ :units => :bytes,
11
+ :read_only => false,
12
+ :optional => false,
13
+ :aliases => []
14
+ }
15
+ UNIT_MULTIPLIERS = {
16
+ :bits => 1,
17
+ :bytes => 8,
18
+ :words => 16,
19
+ }
20
+
21
+ class_inheritable_accessor :assignment_filters
22
+ class_inheritable_accessor :required_fields
23
+ class_inheritable_accessor :optional_fields
24
+ class_inheritable_accessor :read_only_fields
25
+
26
+ class << self
27
+ def inherited(cl)
28
+ cl.assignment_filters = {}
29
+ cl.required_fields = []
30
+ cl.optional_fields = []
31
+ cl.read_only_fields = []
32
+ end
33
+
34
+ def unsigned_field(name, size, opts = {})
35
+ opts = DEFAULT_OPTS.merge opts
36
+ size = size * UNIT_MULTIPLIERS[opts[:units]]
37
+ ivar = "@#{name}".to_sym
38
+ range = 0..2**size-1
39
+
40
+ unless opts[:read_only]
41
+ self.class_eval do
42
+ define_method("#{name}=") do |v|
43
+ if self.assignment_filters.has_key? name
44
+ v = self.assignment_filters[name].call(v)
45
+ end
46
+
47
+ check_integer(v)
48
+
49
+ unless range.include? v
50
+ raise ArgumentError, "value #{v} is out of range for field '#{name}'"
51
+ end
52
+
53
+ instance_variable_set(ivar, v)
54
+ end
55
+ end
56
+ end
57
+
58
+ add_field(name, opts)
59
+
60
+ nil
61
+ end
62
+
63
+ def octets_field(name, size = nil, opts = {})
64
+ opts = DEFAULT_OPTS.merge opts
65
+ ivar = "@#{name}".to_sym
66
+
67
+ unless opts[:read_only]
68
+ self.class_eval do
69
+ define_method("#{name}=") do |v|
70
+ value = v.dup
71
+ if self.assignment_filters.has_key? name
72
+ value = self.assignment_filters[name].call(v)
73
+ end
74
+
75
+ check_string(value)
76
+
77
+ if size && value.length != size
78
+ raise ArgumentError, "value must be #{size} bytes long for field '#{name}'"
79
+ end
80
+
81
+ instance_variable_set(ivar, value)
82
+ end
83
+ end
84
+ end
85
+
86
+ add_field(name, opts)
87
+
88
+ nil
89
+ end
90
+
91
+ def assignment_filter(*fields, &blk)
92
+ fields.each do |f|
93
+ self.assignment_filters[f] = blk
94
+ end
95
+ end
96
+
97
+ def decode(bytes)
98
+ raise NotImplementedError, "class #{self} has not implemented a decode method"
99
+ end
100
+
101
+ def fields
102
+ self.required_fields + self.optional_fields + self.read_only_fields
103
+ end
104
+
105
+ def add_field(name, opts)
106
+ ivar = "@#{name}".to_sym
107
+
108
+ # add this field to the list
109
+ if opts[:read_only]
110
+ self.read_only_fields << name
111
+ elsif opts[:optional]
112
+ self.optional_fields << name
113
+ else
114
+ self.required_fields << name
115
+ end
116
+
117
+ self.class_eval do
118
+ # create the query method
119
+ define_method("#{name}?") do
120
+ !!instance_variable_get(ivar)
121
+ end
122
+
123
+ # create the reader method
124
+ define_method(name) do
125
+ instance_variable_get(ivar)
126
+ end
127
+
128
+ # create any aliases
129
+ opts[:aliases].each do |a|
130
+ alias_method a, name
131
+ alias_method "#{a}?".to_sym, "#{name}?".to_sym
132
+
133
+ unless opts[:read_only]
134
+ alias_method "#{a}=".to_sym, "#{name}=".to_sym
135
+ end
136
+ end
137
+
138
+ # add an auto-checksum method if this is a checksum field
139
+ if name == :checksum
140
+ define_method(:auto_checksum?) do |bool|
141
+ instance_variable_set(:@auto_checksum)
142
+ end
143
+
144
+ define_method(:auto_checksum=) do |bool|
145
+ instance_variable_set(:@auto_checksum, bool)
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ private_class_method :add_field
153
+ attr_reader :ptag
154
+
155
+ def initialize(bytes = nil)
156
+ self.class.decode(bytes) if bytes
157
+
158
+ # only used if class has a checksum field
159
+ @auto_checksum = true
160
+
161
+ self
162
+ end
163
+
164
+ private
165
+
166
+ def check_packable
167
+ not_set = []
168
+
169
+ self.required_fields.each do |f|
170
+ not_set << f unless self.send("#{f}?")
171
+ end
172
+
173
+ if not_set.length > 0
174
+ raise ArgumentError, "the following #{self.class} required fields have not been set: " + not_set.join(", ")
175
+ end
176
+
177
+ true
178
+ end
179
+ end
180
+
181
+ # = Ethernet
182
+ #
183
+ # Class to represent an IEEE 802.3 Ethernet header.
184
+ #
185
+ # === Example
186
+ #
187
+ # e = Libnet::Ethernet.new
188
+ #
189
+ # e.dst = 'aa:bb:cc:dd:ee:ff'
190
+ # e.src = [0x11, 0x22, 0x33, 0x44, 0x55, 0x66].pack("C*")
191
+ # e.type = 0x1234
192
+ # e.payload = "this is the message"
193
+ #
194
+ # == Public Class Methods
195
+ #
196
+ # === decode(string) -> new Ethernet object
197
+ #
198
+ # Decode a packed ethernet packet.
199
+ #
200
+ # == Public Instance Methods
201
+ #
202
+ # === dst, dst=, dst?
203
+ # Get/set/query the destination MAC address.
204
+ #
205
+ # === src, src=, src?
206
+ # Get/set/query the source MAC address.
207
+ #
208
+ # === type, type=, type?
209
+ # Get/set/query the protocol type.
210
+ #
211
+ # === payload, payload=, payload?
212
+ # Get/set/query the ethernet payload. Optional.
213
+ #
214
+ # === ptag
215
+ # Get the ptag value for this header object. Set by the Libnet builder method.
216
+ #
217
+ class Ethernet < Header
218
+ octets_field :dst, 6
219
+ octets_field :src, 6
220
+ unsigned_field :type, 2
221
+ octets_field :payload, nil, :optional => true
222
+
223
+ assignment_filter(:dst, :src) do |v|
224
+ if v.match(HWADDR_RE)
225
+ Libnet.hex_aton(v)
226
+ else
227
+ v
228
+ end
229
+ end
230
+ end
231
+
232
+ # = VLAN
233
+ #
234
+ # Class to represent an IEEE 802.1q VLAN tagging header.
235
+ #
236
+ # === Example
237
+ #
238
+ # v = Libnet::VLAN.new
239
+ #
240
+ # v.dst = 'aa:bb:cc:dd:ee:ff'
241
+ # v.src = '11:22:33:44:55:66'
242
+ # v.tpi = 0xbeef
243
+ # v.priority = 6
244
+ # v.cfi = 0
245
+ # v.id = 2730
246
+ # v.type = 0x0800
247
+ # v.payload = "this is the message"
248
+ #
249
+ # == Public Class Methods
250
+ #
251
+ # === decode(string) -> new VLAN object
252
+ #
253
+ # Decode a packed vlan packet.
254
+ #
255
+ # == Public Instance Methods
256
+ #
257
+ # === dst, dst=, dst?
258
+ # Get/set/query the destination MAC address.
259
+ #
260
+ # === src, src=, src?
261
+ # Get/set/query the source MAC address.
262
+ #
263
+ # === tpi, tpi=, tpi?
264
+ # Get/set/query the tag protocol identifier.
265
+ #
266
+ # === priority, priority=, priority?
267
+ # Get/set/query the priority.
268
+ #
269
+ # === cfi, cfi=, cfi?
270
+ # Get/set/query the canonical format indicator.
271
+ #
272
+ # === id, id=, id?
273
+ # Get/set/query the vlan identifier.
274
+ #
275
+ # === len, len=, len? or type, type=, type?
276
+ # Get/set/query the length/type.
277
+ #
278
+ # === payload, payload=, payload?
279
+ # Get/set/query the payload.
280
+ #
281
+ # === ptag
282
+ # Get the ptag value for this header object. Set by the Libnet builder method.
283
+ #
284
+ class VLAN < Header
285
+ octets_field :dst, 6
286
+ octets_field :src, 6
287
+ unsigned_field :tpi, 2
288
+ unsigned_field :priority, 3, :units => :bits
289
+ unsigned_field :cfi, 1, :units => :bits
290
+ unsigned_field :id, 12, :units => :bits
291
+ unsigned_field :len, 2, :aliases => [ :type ]
292
+ octets_field :payload, nil, :optional => true
293
+
294
+ assignment_filter(:dst, :src) do |v|
295
+ if v.match(HWADDR_RE)
296
+ Libnet.hex_aton(v)
297
+ else
298
+ v
299
+ end
300
+ end
301
+ end
302
+
303
+ # = IPv4
304
+ #
305
+ # Class to represent a version 4 RFC 791 Internet Protocol (IP) header.
306
+ #
307
+ # === Example
308
+ #
309
+ # i = Libnet::IPv4.new
310
+ #
311
+ # i.tos = 0x12
312
+ # i.length = Libnet::HL_IPV4 + payload.length
313
+ # i.id = 0x4321
314
+ # i.frag_off = 0
315
+ # i.ttl = 72
316
+ # i.protocol = Libnet::IPPROTO_UDP
317
+ # i.checksum = 0
318
+ # i.src_ip = '192.168.1.2'
319
+ # i.dst_ip = 0xc0a80103
320
+ # i.payload = "this is the message"
321
+ #
322
+ # == Public Class Methods
323
+ #
324
+ # === decode(string) -> new IPv4 object
325
+ #
326
+ # Decode a packed IPv4 packet.
327
+ #
328
+ # == Public Instance Methods
329
+ #
330
+ # === version, version?
331
+ # Get/query the IP version.
332
+ #
333
+ # === ihl, ihl?
334
+ # Get/query the IP header length.
335
+ #
336
+ # === tos, tos=, tos?
337
+ # Get/set/query the type of service.
338
+ #
339
+ # === length, length=, length?
340
+ # Get/set/query the total length of the IP packet.
341
+ #
342
+ # === id, id=, id?
343
+ # Get/set/query the IP identification number.
344
+ #
345
+ # === frag_off, frag_off=, frag_off?
346
+ # Get/set/query the fragmentation bits and offset.
347
+ #
348
+ # === ttl, ttl=, ttl?
349
+ # Get/set/query the time to live.
350
+ #
351
+ # === protocol, protocol=, protocol?
352
+ # Get/set/query the upper layer protocol.
353
+ #
354
+ # === checksum, checksum=, checksum?
355
+ # Get/set/query the checksum. Set to 0 for Libnet to autofill.
356
+ #
357
+ # === src_ip, src_ip=, src_ip?
358
+ # Get/set/query the source IP address.
359
+ #
360
+ # === dst_ip, dst_ip=, dst_ip?
361
+ # Get/set/query the destination IP address.
362
+ #
363
+ # === payload, payload=, payload?
364
+ # Get/set/query the payload.
365
+ #
366
+ # === ptag
367
+ # Get the ptag value for this header object. Set by the Libnet builder method.
368
+ #
369
+ class IPv4 < Header
370
+ unsigned_field :version, 4, :units => :bits, :read_only => true
371
+ unsigned_field :ihl, 4, :units => :bits, :read_only => true
372
+ unsigned_field :tos, 1
373
+ unsigned_field :length, 2
374
+ unsigned_field :id, 2
375
+ unsigned_field :frag_off, 2
376
+ unsigned_field :ttl, 1
377
+ unsigned_field :protocol, 1
378
+ unsigned_field :checksum, 2
379
+ unsigned_field :src_ip, 4
380
+ unsigned_field :dst_ip, 4
381
+ octets_field :payload, nil, :optional => true
382
+
383
+ assignment_filter(:src_ip, :dst_ip) do |v|
384
+ if v.is_a? String
385
+ Libnet.ipv4_aton(v)
386
+ else
387
+ v
388
+ end
389
+ end
390
+ end
391
+
392
+ # = IPv6
393
+ #
394
+ # Class to represent a version 6 RFC 2460 Internet Protocol (IP) header.
395
+ #
396
+ # === Example
397
+ #
398
+ # i = Libnet::IPv6.new
399
+ #
400
+ # i.traffic_class = 0x22
401
+ # i.flow_label = 0xdbeef
402
+ # i.length = Libnet::HL_IPV6 + payload.length
403
+ # i.next_header = Libnet::IPPROTO_UDP
404
+ # i.hop_limit = 24
405
+ # i.src_ip = [
406
+ # 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
407
+ # 0xcc, 0xdd, 0xee, 0xff
408
+ # ].pack("C*")
409
+ # i.dst_ip = "aabb:aabb:ccdd:ccdd:eeff:eeff:2233:2233"
410
+ # i.payload = "this is the message"
411
+ #
412
+ # == Public Class Methods
413
+ #
414
+ # === decode(string) -> new IPv6 object
415
+ #
416
+ # Decode a packed IPv6 packet.
417
+ #
418
+ # == Public Instance Methods
419
+ #
420
+ # === version, version?
421
+ # Get/query the IP version.
422
+ #
423
+ # === traffic_class, traffic_class=, traffic_class?
424
+ # Get/set/query the traffic class.
425
+ #
426
+ # === flow_label, flow_label=, flow_label?
427
+ # Get/set/query the flow label.
428
+ #
429
+ # === length, length=, length?
430
+ # Get/set/query the length of the IPv6 packet minus the 40 byte IPv6 header.
431
+ #
432
+ # === next_header, next_header=, next_header?
433
+ # Get/set/query the next header.
434
+ #
435
+ # === hop_limit, hop_limit=, hop_limit?
436
+ # Get/set/query the hop limit.
437
+ #
438
+ # === src_ip, src_ip=, src_ip?
439
+ # Get/set/query the source IPv6 address.
440
+ #
441
+ # === dst_ip, dst_ip=, dst_ip?
442
+ # Get/set/query the destination IPv6 address.
443
+ #
444
+ # === payload, payload=, payload?
445
+ # Get/set/query the payload.
446
+ #
447
+ # === ptag
448
+ # Get the ptag value for this header object. Set by the Libnet builder method.
449
+ #
450
+ class IPv6 < Header
451
+ unsigned_field :version, 4, :units => :bits, :read_only => true
452
+ unsigned_field :traffic_class, 1
453
+ unsigned_field :flow_label, 20, :units => :bits
454
+ unsigned_field :length, 2
455
+ unsigned_field :next_header, 1
456
+ unsigned_field :hop_limit, 1
457
+ octets_field :src_ip, 16
458
+ octets_field :dst_ip, 16
459
+ octets_field :payload, nil, :optional => true
460
+
461
+ assignment_filter(:src_ip, :dst_ip) do |v|
462
+ if v.length != 16
463
+ Libnet.ipv6_aton(v)
464
+ else
465
+ v
466
+ end
467
+ end
468
+ end
469
+
470
+ # = UDP
471
+ #
472
+ # Class to represent an RFC 768 User Datagram Protocol (UDP) header.
473
+ #
474
+ # === Example
475
+ #
476
+ # u = Libnet::UDP.new
477
+ #
478
+ # u.src_port = 0x4321
479
+ # u.dst_port = 0xabcd
480
+ # u.length = Libnet::HL_UDP + payload.length
481
+ # u.checksum = 0x1111
482
+ # u.payload = payload
483
+ #
484
+ # == Public Class Methods
485
+ #
486
+ # === decode(string) -> new UDP object
487
+ #
488
+ # Decode a packed UDP packet.
489
+ #
490
+ # == Public Instance Methods
491
+ #
492
+ # === src_port, src_port=, src_port?
493
+ # Get/set/query the source port.
494
+ #
495
+ # === dst_port, dst_port=, dst_port?
496
+ # Get/set/query the destination port.
497
+ #
498
+ # === length, length=, length?
499
+ # Get/set/query the total length of the UDP packet.
500
+ #
501
+ # === checksum, checksum=, checksum?
502
+ # Get/set/query the checksum. Set to 0 for Libnet to autofill.
503
+ #
504
+ # === payload, payload=, payload?
505
+ # Get/set/query the payload.
506
+ #
507
+ # === ptag
508
+ # Get the ptag value for this header object. Set by the Libnet builder method.
509
+ #
510
+ class UDP < Header
511
+ unsigned_field :src_port, 2
512
+ unsigned_field :dst_port, 2
513
+ unsigned_field :length, 2
514
+ unsigned_field :checksum, 2
515
+ octets_field :payload, nil, :optional => true
516
+ end
517
+
518
+ # = ARP
519
+ #
520
+ # Class to represent an Address Resolution Protocol (ARP) header. Depending
521
+ # on the +operation+ value, the method builds one of several different types
522
+ # of RFC 826 or RFC 903 RARP packets.
523
+ #
524
+ # === Example
525
+ #
526
+ # a = Libnet::ARP.new
527
+ #
528
+ # a.htype = 1
529
+ # a.protocol = 0x0800
530
+ # a.hlen = 6
531
+ # a.plen = 4
532
+ # a.operation = 1
533
+ # a.sender_haddr = 'aa:bb:cc:dd:ee:ff'
534
+ # a.sender_paddr = '192.168.1.100'
535
+ # a.target_haddr = '11:22:33:44:55:66'
536
+ # a.target_paddr = '192.168.1.123'
537
+ #
538
+ # == Public Class Methods
539
+ #
540
+ # === decode(string) -> new ARP object
541
+ #
542
+ # Decode a packed ARP packet.
543
+ #
544
+ # == Public Instance Methods
545
+ #
546
+ # === htype, htype=, htype?
547
+ # Get/set/query the hardware address type.
548
+ #
549
+ # === protocol, protocol=, protocol?
550
+ # Get/set/query the protocol address type.
551
+ #
552
+ # === hlen, hlen=, hlen?
553
+ # Get/set/query the hardware address length.
554
+ #
555
+ # === plen, plen=, plen?
556
+ # Get/set/query the protocol address length.
557
+ #
558
+ # === operation, operation=, operation?
559
+ # Get/set/query the ARP operation type.
560
+ #
561
+ # === sender_haddr, sender_haddr=, sender_haddr?
562
+ # Get/set/query the sender's hardware address.
563
+ #
564
+ # === sender_paddr, sender_paddr=, sender_paddr?
565
+ # Get/set/query the sender's protocol address.
566
+ #
567
+ # === target_haddr, target_haddr=, target_haddr?
568
+ # Get/set/query the target's hardware address.
569
+ #
570
+ # === target_paddr, target_paddr=, target_paddr?
571
+ # Get/set/query the target' protocol address.
572
+ #
573
+ # === payload, payload=, payload?
574
+ # Get/set/query the payload.
575
+ #
576
+ # === ptag
577
+ # Get the ptag value for this header object. Set by the Libnet builder method.
578
+ #
579
+ class ARP < Header
580
+ unsigned_field :htype, 2
581
+ unsigned_field :protocol, 2
582
+ unsigned_field :hlen, 1
583
+ unsigned_field :plen, 1
584
+ unsigned_field :operation, 2
585
+ octets_field :sender_haddr
586
+ octets_field :sender_paddr
587
+ octets_field :target_haddr
588
+ octets_field :target_paddr
589
+ octets_field :payload, nil, :optional => true
590
+
591
+ assignment_filter(:sender_haddr, :target_haddr) do |v|
592
+ if v.match(HWADDR_RE)
593
+ Libnet.hex_aton(v)
594
+ else
595
+ v
596
+ end
597
+ end
598
+
599
+ assignment_filter(:sender_paddr, :target_paddr) do |v|
600
+ if v.match(IPADDR_RE)
601
+ ip = Libnet.ipv4_aton(v)
602
+ [ ip ].pack("N")
603
+ else
604
+ v
605
+ end
606
+ end
607
+ end
608
+ end
609
+
@@ -0,0 +1,19 @@
1
+ class Libnet
2
+ module Helpers # :nodoc:
3
+ def check_integer(v)
4
+ unless v.is_a? Integer
5
+ raise TypeError, "value must be an Integer"
6
+ end
7
+
8
+ nil
9
+ end
10
+
11
+ def check_string(v)
12
+ unless v.is_a? String
13
+ raise TypeError, "value must be a String"
14
+ end
15
+
16
+ nil
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+
2
+ class Libnet
3
+ attr_reader :injection_type
4
+
5
+ # :call-seq:
6
+ # Libnet.hexdump(bytes) # -> string
7
+ #
8
+ # Returns a string containing a hexdump of the given byte string.
9
+ #
10
+ # Example:
11
+ # Libnet.hexump("foobar")
12
+ #
13
+ # produces the following string:
14
+ #
15
+ # 0x00000000: 666f6f62 6172
16
+ def self.hexdump(bytes)
17
+ offset = 0
18
+ i = 0
19
+ dump = "0x00000000: "
20
+
21
+ bytes.each_byte do |b|
22
+ if i != 0
23
+ if i % 16 == 0
24
+ offset += 16
25
+ dump += sprintf("\n0x%08x: ", offset)
26
+ elsif i % 4 == 0
27
+ dump += " "
28
+ end
29
+ end
30
+
31
+ dump += sprintf("%02x", b)
32
+
33
+ i += 1
34
+ end
35
+
36
+ dump += "\n"
37
+ end
38
+ end
39
+
@@ -0,0 +1,24 @@
1
+ /Makefile.am.common/1.3/Sat Jan 3 20:31:00 2004//
2
+ /acconfig.h/1.2/Sat Jan 3 20:31:00 2004//
3
+ /config.guess/1.1.1.1/Thu Jun 26 21:55:10 2003//
4
+ /config.sub/1.1.1.1/Thu Jun 26 21:55:10 2003//
5
+ /install-sh/1.1.1.1/Thu Jun 26 21:55:10 2003//
6
+ /libnet-config.in/1.3/Sat Jan 3 20:31:00 2004//
7
+ /missing/1.1.1.1/Thu Jun 26 21:55:10 2003//
8
+ /mkinstalldirs/1.1.1.1/Thu Jun 26 21:55:10 2003//
9
+ /version.h.in/1.1.1.1/Thu Jun 26 21:55:10 2003//
10
+ D/autom4te.cache////
11
+ D/doc////
12
+ D/include////
13
+ D/man////
14
+ D/sample////
15
+ D/src////
16
+ D/win32////
17
+ /acinclude.m4/1.3/Thu Jan 15 23:53:06 2004//
18
+ /README/1.4/Mon Mar 1 20:26:11 2004//
19
+ /aclocal.m4/1.9/Mon Mar 1 20:26:11 2004//
20
+ /configure/1.8/Mon Mar 1 20:02:37 2004//
21
+ /configure.in/1.9/Mon Mar 1 20:26:11 2004//
22
+ /Makefile.in/1.16/Thu Mar 11 18:50:20 2004//
23
+ /Makefile.am/1.7/Wed Mar 10 20:57:09 2004//
24
+ /VERSION/1.12/Mon Mar 29 17:20:53 2004//
@@ -0,0 +1 @@
1
+ /usr/local/CVS/libnet
data/libnet/CVS/Root ADDED
@@ -0,0 +1 @@
1
+ mike@66.234.207.232:/usr/local/CVS
@@ -0,0 +1,15 @@
1
+ # $Id: Makefile.am,v 1.7 2004/03/01 20:26:11 mike Exp $
2
+ #
3
+ # Libnet automake information file
4
+ # Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
5
+ # All rights reserved.
6
+ #
7
+ # Process this file with automake to produce a Makefile.in script.
8
+
9
+ include $(top_srcdir)/Makefile.am.common
10
+
11
+ SUBDIRS = include src sample
12
+
13
+ EXTRA_DIST = Makefile.am.common
14
+
15
+ bin_scripts = libnet-config