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,134 @@
1
+ ===============================================================================
2
+ $Id: DESIGN_NOTES,v 1.3 2004/01/17 07:51:19 mike Exp $
3
+ LIBNET 1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
4
+ http://www.packetfactory.net/libnet
5
+ ===============================================================================
6
+
7
+
8
+ DESIGN NOTES
9
+
10
+ In order to remove most of the decisions a user had to make (how much
11
+ memory to allocate for a packet, where to build the packet headers, where
12
+ to do the checksums, how to inject the packet, etc) I decided to move ALL
13
+ of that logic into the library, behind the scenes. To initialize
14
+ things and get an initial libnet context, the applications programmer
15
+ calls:
16
+
17
+ libnet_t *l;
18
+ l = libnet_init(INJECTION_TYPE, PROTOCOL, DEVICE, ERRBUFFER);
19
+
20
+ where:
21
+
22
+ INJECTION_TYPE = LIBNET_RAW4 (ipv4 raw socket)
23
+ LIBNET_RAW6 (ipv6 raw socket)
24
+ LIBNET_LINK (link-layer socket)
25
+ LIBNET_RAW4_ADV (advanced mode)
26
+ LIBNET_RAW6_ADV (advanced mode)
27
+ LIBNET_LINK_ADV (advanced mode)
28
+
29
+ PROTOCOL = IP protocol to be used for the raw socket. This is
30
+ ignored for the link-layer, and almost always
31
+ IPPROTO_RAW for ipv4.
32
+
33
+ DEVICE = The canoical name of the device, used only with the link
34
+ layer stuff. For ipv4 raw socket, you can leave this
35
+ NULL. If it's NULL with the link-layer, libnet will try
36
+ to find a suitable device.
37
+
38
+ ERRBUFFER = Until we have our libnet context l, this is where
39
+ errors will be.
40
+
41
+ Inside of this newly created context we have a ton of stuff including a
42
+ file descriptor for the packet device the injection type, the device name
43
+ (if applicable) a pointer to the libnet protocol block structure and some
44
+ other ancillary data.
45
+
46
+ Additionally, we will soon be supporting context manipulation functions
47
+ that will allow the user to set certain flags inside the context. This
48
+ interface will be akin to libnet_toggle_checksum() for those of you who
49
+ care.
50
+
51
+ When a packet is first constructed, the protocol block (pblock) stuff comes
52
+ into play. On the outside, to an applications programmer, a packet is
53
+ constructed more or less like normal (with a few notable exceptions):
54
+
55
+ libnet_ptag_t ip_tag;
56
+ ip_tag = libnet_build_ipv4(
57
+ LIBNET_UDP_H,
58
+ 0,
59
+ 242,
60
+ 0,
61
+ 64,
62
+ IPPROTO_UDP,
63
+ 0, /* NEW: checksum */
64
+ src_ip,
65
+ dst_ip,
66
+ NULL,
67
+ 0,
68
+ l, /* NEW: libnet context */
69
+ 0 /* NEW: libnet ptag */
70
+ );
71
+
72
+ The checksum allows an applications programmer to decide if he wants to
73
+ specify his own random value (useful in NIDS fooling) or precompute the
74
+ sum elsewhere, or leave it zero and by default libnet will take care of it
75
+ (although this is over-ridable). The libnet context is the opague
76
+ pointer we allocated earlier and will show up in just about every libnet
77
+ function call from here on out. The libnet ptag is a way to reference an
78
+ ALREADY BUILT protocol block. This is necessary if you want to change
79
+ some values of a header inside of a packet injection loop.
80
+
81
+ So, when you call a build function, internally, it's a completely new
82
+ system. If the item you're constructing is NEW, a new pblock will be
83
+ allocated and linked onto the end of the list. It may be helpful to think
84
+ of this as a "protocol stack" because you MUST build your packets IN
85
+ ORDER, from the top of the protocol stack on down (i.e.: tcp -> ip ->
86
+ ethernet). Once you build a new protocol block, it's "pushed down on the
87
+ stack" and you move on to the next. However, this analogy breaks down
88
+ because you can modify any one of these items and when they're assembled
89
+ for the final packet, libnet starts at the head of the list. It may be
90
+ MORE helpful to think of the pblock chain as a doubly linked FIFO
91
+ queue, because that's what it is. :)
92
+
93
+ For example:
94
+
95
+ libnet_ptag_t 1;
96
+ libnet_ptag_t 2;
97
+ libnet_ptag_t 3;
98
+
99
+ 1 = libnet_build_data(blah, l, 0);
100
+ 2 = libnet_build_tcp(blah, l, 0);
101
+ 3 = libnet_build_ipv4(blah, l, 0);
102
+
103
+ Will result in:
104
+ ---------- ---------- ----------
105
+ l->protocol_blocks--->| data |----->| tcp |----->| ip |
106
+ | pblock |<-----| pblock |<-----| pblock |----|
107
+ --| ptag: 1| | ptag: 2| | ptag: 3| |
108
+ | ---------- ---------- ---------- v
109
+ | -----
110
+ |-------------------------------------------> ---
111
+ -
112
+
113
+ To access and change the ip header, an additional call to libnet_build_ipv4
114
+ with the ptag argument would be made:
115
+
116
+ libnet_build_ipv4(blah..., l, 3);
117
+
118
+ Note that the ptag DOES NOT CHANGE. Once a pblock is built, its tag is
119
+ set in stone.
120
+
121
+ When it comes time to write the packet to the wire,
122
+ libnet_pblock_coalesce() is called to assemble the packet fragments.
123
+
124
+ 1) Gather up all of the pblock sizes in order to allocate one
125
+ contiguous block of memory.
126
+ 2) Copy over the packet fragments.
127
+ 3) Check each pblock to see which items need checksums, then perform
128
+ that checksum over each portion (the entire packet is needed for
129
+ some checksums).
130
+
131
+ So that's a quick description of what's going on under the hood. There's
132
+ more, but this should be enough to get you started.
133
+
134
+ EOF
@@ -0,0 +1,172 @@
1
+ ===============================================================================
2
+ $Id: MIGRATION,v 1.2 2004/01/03 20:31:00 mike Exp $
3
+ LIBNET 1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
4
+ http://www.packetfactory.net/libnet
5
+ ===============================================================================
6
+
7
+
8
+ MIGRATING YOUR CODE AND QUICKSTART
9
+
10
+ Using Libnet 1.1 you will find it MUCH simpler to build and write packets
11
+ than before. Instead of the previous five steps (initialize memory,
12
+ initialize network, build packet, do checksums, write packet) there are
13
+ now only three steps (initialize library, build packet, write packet).
14
+ In order to port your existing code, you will mainly be REMOVING
15
+ function calls and variables.
16
+
17
+ 1) Start with code removal:
18
+
19
+ - Remove all calls to libnet_init_packet() / packet malloc()ing and
20
+ all associated variables.
21
+ - Remove all calls to libnet_open_raw_sock() / libnet_open_link_layer()
22
+ and all associated variables.
23
+ - Remove all calls to libnet_do_checksum() and all associated
24
+ variables.
25
+
26
+ 2) Continue with code addition and modification:
27
+
28
+ - You will need a single "libnet_t *l" which is your libnet file
29
+ context and an error buffer:
30
+
31
+ libnet_t *l
32
+ char errbuf[LIBNET_ERRBUF_SIZE];
33
+
34
+ l = libnet_init(
35
+ LIBNET_RAW4, /* or LIBNET_LINK or LIBNET_RAW6 */
36
+ NULL, /* or device if you using LIBNET_LINK */
37
+ errbuf);
38
+
39
+ - The libnet_build functions are largely unchanged with a few
40
+ important differences:
41
+
42
+ 1) Packets headers MUST be stacked IN ORDER. This is
43
+ intuitive and shouldn't be a problem. Due to the way
44
+ individual packet header memory is allocated and how
45
+ packet pieces are combined to build a packet they HAVE to
46
+ be built IN ORDER, from the high end of the protocol stack
47
+ on down. ie: using the raw interface to build a NTP
48
+ packet, you would:
49
+ libnet_build_ntp(...)
50
+ libnet_build_udp(...)
51
+ libnet_build_ipv4(...)
52
+ To build the same packet using the LINK interface on
53
+ top of ethernet you would:
54
+ libnet_build_ntp(...)
55
+ libnet_build_udp(...)
56
+ libnet_build_ipv4(...)
57
+ libnet_build_ethernet(...)
58
+ 1a) There is the option now of using libnet_autobuild_ipv4()
59
+ and libnet_autobuild_ethernet() which have fewer
60
+ arguments and smaller stack frames and are a bit more
61
+ convenient.
62
+ 2) The libnet_build functions return a libnet_ptag_t datatype
63
+ on success or -1 on error. This ptag is your
64
+ "protocol/packet tag" so you can find this header again
65
+ if you needed to modify it later on. If you don't need
66
+ to modify the packet header you can throw this value
67
+ away. You should definitely check for error now on
68
+ your build functions. Alot's going on down there fellas.
69
+ 2a) NOTE that after packets are built, they may accessed
70
+ independently of construction order via the saved ptag.
71
+ 3) They NO LONGER ACCEPT BUFFER ARGUMENTS. This is ALL
72
+ done internally. The last TWO arguments are the libnet
73
+ context you created in your call to libnet_init() and
74
+ an OPTIONAL ptag argument. The ptag argument, if non-zero,
75
+ specifes a packet tag to an ALREADY EXISTING packet header
76
+ that will be OVERWRITTEN with the values specified in
77
+ this libnet_build function call. This is how you modify
78
+ existing packet header pieces. If this ptag is 0,
79
+ a new protocol block is allocated and the packet is
80
+ pushed down on the "protocol stack".
81
+ 4) For the functions that build headers that have checksums
82
+ these are NOW SPECIFIED AS AN ARGUMENT. This adds more
83
+ flexibility in how checksums are done (you can leave the
84
+ field 0, put in a random value, precompute it on your own,
85
+ or let the library do it). By default, when you build
86
+ a header, a "DO_CHECKSUM" flag will be set. This means
87
+ the library will compute the checksum for the header
88
+ and possibly over the data before the packet is written.
89
+ To clear this flag, there is a special macro you
90
+ can call on the ptag refering to that header.
91
+ 5) For the functions that have a length, it now specifies
92
+ the TOTAL packet length from that protocol unit on down.
93
+ For IP, that would be the entire packet length. For
94
+ TCP, that would be TCP and any possible data.
95
+ 6) Nomenclature support for the eventual support of ipv6
96
+ has been added.
97
+
98
+ libnet_ptag_t ip_tag;
99
+ libnet_ptag_t tcp_tag;
100
+
101
+ tcp_tag = libnet_build_tcp(
102
+ src_prt, /* source TCP port */
103
+ dst_prt, /* destination TCP port */
104
+ 0xffff, /* sequence number */
105
+ 0x53, /* acknowledgement number */
106
+ TH_SYN, /* control flags */
107
+ 1024, /* window size */
108
+ 0xd00d, /* checksum */
109
+ 0, /* urgent pointer */
110
+ LIBNET_TCP_H /* TCP packet size */
111
+ NULL, /* payload (none) */
112
+ 0, /* payload length */
113
+ l, /* libnet context */
114
+ 0); /* ptag */
115
+
116
+ ip_tag = libnet_build_ipv4(
117
+ LIBNET_TCP_H + LIBNET_IPV4_H,/* total packet len */
118
+ IPTOS_LOWDELAY, /* tos */
119
+ ip_id, /* IP ID */
120
+ 0, /* IP Frag */
121
+ 64, /* TTL */
122
+ IPPROTO_TCP, /* protocol */
123
+ 0, /* checksum */
124
+ src_ip, /* source ip */
125
+ dst_ip, /* dest ip */
126
+ NULL, /* payload (none) */
127
+ 0, /* payload size */
128
+ l, /* libnet context */
129
+ 0); /* ptag */
130
+
131
+ Now, if you wanted to modify one of these headers in a loop
132
+ somewhere you would:
133
+
134
+ int i;
135
+ for (ip_tag, tcp_tag = LIBNET_PTAG_INITIALIZER, i = 0; i < 10; i++)
136
+ {
137
+ tcp_tag = libnet_build_tcp(++src_prt, ..., l, tcp_tag);
138
+ ip_tag = libnet_build_ipv4(..., ++ip_id, ..., l, ip_tag);
139
+ /* do something */
140
+ }
141
+ Since we are specifying a ptag for an existing header, the
142
+ build function will NOT create a new header and append it to
143
+ the list, it will FIND the one referenced by the ptag and UPDATE
144
+ it. Since there is nothing new being created, order is NOT
145
+ important here.
146
+
147
+ Also note that it's perfectly fine to wrap the loop around the
148
+ initial building of the packets. Since we're initializing the
149
+ ptags (to be zero), the first call into the builder functions
150
+ will allocate the memory and create the packet blocks. These
151
+ calls will return ptag values. The next calls will modify
152
+ these headers since the ptags will not be NULL.
153
+
154
+ - Finally, we write the packet. Checksums are computed, by default
155
+ for each protocol header that requires one. If the user specifies
156
+ a non-zero value, by default, this will be used INSTEAD of a
157
+ libnet computed checksum. This behavior is overridable with:
158
+
159
+ Turn ON checksums for header referenced by ptag:
160
+ libnet_toggle_checksum(l, ptag, 1)
161
+
162
+ Turn OFF checksums for header referenced by ptag:
163
+ libnet_toggle_checksum(l, ptag, 0)
164
+
165
+ Note, the packet header MUST exist before you can toggle this setting.
166
+
167
+ int c;
168
+ c = libnet_write(l);
169
+
170
+ Boom. You're done. Now go read the sample code.
171
+
172
+ EOF
@@ -0,0 +1,161 @@
1
+ ===============================================================================
2
+ $Id: PACKET_BUILDING,v 1.2 2004/01/03 20:31:00 mike Exp $
3
+ LIBNET 1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
4
+ http://www.packetfactory.net/libnet
5
+ ===============================================================================
6
+
7
+
8
+ ADDING A NEW PACKET BUILDER
9
+
10
+ Adding a new packet building module is usually pretty simple. It depends
11
+ completely on the complexity of the protocol. The following document
12
+ shows you how to add a packet builder for a simple protocol with a
13
+ static header size, but these concepts can be extended to a complex
14
+ protocol also.
15
+
16
+ 1) Start by defining your protocol header format in libnet-headers.h:
17
+
18
+ #define LIBNET_XXX_H 0xSIZE
19
+
20
+ struct XXX_hdr
21
+ {
22
+ u_char field1;
23
+ u_short field2;
24
+ u_long field3;
25
+ };
26
+
27
+ 2) Add a pblock definition to libnet-structures.h (appened to the list):
28
+
29
+ #define LIBNET_PBLOCK_XXX_H 0xNUMBER
30
+
31
+ 3) Then work from the following template for libnet_build_XXX.c:
32
+
33
+ #if (HAVE_CONFIG_H)
34
+ #include "../include/config.h"
35
+ #endif
36
+ #include "../include/libnet.h"
37
+
38
+
39
+ libnet_ptag_t
40
+ libnet_build_XXX(u_char arg1, u_short arg2, u_long arg3, u_char *payload,
41
+ u_long payload_s, libnet_t *l, libnet_ptag_t ptag)
42
+ {
43
+ /*
44
+ * n is the size of the protocol unit. This is usually the header size
45
+ * plus the payload size. This is also how many bytes are allocated on
46
+ * the heap to hold this protocol unit.
47
+ */
48
+ u_long n;
49
+
50
+ /*
51
+ * h is used inside the pblock structure to let libnet know how big
52
+ * much data to checksum. This is different for different protocols.
53
+ * The IPv4 checksum covers the IP header only, while TCP and UDP
54
+ * checksums cover header and data.
55
+ */
56
+ u_short h;
57
+
58
+ /*
59
+ * p will be used to refer to the protocol block that will either be
60
+ * allocated if the function's pt argument is 0, or located if ptag refers
61
+ * to a previously created protocol unit.
62
+ */
63
+ libnet_pblock_t *p;
64
+
65
+ /*
66
+ * XXX_hdr is the header structure that will be overlaid onto the
67
+ * allocated memory by way of a memcpy.
68
+ */
69
+ struct libnet_XXX_hdr XXX_hdr;
70
+
71
+ /*
72
+ * Here we sanity check to make sure we have a live l.
73
+ */
74
+ if (l == NULL)
75
+ {
76
+ return (-1);
77
+ }
78
+
79
+ n = LIBNET_XXX_H + payload_s;
80
+ h = 0; /* no checksum by default */
81
+
82
+ /*
83
+ * Find the existing protocol block if a ptag is specified, or create
84
+ * a new one.
85
+ */
86
+ p = libnet_pblock_probe(l, pt, n, LIBNET_PBLOCK_XXX_H);
87
+ if (p == NULL)
88
+ {
89
+ return (-1);
90
+ }
91
+
92
+ /*
93
+ * Build your packet here. Be sure to call appropriate endian conversion
94
+ * routines.
95
+ */
96
+ XXX_hdr.field1 = arg1;
97
+ XXX_hdr.field2 = htons(arg2);
98
+ XXX_hdr.field3 = htonl(arg3);
99
+
100
+ /*
101
+ * Appened the protocol unit to the list.
102
+ */
103
+ n = libnet_pblock_append(l, p, (u_char *)&XXX_hdr, LIBNET_XXX_H);
104
+ if (n == -1)
105
+ {
106
+ goto bad;
107
+ }
108
+
109
+ /*
110
+ * Sanity check the payload arguments.
111
+ */
112
+ if ((payload && !payload_s) || (!payload && payload_s))
113
+ {
114
+ sprintf(l->err_buf, "%s(): payload inconsistency\n", __FUNCTION__);
115
+ goto bad;
116
+ }
117
+
118
+ /*
119
+ * Append the payload to the list if it exists.
120
+ */
121
+ if (payload && payload_s)
122
+ {
123
+ n = libnet_pblock_append(l, p, payload, payload_s);
124
+ if (n == -1)
125
+ {
126
+ goto bad;
127
+ }
128
+ }
129
+
130
+ /*
131
+ * If this packet header has a checksum field, you'll add this
132
+ * and you'll have to edit libnet_checksum.c to add it to the switch
133
+ * table. You might have to define the protocol number too.
134
+ */
135
+ if (sum == 0 && l->injection_type != LIBNET_RAW4)
136
+ {
137
+ /*
138
+ * If checksum is zero, by default libnet will compute a checksum
139
+ * for the user. The programmer can override this by calling
140
+ * libnet_toggle_checksum(l, ptag, 1);
141
+ */
142
+ libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
143
+ }
144
+
145
+ /*
146
+ * Update the protocol block's meta information and return the protocol
147
+ * tag id of this pblock. This tag will be used to locate the pblock
148
+ * in order to modify the protocol header in subsequent calls.
149
+ */
150
+ return (pt ? pt : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_XXX_H));
151
+ bad:
152
+ libnet_pblock_delete(l, p);
153
+ return (-1);
154
+
155
+ }
156
+ 4) Add it to src/Makefile.am and then automake from the TLD.
157
+ 5) Test the shit out of it.
158
+ 6) Send it over to mike@infonexus.com.
159
+
160
+
161
+ EOF
data/libnet/doc/PORTED ADDED
@@ -0,0 +1,45 @@
1
+ ===============================================================================
2
+ $Id: PORTED,v 1.2 2004/01/03 20:31:00 mike Exp $
3
+ LIBNET 1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
4
+ http://www.packetfactory.net/libnet
5
+ ===============================================================================
6
+
7
+
8
+ 1.1.0 PORTED OPERATING SYSTEMS
9
+
10
+ If you verify libnet building and running successfully (sample code works)
11
+ on a platform not listed here please send email to mike@infonexus.com.
12
+
13
+ - BSD/OS
14
+ 4.x
15
+
16
+ - Cygwin
17
+ - requires winpcap (http://netgroup-serv.polito.it/winpcap) and pcap
18
+ header files copied to /usr/include/pcap/ and the library files to
19
+ be copied to /usr/lib/
20
+
21
+ - FreeBSD
22
+ version?
23
+
24
+ - HPUX
25
+ 11.0
26
+
27
+ - Linux
28
+ 2.0.x
29
+ 2.2.x
30
+ 2.4.x
31
+
32
+ - OpenBSD
33
+ 2.x
34
+ 3.x
35
+
36
+ - OS/X
37
+ version?
38
+
39
+ - Solaris
40
+ 2.x
41
+ 7
42
+ 8
43
+ 9
44
+
45
+ EOF
@@ -0,0 +1,41 @@
1
+ ===============================================================================
2
+ $Id: RAWSOCKET_NON_SEQUITUR,v 1.2 2004/01/03 20:31:00 mike Exp $
3
+ LIBNET 1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
4
+ http://www.packetfactory.net/libnet
5
+ ===============================================================================
6
+
7
+ Raw sockets are horribly non-standard across implementations. Here is
8
+ an incomplete list of some of the differences (corrections welcomed):
9
+
10
+ Linux 2.2+:
11
+
12
+ IP fragmentation: performed if packet is larger than MTU
13
+ IP checksum: always filled in
14
+ IP total length: always filled in
15
+ IP ID: filled in when zero
16
+ IP source address: filled in when zero
17
+ IP destination address: filled in when zero
18
+ Max packet size before kernel complains: 1500 bytes
19
+
20
+ Solaris 2.6+:
21
+
22
+ IP fragmentation bits: can't specify
23
+ IP fragmentation: performed if packet is larger than MTU
24
+ IP DF bit: always set
25
+ IP checksum: always filled in
26
+ Max packet size before kernel complains: ?
27
+
28
+ OpenBSD 2.8+:
29
+
30
+ IP fragmentation: performed if packet is larger than MTU
31
+ Max packet size before kernel complains: 8192 bytes
32
+
33
+ Solaris,
34
+ for example, has terrible support for this packet interface. Older OpenBSD
35
+ versions and recent FreeBSD versions have the BSD_BYTE_SWAP issue where
36
+ the ip_len and ip_frag fields need to be in little endian order. Linux
37
+ apparently doesn't allow for the injection of broadcast IP datagrams.
38
+ Whenever complete control over the IP header is desired, use the link
39
+ layer API.
40
+
41
+ EOF
data/libnet/doc/TODO ADDED
@@ -0,0 +1,96 @@
1
+ ===============================================================================
2
+ $Id: TODO,v 1.2 2004/01/03 20:31:00 mike Exp $
3
+ LIBNET 1.1 (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
4
+ http://www.packetfactory.net/libnet
5
+ ===============================================================================
6
+
7
+
8
+ 1.1.x TODO LIST
9
+
10
+ * Update the man page!
11
+
12
+ - Add a programmer's man page detailing the pblock architecture.
13
+
14
+ - Fix plist memory leak.
15
+
16
+ - Fix IPv6. According to RFC 2992:
17
+ "Another difference from IPv4 raw sockets is that complete packets
18
+ (that is, IPv6 packets with extension headers) cannot be read or
19
+ written using the IPv6 raw sockets API. Instead, ancillary data
20
+ objects are used to transfer the extension headers, as described
21
+ later in this document. Should an application need access to the
22
+ complete IPv6 packet, some other technique, such as the datalink
23
+ interfaces BPF or DLPI, must be used.
24
+
25
+ All fields in the IPv6 header that an application might want to
26
+ change (i.e., everything other than the version number) can be
27
+ modified using ancillary data and/or socket options by the
28
+ application for output. All fields in a received IPv6 header (other
29
+ than the version number and Next Header fields) and all extension
30
+ headers are also made available to the application as ancillary data
31
+ on input. Hence there is no need for a socket option similar to the
32
+ IPv4 IP_HDRINCL socket option."
33
+
34
+ - Add self-throttling logic to libnet_write()/libnet_init()? Advanced
35
+ mode thing?
36
+
37
+ - Prune the include list in libnet.h.in. Also add conditionals
38
+ around the headers we use for building the library, but not when
39
+ using it.
40
+
41
+ - Data marshalling API for unaligned structures (like STP).
42
+
43
+ - Make cisco ISL work. The issue is that we have build our Ethernet
44
+ frame first, then encapsulate it inside of an ISL envelope.
45
+ - We have to compute CRCs for both Ethernet and ISL.
46
+
47
+ - Tune advanced interface functionality that allow the application
48
+ programmer to get inside libnet_t.
49
+
50
+ - Test HPUX 11 port.
51
+
52
+ - Test cywin32 port.
53
+
54
+ - Flesh out the advanced mode.
55
+
56
+ - Consider making a flag for "strict mode" where libnet will check
57
+ things like when you build an IP options list there is an IP
58
+ header preceding it (likewise for TCP)... Other "smart" things
59
+ could happen in this mode too. When in non-strict mode, libnet
60
+ will be less rigid but prone to user-error mode.
61
+
62
+ - If we have a problem building a header we might end up freeing it
63
+ creating a NULL entry on the list and preventing us from getting to
64
+ entries beyond it (to free or whatever). Maybe we should mark it
65
+ bad or something and rely on the cleanup at the end to free it up?
66
+
67
+ - Fix checksum support for CDP
68
+
69
+ - Verify Checksuming:
70
+ Currently verified working on OpenBSD/Linux/Solaris:
71
+ - raw IP/UDP [with and without data]
72
+ - raw IP/TCP [with and without data]
73
+ - raw IP/ICMP [with and without data]
74
+ - raw IP/OSPF
75
+ - hello packet [with no auth data]
76
+ - hello packet [with no auth data and LSA sub-header (LSA check = bad)]
77
+ - link IP/UDP [with and without data]
78
+ - link IP/TCP [with and without data]
79
+
80
+ - Update the rest of the libnet_link_* files for the new format, already
81
+ ported:
82
+ - bpf [works]
83
+ - linux packet socket [works]
84
+ - linux sock packet [works]
85
+ - dlpi [works]
86
+
87
+ - Port link stuff to use writev() in libnet_write() (sendto can't hang).
88
+
89
+ - Get IPsec code working.
90
+
91
+ - Add the following packet builders:
92
+ - SNMP
93
+
94
+ - Update __libnet_handle_dump to dump everything in l verbosely.
95
+
96
+ EOF