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,892 @@
1
+ /*
2
+ * $Id: libnet_build_ip.c,v 1.18 2004/03/16 18:40:59 mike Exp $
3
+ *
4
+ * libnet
5
+ * libnet_build_ip.c - IP packet assembler
6
+ *
7
+ * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
8
+ * All rights reserved.
9
+ *
10
+ * Redistribution and use in source and binary forms, with or without
11
+ * modification, are permitted provided that the following conditions
12
+ * are met:
13
+ * 1. Redistributions of source code must retain the above copyright
14
+ * notice, this list of conditions and the following disclaimer.
15
+ * 2. Redistributions in binary form must reproduce the above copyright
16
+ * notice, this list of conditions and the following disclaimer in the
17
+ * documentation and/or other materials provided with the distribution.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
+ * SUCH DAMAGE.
30
+ *
31
+ */
32
+
33
+ #if (HAVE_CONFIG_H)
34
+ #include "../include/config.h"
35
+ #endif
36
+ #if (!(_WIN32) || (__CYGWIN__))
37
+ #include "../include/libnet.h"
38
+ #else
39
+ #include "../include/win32/libnet.h"
40
+ #endif
41
+
42
+
43
+ libnet_ptag_t
44
+ libnet_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag,
45
+ u_int8_t ttl, u_int8_t prot, u_int16_t sum, u_int32_t src, u_int32_t dst,
46
+ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
47
+ {
48
+ int offset;
49
+ u_int32_t h, n, i, j;
50
+ libnet_pblock_t *p, *p_data, *p_temp;
51
+ struct libnet_ipv4_hdr ip_hdr;
52
+ libnet_ptag_t ptag_data, ptag_hold;
53
+
54
+ if (l == NULL)
55
+ {
56
+ return (-1);
57
+ }
58
+
59
+ n = LIBNET_IPV4_H; /* size of memory block */
60
+ h = len; /* header length */
61
+ ptag_data = 0; /* used if options are present */
62
+
63
+ if (h + payload_s > IP_MAXPACKET)
64
+ {
65
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
66
+ "%s(): IP packet too large\n", __func__);
67
+ return (-1);
68
+ }
69
+
70
+ /*
71
+ * Find the existing protocol block if a ptag is specified, or create
72
+ * a new one.
73
+ */
74
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV4_H);
75
+ if (p == NULL)
76
+ {
77
+ return (-1);
78
+ }
79
+
80
+ memset(&ip_hdr, 0, sizeof(ip_hdr));
81
+ ip_hdr.ip_v = 4; /* version 4 */
82
+ ip_hdr.ip_hl = 5; /* 20 byte header */
83
+
84
+ /* check to see if there are IP options to include */
85
+ if (p->prev)
86
+ {
87
+ if (p->prev->type == LIBNET_PBLOCK_IPO_H)
88
+ {
89
+ /*
90
+ * Count up number of 32-bit words in options list, padding if
91
+ * neccessary.
92
+ */
93
+ for (i = 0, j = 0; i < p->prev->b_len; i++)
94
+ {
95
+ (i % 4) ? j : j++;
96
+ }
97
+ ip_hdr.ip_hl += j;
98
+ }
99
+ }
100
+
101
+ ip_hdr.ip_tos = tos; /* IP tos */
102
+ ip_hdr.ip_len = htons(h); /* total length */
103
+ ip_hdr.ip_id = htons(id); /* IP ID */
104
+ ip_hdr.ip_off = htons(frag); /* fragmentation flags */
105
+ ip_hdr.ip_ttl = ttl; /* time to live */
106
+ ip_hdr.ip_p = prot; /* transport protocol */
107
+ ip_hdr.ip_sum = (sum ? htons(sum) : 0); /* checksum */
108
+ ip_hdr.ip_src.s_addr = src; /* source ip */
109
+ ip_hdr.ip_dst.s_addr = dst; /* destination ip */
110
+
111
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV4_H);
112
+ if (n == -1)
113
+ {
114
+ goto bad;
115
+ }
116
+
117
+ /* save the original ptag value */
118
+ ptag_hold = ptag;
119
+
120
+ if (ptag == LIBNET_PTAG_INITIALIZER)
121
+ {
122
+ ptag = libnet_pblock_update(l, p, LIBNET_IPV4_H, LIBNET_PBLOCK_IPV4_H);
123
+ }
124
+
125
+ /* find and set the appropriate ptag, or else use the default of 0 */
126
+ offset = payload_s;
127
+ if (ptag_hold && p->prev)
128
+ {
129
+ p_temp = p->prev;
130
+ while (p_temp->prev &&
131
+ (p_temp->type != LIBNET_PBLOCK_IPDATA) &&
132
+ (p_temp->type != LIBNET_PBLOCK_IPV4_H))
133
+ {
134
+ p_temp = p_temp->prev;
135
+ }
136
+
137
+ if (p_temp->type == LIBNET_PBLOCK_IPDATA)
138
+ {
139
+ ptag_data = p_temp->ptag;
140
+ offset -= p_temp->b_len;
141
+ p->h_len += offset;
142
+ }
143
+ else
144
+ {
145
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
146
+ "%s(): IPv4 data pblock not found\n", __func__);
147
+ }
148
+ }
149
+
150
+ if ((payload && !payload_s) || (!payload && payload_s))
151
+ {
152
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
153
+ "%s(): payload inconsistency\n", __func__);
154
+ goto bad;
155
+ }
156
+
157
+ if (payload && payload_s)
158
+ {
159
+ /* update ptag_data with the new payload */
160
+ p_data = libnet_pblock_probe(l, ptag_data, payload_s,
161
+ LIBNET_PBLOCK_IPDATA);
162
+ if (p_data == NULL)
163
+ {
164
+ return (-1);
165
+ }
166
+
167
+ if (libnet_pblock_append(l, p_data, payload, payload_s) == -1)
168
+ {
169
+ goto bad;
170
+ }
171
+
172
+ if (ptag_data == LIBNET_PTAG_INITIALIZER)
173
+ {
174
+ if (p_data->prev->type == LIBNET_PBLOCK_IPV4_H)
175
+ {
176
+ libnet_pblock_update(l, p_data, payload_s,
177
+ LIBNET_PBLOCK_IPDATA);
178
+ /* swap pblocks to correct the protocol order */
179
+ libnet_pblock_swap(l, p->ptag, p_data->ptag);
180
+ }
181
+ else
182
+ {
183
+ /* update without setting this as the final pblock */
184
+ p_data->type = LIBNET_PBLOCK_IPDATA;
185
+ p_data->ptag = ++(l->ptag_state);
186
+ p_data->h_len = payload_s;
187
+
188
+ /* Adjust h_len for checksum. */
189
+ p->h_len += payload_s;
190
+
191
+ /* data was added after the initial construction */
192
+ for (p_temp = l->protocol_blocks;
193
+ p_temp->type == LIBNET_PBLOCK_IPV4_H ||
194
+ p_temp->type == LIBNET_PBLOCK_IPO_H;
195
+ p_temp = p_temp->next)
196
+ {
197
+ libnet_pblock_insert_before(l, p_temp->ptag, p_data->ptag);
198
+ break;
199
+ }
200
+
201
+ /* the end block needs to have its next pointer cleared */
202
+ l->pblock_end->next = NULL;
203
+ }
204
+
205
+ if (p_data->prev && p_data->prev->type == LIBNET_PBLOCK_IPO_H)
206
+ {
207
+ libnet_pblock_swap(l, p_data->prev->ptag, p_data->ptag);
208
+ }
209
+ }
210
+ }
211
+ else
212
+ {
213
+ p_data = libnet_pblock_find(l, ptag_data);
214
+ if (p_data)
215
+ {
216
+ libnet_pblock_delete(l, p_data);
217
+ }
218
+ else
219
+ {
220
+ /*
221
+ * XXX - When this completes successfully, libnet errbuf contains
222
+ * an error message so to come correct, we'll clear it.
223
+ */
224
+ memset(l->err_buf, 0, sizeof (l->err_buf));
225
+ }
226
+ }
227
+ if (sum == 0)
228
+ {
229
+ /*
230
+ * If checksum is zero, by default libnet will compute a checksum
231
+ * for the user. The programmer can override this by calling
232
+ * libnet_toggle_checksum(l, ptag, 1);
233
+ */
234
+ libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
235
+ }
236
+
237
+ /*
238
+ * FREDRAYNAL: as we insert a new IP header, all checksums for headers
239
+ * placed after this one will refer to here.
240
+ */
241
+ libnet_pblock_record_ip_offset(l, l->total_size);
242
+
243
+ return (ptag);
244
+ bad:
245
+ libnet_pblock_delete(l, p);
246
+ return (-1);
247
+ }
248
+
249
+ libnet_ptag_t
250
+ libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_int32_t dst, libnet_t *l)
251
+ {
252
+ u_int32_t n, i, j, src;
253
+ u_int16_t h;
254
+ libnet_pblock_t *p;
255
+ libnet_ptag_t ptag;
256
+ struct libnet_ipv4_hdr ip_hdr;
257
+
258
+ if (l == NULL)
259
+ {
260
+ return (-1);
261
+ }
262
+
263
+ n = LIBNET_IPV4_H; /* size of memory block */
264
+ h = len; /* header length */
265
+ ptag = LIBNET_PTAG_INITIALIZER;
266
+ src = libnet_get_ipaddr4(l);
267
+ if (src == -1)
268
+ {
269
+ /* err msg set in libnet_get_ipaddr() */
270
+ return (-1);
271
+ }
272
+
273
+ /*
274
+ * Create a new pblock.
275
+ */
276
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV4_H);
277
+ if (p == NULL)
278
+ {
279
+ return (-1);
280
+ }
281
+
282
+ memset(&ip_hdr, 0, sizeof(ip_hdr));
283
+ ip_hdr.ip_v = 4; /* version 4 */
284
+ ip_hdr.ip_hl = 5; /* 20 byte header */
285
+
286
+ /* check to see if there are IP options to include */
287
+ if (p->prev)
288
+ {
289
+ if (p->prev->type == LIBNET_PBLOCK_IPO_H)
290
+ {
291
+ /*
292
+ * Count up number of 32-bit words in options list, padding if
293
+ * neccessary.
294
+ */
295
+ for (i = 0, j = 0; i < p->prev->b_len; i++)
296
+ {
297
+ (i % 4) ? j : j++;
298
+ }
299
+ ip_hdr.ip_hl += j;
300
+ }
301
+ }
302
+
303
+ ip_hdr.ip_tos = 0; /* IP tos */
304
+ ip_hdr.ip_len = htons(h); /* total length */
305
+ ip_hdr.ip_id = htons((l->ptag_state) & 0x0000ffff); /* IP ID */
306
+ ip_hdr.ip_off = 0; /* fragmentation flags */
307
+ ip_hdr.ip_ttl = 64; /* time to live */
308
+ ip_hdr.ip_p = prot; /* transport protocol */
309
+ ip_hdr.ip_sum = 0; /* checksum */
310
+ ip_hdr.ip_src.s_addr = src; /* source ip */
311
+ ip_hdr.ip_dst.s_addr = dst; /* destination ip */
312
+
313
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV4_H);
314
+ if (n == -1)
315
+ {
316
+ goto bad;
317
+ }
318
+
319
+ libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
320
+ ptag = libnet_pblock_update(l, p, LIBNET_IPV4_H, LIBNET_PBLOCK_IPV4_H);
321
+
322
+ /*
323
+ * FREDRAYNAL: as we insert a new IP header, all checksums for headers
324
+ * placed after this one will refer to here.
325
+ */
326
+ libnet_pblock_record_ip_offset(l, l->total_size);
327
+ return (ptag);
328
+
329
+ bad:
330
+ libnet_pblock_delete(l, p);
331
+ return (-1);
332
+ }
333
+
334
+ libnet_ptag_t
335
+ libnet_build_ipv4_options(u_int8_t *options, u_int32_t options_s, libnet_t *l,
336
+ libnet_ptag_t ptag)
337
+ {
338
+ int offset, underflow;
339
+ u_int32_t i, j, n, adj_size;
340
+ libnet_pblock_t *p, *p_temp;
341
+ struct libnet_ipv4_hdr *ip_hdr;
342
+
343
+ if (l == NULL)
344
+ {
345
+ return (-1);
346
+ }
347
+
348
+ underflow = 0;
349
+ offset = 0;
350
+
351
+ /* check options list size */
352
+ if (options_s > LIBNET_MAXOPTION_SIZE)
353
+ {
354
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
355
+ "%s(): options list is too large %d\n", __func__, options_s);
356
+ return (-1);
357
+ }
358
+
359
+ adj_size = options_s;
360
+ if (adj_size % 4)
361
+ {
362
+ /* size of memory block with padding */
363
+ adj_size += 4 - (options_s % 4);
364
+ }
365
+
366
+ /* if this pblock already exists, determine if there is a size diff */
367
+ if (ptag)
368
+ {
369
+ p_temp = libnet_pblock_find(l, ptag);
370
+ if (p_temp)
371
+ {
372
+ if (adj_size >= p_temp->b_len)
373
+ {
374
+ offset = adj_size - p_temp->b_len;
375
+ }
376
+ else
377
+ {
378
+ offset = p_temp->b_len - adj_size;
379
+ underflow = 1;
380
+ }
381
+ }
382
+ else
383
+ {
384
+ /*
385
+ * XXX - When this completes successfully, libnet errbuf contains
386
+ * an error message so to come correct, we'll clear it.
387
+ */
388
+ memset(l->err_buf, 0, sizeof (l->err_buf));
389
+ }
390
+ }
391
+
392
+ /*
393
+ * Find the existing protocol block if a ptag is specified, or create
394
+ * a new one.
395
+ */
396
+ p = libnet_pblock_probe(l, ptag, adj_size, LIBNET_PBLOCK_IPO_H);
397
+ if (p == NULL)
398
+ {
399
+ return (-1);
400
+ }
401
+
402
+ /* append options */
403
+ n = libnet_pblock_append(l, p, options, options_s);
404
+ if (n == -1)
405
+ {
406
+ goto bad;
407
+ }
408
+
409
+ /* append padding */
410
+ n = libnet_pblock_append(l, p, "\0\0\0", adj_size - options_s);
411
+ if (n == -1)
412
+ {
413
+ goto bad;
414
+ }
415
+
416
+ if (ptag && p->next)
417
+ {
418
+ p_temp = p->next;
419
+ while ((p_temp->next) && (p_temp->type != LIBNET_PBLOCK_IPV4_H))
420
+ {
421
+ p_temp = p_temp->next;
422
+ }
423
+
424
+ /* fix the IP header size */
425
+ if (p_temp->type == LIBNET_PBLOCK_IPV4_H)
426
+ {
427
+ /*
428
+ * Count up number of 32-bit words in options list, padding if
429
+ * neccessary.
430
+ */
431
+ for (i = 0, j = 0; i < p->b_len; i++)
432
+ {
433
+ (i % 4) ? j : j++;
434
+ }
435
+ ip_hdr = (struct libnet_ipv4_hdr *) p_temp->buf;
436
+ ip_hdr->ip_hl = j + 5;
437
+
438
+ if (!underflow)
439
+ {
440
+ p_temp->h_len += offset;
441
+ }
442
+ else
443
+ {
444
+ p_temp->h_len -= offset;
445
+ }
446
+ }
447
+ }
448
+
449
+ return (ptag ? ptag : libnet_pblock_update(l, p, adj_size,
450
+ LIBNET_PBLOCK_IPO_H));
451
+ bad:
452
+ libnet_pblock_delete(l, p);
453
+ return (-1);
454
+ }
455
+
456
+ libnet_ptag_t
457
+ libnet_build_ipv6(u_int8_t tc, u_int32_t fl, u_int16_t len, u_int8_t nh,
458
+ u_int8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst,
459
+ u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
460
+ {
461
+ u_int32_t n;
462
+ libnet_pblock_t *p;
463
+ struct libnet_ipv6_hdr ip_hdr;
464
+
465
+ if (l == NULL)
466
+ {
467
+ return (-1);
468
+ }
469
+
470
+ n = LIBNET_IPV6_H + payload_s; /* size of memory block */
471
+
472
+ if (LIBNET_IPV6_H + payload_s > IP_MAXPACKET)
473
+ {
474
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
475
+ "%s(): IP packet too large\n", __func__);
476
+ return (-1);
477
+ }
478
+
479
+ /*
480
+ * Find the existing protocol block if a ptag is specified, or create
481
+ * a new one.
482
+ */
483
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_H);
484
+ if (p == NULL)
485
+ {
486
+ return (-1);
487
+ }
488
+
489
+ memset(&ip_hdr, 0, sizeof(ip_hdr));
490
+ /* corey: pack 4 most significant bits of tc */
491
+ ip_hdr.ip_flags[0] = (0x06 << 4) | ((tc & 0xF0) >> 4);
492
+ /* corey: fix packing of fl field */
493
+ ip_hdr.ip_flags[1] = ((tc & 0x0F) << 4) | ((fl & 0x000F0000) >> 16);
494
+ ip_hdr.ip_flags[2] = (fl & 0x0000FF00) >> 8;
495
+ ip_hdr.ip_flags[3] = (fl & 0x000000FF);
496
+ ip_hdr.ip_len = htons(len);
497
+ ip_hdr.ip_nh = nh;
498
+ ip_hdr.ip_hl = hl;
499
+ ip_hdr.ip_src = src;
500
+ ip_hdr.ip_dst = dst;
501
+
502
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ip_hdr, LIBNET_IPV6_H);
503
+ if (n == -1)
504
+ {
505
+ goto bad;
506
+ }
507
+
508
+ if ((payload && !payload_s) || (!payload && payload_s))
509
+ {
510
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
511
+ "%s(): payload inconsistency\n", __func__);
512
+ goto bad;
513
+ }
514
+
515
+ if (payload && payload_s)
516
+ {
517
+ n = libnet_pblock_append(l, p, payload, payload_s);
518
+ if (n == -1)
519
+ {
520
+ goto bad;
521
+ }
522
+ }
523
+
524
+ /* corey: allow for checksums in upper layer protocols */
525
+ if (!ptag) {
526
+ ptag = libnet_pblock_update(l, p, LIBNET_IPV6_H,
527
+ LIBNET_PBLOCK_IPV6_H);
528
+
529
+ libnet_pblock_record_ip_offset(l, l->total_size);
530
+ }
531
+
532
+ /*
533
+ return (ptag ? ptag : libnet_pblock_update(l, p, LIBNET_IPV6_H,
534
+ LIBNET_PBLOCK_IPV6_H));
535
+ */
536
+ return ptag;
537
+ bad:
538
+ libnet_pblock_delete(l, p);
539
+ return (-1);
540
+ }
541
+
542
+ libnet_ptag_t
543
+ libnet_build_ipv6_frag(u_int8_t nh, u_int8_t reserved, u_int16_t frag,
544
+ u_int32_t id, u_int8_t *payload, u_int32_t payload_s, libnet_t *l,
545
+ libnet_ptag_t ptag)
546
+ {
547
+ u_int32_t n;
548
+ u_int16_t h;
549
+ libnet_pblock_t *p;
550
+ struct libnet_ipv6_frag_hdr ipv6_frag_hdr;
551
+
552
+ if (l == NULL)
553
+ {
554
+ return (-1);
555
+ }
556
+
557
+ n = LIBNET_IPV6_FRAG_H + payload_s;
558
+ h = 0;
559
+
560
+ if (LIBNET_IPV6_FRAG_H + payload_s > IP_MAXPACKET)
561
+ {
562
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
563
+ "%s(): IP packet too large\n", __func__);
564
+ return (-1);
565
+ }
566
+
567
+ /*
568
+ * Find the existing protocol block if a ptag is specified, or create
569
+ * a new one.
570
+ */
571
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_FRAG_H);
572
+ if (p == NULL)
573
+ {
574
+ return (-1);
575
+ }
576
+
577
+ memset(&ipv6_frag_hdr, 0 , sizeof(ipv6_frag_hdr));
578
+ ipv6_frag_hdr.ip_nh = nh;
579
+ ipv6_frag_hdr.ip_reserved = reserved;
580
+ ipv6_frag_hdr.ip_frag = frag;
581
+ ipv6_frag_hdr.ip_id = id;
582
+
583
+ /*
584
+ * Appened the protocol unit to the list.
585
+ */
586
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_frag_hdr,
587
+ LIBNET_IPV6_FRAG_H);
588
+ if (n == -1)
589
+ {
590
+ goto bad;
591
+ }
592
+
593
+ /*
594
+ * Sanity check the payload arguments.
595
+ */
596
+ if ((payload && !payload_s) || (!payload && payload_s))
597
+ {
598
+ sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
599
+ goto bad;
600
+ }
601
+
602
+ /*
603
+ * Append the payload to the list if it exists.
604
+ */
605
+ if (payload && payload_s)
606
+ {
607
+ n = libnet_pblock_append(l, p, payload, payload_s);
608
+ if (n == -1)
609
+ {
610
+ goto bad;
611
+ }
612
+ }
613
+
614
+ /*
615
+ * Update the protocol block's meta information and return the protocol
616
+ * tag id of this pblock. This tag will be used to locate the pblock
617
+ * in order to modify the protocol header in subsequent calls.
618
+ */
619
+ return (ptag ? ptag : libnet_pblock_update(l, p, h,
620
+ LIBNET_PBLOCK_IPV6_FRAG_H));
621
+ bad:
622
+ libnet_pblock_delete(l, p);
623
+ return (-1);
624
+ }
625
+
626
+ libnet_ptag_t
627
+ libnet_build_ipv6_routing(u_int8_t nh, u_int8_t len, u_int8_t rtype,
628
+ u_int8_t segments, u_int8_t *payload, u_int32_t payload_s, libnet_t *l,
629
+ libnet_ptag_t ptag)
630
+ {
631
+ u_int32_t n;
632
+ u_int16_t h;
633
+ libnet_pblock_t *p;
634
+ struct libnet_ipv6_routing_hdr ipv6_routing_hdr;
635
+
636
+ if (l == NULL)
637
+ {
638
+ return (-1);
639
+ }
640
+
641
+ /* Important: IPv6 routing header routes are specified using the payload
642
+ * interface!
643
+ */
644
+ n = LIBNET_IPV6_ROUTING_H + payload_s;
645
+ h = 0;
646
+
647
+ if (LIBNET_IPV6_ROUTING_H + payload_s > IP_MAXPACKET)
648
+ {
649
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
650
+ "%s(): IP packet too large\n", __func__);
651
+ return (-1);
652
+ }
653
+
654
+ /*
655
+ * Find the existing protocol block if a ptag is specified, or create
656
+ * a new one.
657
+ */
658
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_ROUTING_H);
659
+ if (p == NULL)
660
+ {
661
+ return (-1);
662
+ }
663
+
664
+ memset(&ipv6_routing_hdr, 0 , sizeof(ipv6_routing_hdr));
665
+ ipv6_routing_hdr.ip_nh = nh;
666
+ ipv6_routing_hdr.ip_len = len;
667
+ ipv6_routing_hdr.ip_rtype = rtype;
668
+ ipv6_routing_hdr.ip_segments = segments;
669
+
670
+ /*
671
+ * Appened the protocol unit to the list.
672
+ */
673
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_routing_hdr,
674
+ LIBNET_IPV6_ROUTING_H);
675
+ if (n == -1)
676
+ {
677
+ goto bad;
678
+ }
679
+
680
+ /*
681
+ * Sanity check the payload arguments.
682
+ */
683
+ if ((payload && !payload_s) || (!payload && payload_s))
684
+ {
685
+ sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
686
+ goto bad;
687
+ }
688
+
689
+ /*
690
+ * Append the payload to the list if it exists.
691
+ */
692
+ if (payload && payload_s)
693
+ {
694
+ n = libnet_pblock_append(l, p, payload, payload_s);
695
+ if (n == -1)
696
+ {
697
+ goto bad;
698
+ }
699
+ }
700
+
701
+ /*
702
+ * Update the protocol block's meta information and return the protocol
703
+ * tag id of this pblock. This tag will be used to locate the pblock
704
+ * in order to modify the protocol header in subsequent calls.
705
+ */
706
+ return (ptag ? ptag : libnet_pblock_update(l, p, h,
707
+ LIBNET_PBLOCK_IPV6_ROUTING_H));
708
+ bad:
709
+ libnet_pblock_delete(l, p);
710
+ return (-1);
711
+ }
712
+
713
+ libnet_ptag_t
714
+ libnet_build_ipv6_destopts(u_int8_t nh, u_int8_t len, u_int8_t *payload,
715
+ u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
716
+ {
717
+ u_int32_t n;
718
+ u_int16_t h;
719
+ libnet_pblock_t *p;
720
+ struct libnet_ipv6_destopts_hdr ipv6_destopts_hdr;
721
+
722
+ if (l == NULL)
723
+ {
724
+ return (-1);
725
+ }
726
+
727
+ /* Important: IPv6 dest opts information is specified using the payload
728
+ * interface!
729
+ */
730
+ n = LIBNET_IPV6_DESTOPTS_H + payload_s;
731
+ h = 0;
732
+
733
+ if (LIBNET_IPV6_DESTOPTS_H + payload_s > IP_MAXPACKET)
734
+ {
735
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
736
+ "%s(): IP packet too large\n", __func__);
737
+ return (-1);
738
+ }
739
+
740
+ /*
741
+ * Find the existing protocol block if a ptag is specified, or create
742
+ * a new one.
743
+ */
744
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_DESTOPTS_H);
745
+ if (p == NULL)
746
+ {
747
+ return (-1);
748
+ }
749
+
750
+ memset(&ipv6_destopts_hdr, 0 , sizeof(ipv6_destopts_hdr));
751
+ ipv6_destopts_hdr.ip_nh = nh;
752
+ ipv6_destopts_hdr.ip_len = len;
753
+
754
+ /*
755
+ * Appened the protocol unit to the list.
756
+ */
757
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_destopts_hdr,
758
+ LIBNET_IPV6_DESTOPTS_H);
759
+ if (n == -1)
760
+ {
761
+ goto bad;
762
+ }
763
+
764
+ /*
765
+ * Sanity check the payload arguments.
766
+ */
767
+ if ((payload && !payload_s) || (!payload && payload_s))
768
+ {
769
+ sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
770
+ goto bad;
771
+ }
772
+
773
+ /*
774
+ * Append the payload to the list if it exists.
775
+ */
776
+ if (payload && payload_s)
777
+ {
778
+ n = libnet_pblock_append(l, p, payload, payload_s);
779
+ if (n == -1)
780
+ {
781
+ goto bad;
782
+ }
783
+ }
784
+
785
+ /*
786
+ * Update the protocol block's meta information and return the protocol
787
+ * tag id of this pblock. This tag will be used to locate the pblock
788
+ * in order to modify the protocol header in subsequent calls.
789
+ */
790
+ return (ptag ? ptag : libnet_pblock_update(l, p, h,
791
+ LIBNET_PBLOCK_IPV6_DESTOPTS_H));
792
+ bad:
793
+ libnet_pblock_delete(l, p);
794
+ return (-1);
795
+ }
796
+
797
+ libnet_ptag_t
798
+ libnet_build_ipv6_hbhopts(u_int8_t nh, u_int8_t len, u_int8_t *payload,
799
+ u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
800
+ {
801
+ u_int32_t n;
802
+ u_int16_t h;
803
+ libnet_pblock_t *p;
804
+ struct libnet_ipv6_hbhopts_hdr ipv6_hbhopts_hdr;
805
+
806
+ if (l == NULL)
807
+ {
808
+ return (-1);
809
+ }
810
+
811
+ /* Important: IPv6 hop by hop opts information is specified using the
812
+ * payload interface!
813
+ */
814
+ n = LIBNET_IPV6_HBHOPTS_H + payload_s;
815
+ h = 0;
816
+
817
+ if (LIBNET_IPV6_HBHOPTS_H + payload_s > IP_MAXPACKET)
818
+ {
819
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
820
+ "%s(): IP packet too large\n", __func__);
821
+ return (-1);
822
+ }
823
+
824
+ /*
825
+ * Find the existing protocol block if a ptag is specified, or create
826
+ * a new one.
827
+ */
828
+ p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_IPV6_HBHOPTS_H);
829
+ if (p == NULL)
830
+ {
831
+ return (-1);
832
+ }
833
+
834
+ memset(&ipv6_hbhopts_hdr, 0 , sizeof(ipv6_hbhopts_hdr));
835
+ ipv6_hbhopts_hdr.ip_nh = nh;
836
+ ipv6_hbhopts_hdr.ip_len = len;
837
+
838
+ /*
839
+ * Appened the protocol unit to the list.
840
+ */
841
+ n = libnet_pblock_append(l, p, (u_int8_t *)&ipv6_hbhopts_hdr,
842
+ LIBNET_IPV6_HBHOPTS_H);
843
+ if (n == -1)
844
+ {
845
+ goto bad;
846
+ }
847
+
848
+ /*
849
+ * Sanity check the payload arguments.
850
+ */
851
+ if ((payload && !payload_s) || (!payload && payload_s))
852
+ {
853
+ sprintf(l->err_buf, "%s(): payload inconsistency\n", __func__);
854
+ goto bad;
855
+ }
856
+
857
+ /*
858
+ * Append the payload to the list if it exists.
859
+ */
860
+ if (payload && payload_s)
861
+ {
862
+ n = libnet_pblock_append(l, p, payload, payload_s);
863
+ if (n == -1)
864
+ {
865
+ goto bad;
866
+ }
867
+ }
868
+
869
+ /*
870
+ * Update the protocol block's meta information and return the protocol
871
+ * tag id of this pblock. This tag will be used to locate the pblock
872
+ * in order to modify the protocol header in subsequent calls.
873
+ */
874
+ return (ptag ? ptag : libnet_pblock_update(l, p, h,
875
+ LIBNET_PBLOCK_IPV6_HBHOPTS_H));
876
+ bad:
877
+ libnet_pblock_delete(l, p);
878
+ return (-1);
879
+ }
880
+
881
+ libnet_ptag_t
882
+ libnet_autobuild_ipv6(u_int16_t len, u_int8_t nh, struct libnet_in6_addr dst,
883
+ libnet_t *l)
884
+ {
885
+
886
+ /* NYI */
887
+ snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
888
+ "%s(): not yet implemented\n", __func__);
889
+ return (-1);
890
+ }
891
+
892
+ /* EOF */