Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | /* |
2 | * $Id: libnet-functions.h,v 1.19 2005/11/29 22:48:39 carlosc Exp $ | |
3 | * | |
4 | * libnet-functions.h - function prototypes | |
5 | * | |
6 | * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com> | |
7 | * All rights reserved. | |
8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in the | |
16 | * documentation and/or other materials provided with the distribution. | |
17 | * | |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
28 | * SUCH DAMAGE. | |
29 | * | |
30 | */ | |
31 | ||
32 | #ifndef __LIBNET_FUNCTIONS_H | |
33 | #define __LIBNET_FUNCTIONS_H | |
34 | /** | |
35 | * @file libnet-functions.h | |
36 | * @brief libnet exported function prototypes | |
37 | */ | |
38 | ||
39 | /** | |
40 | * libnet_pkt.c includes | |
41 | */ | |
42 | ||
43 | libnet_t * | |
44 | libnet_init_pkt(int injection_type, char *device, char *err_buf); | |
45 | ||
46 | int | |
47 | libnet_write_pkt(libnet_t *l, u_int8_t **packet, u_int32_t *len, u_int32_t align); | |
48 | ||
49 | void | |
50 | libnet_print_pkt(u_int8_t *pktbuf, u_int32_t pktlen); | |
51 | ||
52 | /** | |
53 | * Creates the libnet environment. It initializes the library and returns a | |
54 | * libnet context. If the injection_type is LIBNET_LINK or LIBNET_LINK_ADV, the | |
55 | * function initializes the injection primitives for the link-layer interface | |
56 | * enabling the application programmer to build packets starting at the | |
57 | * data-link layer (which also provides more granular control over the IP | |
58 | * layer). If libnet uses the link-layer and the device argument is non-NULL, | |
59 | * the function attempts to use the specified network device for packet | |
60 | * injection. This is either a canonical string that references the device | |
61 | * (such as "eth0" for a 100MB Ethernet card on Linux or "fxp0" for a 100MB | |
62 | * Ethernet card on OpenBSD) or the dots and decimals representation of the | |
63 | * device's IP address (192.168.0.1). If device is NULL, libnet attempts to | |
64 | * find a suitable device to use. If the injection_type is LIBNET_RAW4 or | |
65 | * LIBNET_RAW4_ADV, the function initializes the injection primitives for the | |
66 | * IPv4 raw socket interface. The final argument, err_buf, should be a buffer | |
67 | * of size LIBNET_ERRBUF_SIZE and holds an error message if the function fails. | |
68 | * This function requires root privileges to execute successfully. Upon | |
69 | * success, the function returns a valid libnet context for use in later | |
70 | * function calls; upon failure, the function returns NULL. | |
71 | * @param injection_type packet injection type (LIBNET_LINK, LIBNET_LINK_ADV, LIBNET_RAW4, LIBNET_RAW4_ADV, LIBNET_RAW6, LIBNET_RAW6_ADV) | |
72 | * @param device the interface to use (NULL and libnet will choose one) | |
73 | * @param err_buf will contain an error message on failure | |
74 | * @return libnet context ready for use or NULL on error. | |
75 | */ | |
76 | libnet_t * | |
77 | libnet_init(int injection_type, char *device, char *err_buf); | |
78 | ||
79 | /** | |
80 | * Shuts down the libnet session referenced by l. It closes the network | |
81 | * interface and frees all internal memory structures associated with l. | |
82 | * @param l pointer to a libnet context | |
83 | */ | |
84 | void | |
85 | libnet_destroy(libnet_t *l); | |
86 | ||
87 | /** | |
88 | * Clears the current packet referenced and frees all pblocks. Should be | |
89 | * called when the programmer want to send a completely new packet of | |
90 | * a different type using the same context. | |
91 | * @param l pointer to a libnet context | |
92 | */ | |
93 | void | |
94 | libnet_clear_packet(libnet_t *l); | |
95 | ||
96 | /** | |
97 | * Fills in a libnet_stats structure with packet injection statistics | |
98 | * (packets written, bytes written, packet sending errors). | |
99 | * @param l pointer to a libnet context | |
100 | * @param ls pointer to a libnet statistics structure | |
101 | */ | |
102 | void | |
103 | libnet_stats(libnet_t *l, struct libnet_stats *ls); | |
104 | ||
105 | /** | |
106 | * Returns the FILENO of the file descriptor used for packet injection. | |
107 | * @param l pointer to a libnet context | |
108 | * @return the file number of the file descriptor used for packet injection | |
109 | */ | |
110 | int | |
111 | libnet_getfd(libnet_t *l); | |
112 | ||
113 | /** | |
114 | * Returns the canonical name of the device used for packet injection. | |
115 | * @param l pointer to a libnet context | |
116 | * @return the canonical name of the device used for packet injection. Note | |
117 | * it can be NULL without being an error. | |
118 | */ | |
119 | int8_t * | |
120 | libnet_getdevice(libnet_t *l); | |
121 | ||
122 | /** | |
123 | * Returns the pblock buffer contents for the specified ptag; a | |
124 | * subsequent call to libnet_getpbuf_size() should be made to determine the | |
125 | * size of the buffer. | |
126 | * @param l pointer to a libnet context | |
127 | * @param ptag the ptag reference number | |
128 | * @return a pointer to the pblock buffer or NULL on error | |
129 | */ | |
130 | u_int8_t * | |
131 | libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag); | |
132 | ||
133 | /** | |
134 | * Returns the pblock buffer size for the specified ptag; a | |
135 | * previous call to libnet_getpbuf() should be made to pull the actual buffer | |
136 | * contents. | |
137 | * @param l pointer to a libnet context | |
138 | * @param ptag the ptag reference number | |
139 | * @return the size of the pblock buffer | |
140 | */ | |
141 | u_int32_t | |
142 | libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag); | |
143 | ||
144 | /** | |
145 | * Returns the last error set inside of the referenced libnet context. This | |
146 | * function should be called anytime a function fails or an error condition | |
147 | * is detected inside of libnet. | |
148 | * @param l pointer to a libnet context | |
149 | * @return an error string or NULL if no error has occured | |
150 | */ | |
151 | char * | |
152 | libnet_geterror(libnet_t *l); | |
153 | ||
154 | /** | |
155 | * Returns the sum of the size of all of the pblocks inside of l (this should | |
156 | * be the resuling packet size). | |
157 | * @param l pointer to a libnet context | |
158 | * @return the size of the packet in l | |
159 | */ | |
160 | u_int32_t | |
161 | libnet_getpacket_size(libnet_t *l); | |
162 | ||
163 | /** | |
164 | * Seeds the psuedo-random number generator. | |
165 | * @param l pointer to a libnet context | |
166 | * @return 1 on success, -1 on failure | |
167 | */ | |
168 | int | |
169 | libnet_seed_prand(libnet_t *l); | |
170 | ||
171 | /** | |
172 | * Generates an unsigned psuedo-random value within the range specified by | |
173 | * mod. | |
174 | * LIBNET_PR2 0 - 1 | |
175 | * LIBNET_PR8 0 - 255 | |
176 | * LIBNET_PR16 0 - 32767 | |
177 | * LIBNET_PRu16 0 - 65535 | |
178 | * LIBNET_PR32 0 - 2147483647 | |
179 | * LIBNET_PRu32 0 - 4294967295 | |
180 | * | |
181 | * @param mod one the of LIBNET_PR* constants | |
182 | * @return 1 on success, -1 on failure | |
183 | */ | |
184 | u_int32_t | |
185 | libnet_get_prand(int mod); | |
186 | ||
187 | /** | |
188 | * If a given protocol header is built with the checksum field set to "0", by | |
189 | * default libnet will calculate the header checksum prior to injection. If the | |
190 | * header is set to any other value, by default libnet will not calculate the | |
191 | * header checksum. To over-ride this behavior, use libnet_toggle_checksum(). | |
192 | * Switches auto-checksumming on or off for the specified ptag. If mode is set | |
193 | * to LIBNET_ON, libnet will mark the specificed ptag to calculate a checksum | |
194 | * for the ptag prior to injection. This assumes that the ptag refers to a | |
195 | * protocol that has a checksum field. If mode is set to LIBNET_OFF, libnet | |
196 | * will clear the checksum flag and no checksum will be computed prior to | |
197 | * injection. This assumes that the programmer will assign a value (zero or | |
198 | * otherwise) to the checksum field. Often times this is useful if a | |
199 | * precomputed checksum or some other predefined value is going to be used. | |
200 | * Note that when libnet is initialized with LIBNET_RAW4, the IPv4 header | |
201 | * checksum will always be computed by the kernel prior to injection, | |
202 | * regardless of what the programmer sets. | |
203 | * @param l pointer to a libnet context | |
204 | * @param ptag the ptag reference number | |
205 | * @param mode LIBNET_ON or LIBNET_OFF | |
206 | * @return 1 on success, -1 on failure | |
207 | */ | |
208 | int | |
209 | libnet_toggle_checksum(libnet_t *l, libnet_ptag_t ptag, int mode); | |
210 | ||
211 | /** | |
212 | * Takes a network byte ordered IPv4 address and returns a pointer to either a | |
213 | * canonical DNS name (if it has one) or a string of dotted decimals. This may | |
214 | * incur a DNS lookup if the hostname and mode is set to LIBNET_RESOLVE. If | |
215 | * mode is set to LIBNET_DONT_RESOLVE, no DNS lookup will be performed and | |
216 | * the function will return a pointer to a dotted decimal string. The function | |
217 | * cannot fail -- if no canonical name exists, it will fall back on returning | |
218 | * a dotted decimal string. This function is non-reentrant. | |
219 | * @param in network byte ordered IPv4 address | |
220 | * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE | |
221 | * @return a pointer to presentation format string | |
222 | */ | |
223 | char * | |
224 | libnet_addr2name4(u_int32_t in, u_int8_t use_name); | |
225 | ||
226 | /** | |
227 | * Takes a dotted decimal string or a canonical DNS name and returns a | |
228 | * network byte ordered IPv4 address. This may incur a DNS lookup if mode is | |
229 | * set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode | |
230 | * is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can | |
231 | * fail if DNS lookup fails or if mode is set to LIBNET_DONT_RESOLVE and | |
232 | * host_name refers to a canonical DNS name. | |
233 | * @param l pointer to a libnet context | |
234 | * @param host_name pointer to a string containing a presentation format host | |
235 | * name | |
236 | * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE | |
237 | * @return network byte ordered IPv4 address or -1 (2^32 - 1) on error | |
238 | */ | |
239 | u_int32_t | |
240 | libnet_name2addr4(libnet_t *l, char *host_name, u_int8_t use_name); | |
241 | ||
242 | extern const struct libnet_in6_addr in6addr_error; | |
243 | ||
244 | /** | |
245 | * Takes a dotted decimal string or a canonical DNS name and returns a | |
246 | * network byte ordered IPv6 address. This may incur a DNS lookup if mode is | |
247 | * set to LIBNET_RESOLVE and host_name refers to a canonical DNS name. If mode | |
248 | * is set to LIBNET_DONT_RESOLVE no DNS lookup will occur. The function can | |
249 | * fail if DNS lookup fails or if mode is set to LIBNET_DONT_RESOLVE and | |
250 | * host_name refers to a canonical DNS name. | |
251 | * @param l pointer to a libnet context | |
252 | * @param host_name pointer to a string containing a presentation format host | |
253 | * name | |
254 | * @param use_name LIBNET_RESOLVE or LIBNET_DONT_RESOLVE | |
255 | * @return network byte ordered IPv6 address structure | |
256 | */ | |
257 | struct libnet_in6_addr | |
258 | libnet_name2addr6(libnet_t *l, char *host_name, u_int8_t use_name); | |
259 | ||
260 | /** | |
261 | * Should document this baby right here. | |
262 | */ | |
263 | void | |
264 | libnet_addr2name6_r(struct libnet_in6_addr addr, u_int8_t use_name, | |
265 | char *host_name, int host_name_len); | |
266 | ||
267 | /** | |
268 | * Creates a new port list. Port list chains are useful for TCP and UDP-based | |
269 | * applications that need to send packets to a range of ports (contiguous or | |
270 | * otherwise). The port list chain, which token_list points to, should contain | |
271 | * a series of int8_tacters from the following list: "0123456789,-" of the | |
272 | * general format "x - y, z", where "xyz" are port numbers between 0 and | |
273 | * 65,535. plist points to the front of the port list chain list for use in | |
274 | * further libnet_plist_chain() functions. Upon success, the function returns | |
275 | * 1. Upon failure, the function returns -1 and libnet_geterror() can tell you | |
276 | * why. | |
277 | * @param l pointer to a libnet context | |
278 | * @param plist if successful, will refer to the portlist, if not, NULL | |
279 | * @param token_list string containing the port list primitive | |
280 | * @return 1 on success, -1 on failure | |
281 | */ | |
282 | int | |
283 | libnet_plist_chain_new(libnet_t *l, libnet_plist_t **plist, char *token_list); | |
284 | ||
285 | /** | |
286 | * Returns the next port list chain pair from the port list chain plist. bport | |
287 | * and eport contain the starting port number and ending port number, | |
288 | * respectively. Upon success, the function returns 1 and fills in the port | |
289 | * variables; however, if the list is empty, the function returns 0 and sets | |
290 | * both port variables to 0. Upon failure, the function returns -1. | |
291 | * @param plist previously created portlist | |
292 | * @param bport will contain the beginning port number or 0 | |
293 | * @param eport will contain the ending port number or 0 | |
294 | * @return 1 on success, 0 if empty, -1 on failure | |
295 | */ | |
296 | int | |
297 | libnet_plist_chain_next_pair(libnet_plist_t *plist, u_int16_t *bport, | |
298 | u_int16_t *eport); | |
299 | ||
300 | /** | |
301 | * Runs through the port list and prints the contents of the port list chain | |
302 | * list to stdout. | |
303 | * @param plist previously created portlist | |
304 | * @return 1 on success, -1 on failure | |
305 | */ | |
306 | int | |
307 | libnet_plist_chain_dump(libnet_plist_t *plist); | |
308 | ||
309 | /** | |
310 | * Runs through the port list and prints the contents of the port list chain | |
311 | * list to string. This function uses strdup and is not re-entrant. It also | |
312 | * has a memory leak and should not really be used. | |
313 | * @param plist previously created portlist | |
314 | * @return a printable string containing the port list contents on success | |
315 | * NULL on error | |
316 | */ | |
317 | char * | |
318 | libnet_plist_chain_dump_string(libnet_plist_t *plist); | |
319 | ||
320 | /** | |
321 | * Frees all memory associated with port list chain. | |
322 | * @param plist previously created portlist | |
323 | * @return 1 on success, -1 on failure | |
324 | */ | |
325 | int | |
326 | libnet_plist_chain_free(libnet_plist_t *plist); | |
327 | ||
328 | /** | |
329 | * @section PBF Packet Builder Functions | |
330 | * | |
331 | * The core of libnet is the platform-independent packet-building | |
332 | * functionality. These functions enable an application programmer to build | |
333 | * protocol headers (and data) in a simple and consistent manner without having | |
334 | * to worry (too much) about low-level network odds and ends. Each | |
335 | * libnet_build() function builds a piece of a packet (generally a protocol | |
336 | * header). While it is perfectly possible to build an entire, | |
337 | * ready-to-transmit packet with a single call to a libnet_build() function, | |
338 | * generally more than one builder-class function call is required to construct | |
339 | * a full packet. A complete wire-ready packet generally consists of more than | |
340 | * one piece. | |
341 | * Every function that builds a protocol header takes a series of arguments | |
342 | * roughly corresponding to the header values as they appear on the wire. This | |
343 | * process is intuitive but often makes for functions with huge prototypes and | |
344 | * large stack frames. | |
345 | * One important thing to note is that you must call these functions in order, | |
346 | * corresponding to how they should appear on the wire (from the highest | |
347 | * protocol layer on down). This building process is intuitive; it approximates | |
348 | * what happens in an operating system kernel. In other words, to build a | |
349 | * Network Time Protocol (NTP) packet by using the link-layer interface, the | |
350 | * application programmer would call the libnet_build() functions in the | |
351 | * following order: | |
352 | * 1. libnet_build_ntp() | |
353 | * 2. libnet_build_udp() | |
354 | * 3. libnet_build_ipv4() | |
355 | * 4. libnet_build_ethernet() | |
356 | * This ordering is essential for libnet 1.1.x to properly link together the | |
357 | * packet internally (previous libnet versions did not have the requirement). | |
358 | * | |
359 | * @subsection TPI The Payload Interface | |
360 | * | |
361 | * The payload interface specifies an optional way to include data directly | |
362 | * after the protocol header in question. You can use this function for a | |
363 | * variety of purposes, including the following: | |
364 | * - Including additional or arbitrary protocol header information that is not | |
365 | * available from a libnet interface | |
366 | * - Including a packet payload (data segment) | |
367 | * - Building another protocol header that is not available from a libnet | |
368 | * interface | |
369 | * To employ the interface, the application programmer should construct the i | |
370 | * payload data and pass a u_int8_t * to this data and its size to the desired | |
371 | * libnet_build() function. Libnet handles the rest. | |
372 | * | |
373 | * It is important to note that some functions (notably the IPv6 builders) do | |
374 | * use the payload interface to specify variable length but ostensibly | |
375 | * non-optional data. See the individual libnet_build_ipv6*() functions for | |
376 | * more information. | |
377 | * | |
378 | * @subsection PT Protocol Tags and Packet Builder Return Values | |
379 | * | |
380 | * Libnet uses the protocol tag (ptag) to identify individual pieces of a | |
381 | * packet after being created. A new ptag results every time a libnet_build() | |
382 | * function with an empty (0) ptag argument completes successfully. This new | |
383 | * ptag now refers to the packet piece just created. The application | |
384 | * programmer's responsibility is to save this value if he or she plans to | |
385 | * modify this particular portion later on in the program. If the application | |
386 | * programmer needs to modify some portion of that particular packet piece | |
387 | * again, he or she calls the same libnet_build() function specifying the | |
388 | * saved ptag argument. Libnet then searches for that packet piece and modifies | |
389 | * it rather than creating a new one. Upon failure for any reason, | |
390 | * libnet_build() functions return -1; libnet_geterror() tells you why. | |
391 | */ | |
392 | ||
393 | /** | |
394 | * Builds an IEEE 802.1q VLAN tagging header. Depending on the value of | |
395 | * len_proto, the function wraps the 802.1q header inside either an IEEE 802.3 | |
396 | * header or an RFC 894 Ethernet II (DIX) header (both resulting in an 18-byte | |
397 | * frame). If len is 1500 or less, most receiving protocol stacks parse the | |
398 | * frame as an IEEE 802.3 encapsulated frame. If len is one of the Ethernet type | |
399 | * values, most protocol stacks parse the frame as an RFC 894 Ethernet II | |
400 | * encapsulated frame. Note the length value is calculated without the 802.1q | |
401 | * header of 18 bytes. | |
402 | * @param dst pointer to a six byte source ethernet address | |
403 | * @param src pointer to a six byte destination ethernet address | |
404 | * @param tpi tag protocol identifier | |
405 | * @param priority priority | |
406 | * @param cfi canonical format indicator | |
407 | * @param vlan_id vlan identifier | |
408 | * @param len_proto length (802.3) protocol (Ethernet II) | |
409 | * @param payload optional payload or NULL | |
410 | * @param payload_s payload length or 0 | |
411 | * @param l pointer to a libnet context | |
412 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
413 | * @return protocol tag value on success, -1 on error | |
414 | */ | |
415 | libnet_ptag_t | |
416 | libnet_build_802_1q(u_int8_t *dst, u_int8_t *src, u_int16_t tpi, | |
417 | u_int8_t priority, u_int8_t cfi, u_int16_t vlan_id, u_int16_t len_proto, | |
418 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
419 | ||
420 | /** | |
421 | * Builds an IEEE 802.1x extended authentication protocol header. | |
422 | * @param eap_ver the EAP version | |
423 | * @param eap_type the EAP type | |
424 | * @param length frame length | |
425 | * @param payload optional payload or NULL | |
426 | * @param payload_s payload length or 0 | |
427 | * @param l pointer to a libnet context | |
428 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
429 | * @return protocol tag value on success, -1 on error | |
430 | */ | |
431 | libnet_ptag_t | |
432 | libnet_build_802_1x(u_int8_t eap_ver, u_int8_t eap_type, u_int16_t length, | |
433 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
434 | ||
435 | /** | |
436 | * Builds an IEEE 802.2 LLC header. | |
437 | * @param dsap destination service access point | |
438 | * @param ssap source service access point | |
439 | * @param control control field | |
440 | * @param payload optional payload or NULL | |
441 | * @param payload_s payload length or 0 | |
442 | * @param l pointer to a libnet context | |
443 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
444 | * @return protocol tag value on success, -1 on error | |
445 | */ | |
446 | libnet_ptag_t | |
447 | libnet_build_802_2(u_int8_t dsap, u_int8_t ssap, u_int8_t control, | |
448 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
449 | ||
450 | /** | |
451 | * Builds an IEEE 802.2 LLC SNAP header. | |
452 | * @param dsap destination service access point | |
453 | * @param ssap source service access point | |
454 | * @param control control field | |
455 | * @param oui Organizationally Unique Identifier | |
456 | * @param type upper layer protocol | |
457 | * @param payload optional payload or NULL | |
458 | * @param payload_s payload length or 0 | |
459 | * @param l pointer to a libnet context | |
460 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
461 | * @return protocol tag value on success, -1 on error | |
462 | */ | |
463 | libnet_ptag_t | |
464 | libnet_build_802_2snap(u_int8_t dsap, u_int8_t ssap, u_int8_t control, | |
465 | u_int8_t *oui, u_int16_t type, u_int8_t *payload, u_int32_t payload_s, | |
466 | libnet_t *l, libnet_ptag_t ptag); | |
467 | ||
468 | /** | |
469 | * Builds an IEEE 802.3 header. The 802.3 header is almost identical to the | |
470 | * RFC 894 Ethernet II header, the exception being that the field immediately | |
471 | * following the source address holds the frame's length (as opposed to the | |
472 | * layer 3 protocol). You should only use this function when libnet is | |
473 | * initialized with the LIBNET_LINK interface. | |
474 | * @param dst destination ethernet address | |
475 | * @param src source ethernet address | |
476 | * @param len frame length sans header | |
477 | * @param payload optional payload or NULL | |
478 | * @param payload_s payload length or 0 | |
479 | * @param l pointer to a libnet context | |
480 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
481 | * @return protocol tag value on success, -1 on error | |
482 | */ | |
483 | libnet_ptag_t | |
484 | libnet_build_802_3(u_int8_t *dst, u_int8_t *src, u_int16_t len, | |
485 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
486 | ||
487 | /** | |
488 | * Builds an Ethernet header. The RFC 894 Ethernet II header is almost | |
489 | * identical to the IEEE 802.3 header, with the exception that the field | |
490 | * immediately following the source address holds the layer 3 protocol (as | |
491 | * opposed to frame's length). You should only use this function when | |
492 | * libnet is initialized with the LIBNET_LINK interface. | |
493 | * @param dst destination ethernet address | |
494 | * @param src source ethernet address | |
495 | * @param type upper layer protocol type | |
496 | * @param payload optional payload or NULL | |
497 | * @param payload_s payload length or 0 | |
498 | * @param l pointer to a libnet context | |
499 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
500 | * @return protocol tag value on success, -1 on error | |
501 | */ | |
502 | libnet_ptag_t | |
503 | libnet_build_ethernet(u_int8_t *dst, u_int8_t *src, u_int16_t type, | |
504 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
505 | ||
506 | /** | |
507 | * Autobuilds an Ethernet header. The RFC 894 Ethernet II header is almost | |
508 | * identical to the IEEE 802.3 header, with the exception that the field | |
509 | * immediately following the source address holds the layer 3 protocol (as | |
510 | * opposed to frame's length). You should only use this function when | |
511 | * libnet is initialized with the LIBNET_LINK interface. | |
512 | * @param dst destination ethernet address | |
513 | * @param type upper layer protocol type | |
514 | * @param l pointer to a libnet context | |
515 | * @return protocol tag value on success, -1 on error | |
516 | */ | |
517 | libnet_ptag_t | |
518 | libnet_autobuild_ethernet(u_int8_t *dst, u_int16_t type, libnet_t *l); | |
519 | ||
520 | /** | |
521 | * Builds a Fiber Distributed Data Interface (FDDI) header. | |
522 | * @param fc class format and priority | |
523 | * @oaram dst destination fddi address | |
524 | * @oaram src source fddi address | |
525 | * @param dsap destination service access point | |
526 | * @param ssap source service access point | |
527 | * @param cf cf | |
528 | * @param oui 3 byte IEEE organizational code | |
529 | * @param type upper layer protocol | |
530 | * @param payload optional payload or NULL | |
531 | * @param payload_s payload length or 0 | |
532 | * @param l pointer to a libnet context | |
533 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
534 | * @return protocol tag value on success, -1 on error | |
535 | */ | |
536 | libnet_ptag_t | |
537 | libnet_build_fddi(u_int8_t fc, u_int8_t *dst, u_int8_t *src, u_int8_t dsap, | |
538 | u_int8_t ssap, u_int8_t cf, u_int8_t *oui, u_int16_t type, u_int8_t *payload, | |
539 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
540 | ||
541 | /** | |
542 | * Autobuilds a Fiber Distributed Data Interface (FDDI) header. | |
543 | * @param fc class format and priority | |
544 | * @oaram dst destination fddi address | |
545 | * @param dsap destination service access point | |
546 | * @param ssap source service access point | |
547 | * @param cf cf | |
548 | * @param oui IEEE organizational code | |
549 | * @param type upper layer protocol | |
550 | * @param l pointer to a libnet context | |
551 | * @return protocol tag value on success, -1 on error | |
552 | */ | |
553 | libnet_ptag_t | |
554 | libnet_autobuild_fddi(u_int8_t fc, u_int8_t *dst, u_int8_t dsap, u_int8_t ssap, | |
555 | u_int8_t cf, u_int8_t *oui, u_int16_t type, libnet_t *l); | |
556 | ||
557 | /** | |
558 | * Builds an Address Resolution Protocol (ARP) header. Depending on the op | |
559 | * value, the function builds one of several different types of RFC 826 or | |
560 | * RFC 903 RARP packets. | |
561 | * @param hrd hardware address format | |
562 | * @param pro protocol address format | |
563 | * @param hln hardware address length | |
564 | * @param pln protocol address length | |
565 | * @param op ARP operation type | |
566 | * @param sha sender's hardware address | |
567 | * @param spa sender's protocol address | |
568 | * @param tha target hardware address | |
569 | * @param tpa targer protocol address | |
570 | * @param payload optional payload or NULL | |
571 | * @param payload_s payload length or 0 | |
572 | * @param l pointer to a libnet context | |
573 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
574 | * @return protocol tag value on success, -1 on error | |
575 | */ | |
576 | libnet_ptag_t | |
577 | libnet_build_arp(u_int16_t hrd, u_int16_t pro, u_int8_t hln, u_int8_t pln, | |
578 | u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, u_int8_t *tpa, | |
579 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
580 | ||
581 | /** | |
582 | * Autouilds an Address Resolution Protocol (ARP) header. Depending on the op | |
583 | * value, the function builds one of several different types of RFC 826 or | |
584 | * RFC 903 RARP packets. | |
585 | * @param op ARP operation type | |
586 | * @param sha sender's hardware address | |
587 | * @param spa sender's protocol address | |
588 | * @param tha target hardware address | |
589 | * @param tpa targer protocol address | |
590 | * @param l pointer to a libnet context | |
591 | * @return protocol tag value on success, -1 on error | |
592 | */ | |
593 | libnet_ptag_t | |
594 | libnet_autobuild_arp(u_int16_t op, u_int8_t *sha, u_int8_t *spa, u_int8_t *tha, | |
595 | u_int8_t *tpa, libnet_t *l); | |
596 | ||
597 | /** | |
598 | * Builds an RFC 793 Transmission Control Protocol (TCP) header. | |
599 | * @param sp source port | |
600 | * @param dp destination port | |
601 | * @param seq sequence number | |
602 | * @param ack acknowledgement number | |
603 | * @param control control flags | |
604 | * @param win window size | |
605 | * @param sum checksum (0 for libnet to autofill) | |
606 | * @param urg urgent pointer | |
607 | * @parama len total length of the TCP packet (for checksum calculation) | |
608 | * @param payload_s payload length or 0 | |
609 | * @param l pointer to a libnet context | |
610 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
611 | * @return protocol tag value on success, -1 on error | |
612 | */ | |
613 | libnet_ptag_t | |
614 | libnet_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, | |
615 | u_int8_t control, u_int16_t win, u_int16_t sum, u_int16_t urg, u_int16_t len, | |
616 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
617 | ||
618 | /** | |
619 | * Builds an RFC 793 Transmission Control Protocol (TCP) options header. | |
620 | * The function expects options to be a valid TCP options string of size | |
621 | * options_s, which is no larger than 40 bytes (the maximum size of an | |
622 | * options string). The function checks to ensure that the packet consists of | |
623 | * a TCP header preceded by an IPv4 header, and that the addition of the | |
624 | * options string would not result in a packet larger than 65,535 bytes | |
625 | * (IPMAXPACKET). The function counts up the number of 32-bit words in the | |
626 | * options string and adjusts the TCP header length value as necessary. | |
627 | * @param options byte string of TCP options | |
628 | * @param options_s length of options string | |
629 | * @param l pointer to a libnet context | |
630 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
631 | * @return protocol tag value on success, -1 on error | |
632 | */ | |
633 | libnet_ptag_t | |
634 | libnet_build_tcp_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, | |
635 | libnet_ptag_t ptag); | |
636 | ||
637 | /** | |
638 | * Builds an RFC 768 User Datagram Protocol (UDP) header. | |
639 | * @param sp source port | |
640 | * @param dp destination port | |
641 | * @param len total length of the UDP packet | |
642 | * @param sum checksum (0 for libnet to autofill) | |
643 | * @param payload optional payload or NULL | |
644 | * @param payload_s payload length or 0 | |
645 | * @param l pointer to a libnet context | |
646 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
647 | * @return protocol tag value on success, -1 on error | |
648 | */ | |
649 | libnet_ptag_t | |
650 | libnet_build_udp(u_int16_t sp, u_int16_t dp, u_int16_t len, u_int16_t sum, | |
651 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
652 | ||
653 | /** | |
654 | * Builds a Cisco Discovery Protocol (CDP) header. Cisco Systems designed CDP | |
655 | * to aid in the network management of adjacent Cisco devices. The CDP protocol | |
656 | * specifies data by using a type/length/value (TLV) setup. The first TLV can | |
657 | * specified by using the functions type, length, and value arguments. To | |
658 | * specify additional TLVs, the programmer could either use the payload | |
659 | * interface or libnet_build_data() to construct them. | |
660 | * @param version CDP version | |
661 | * @param ttl time to live (time information should be cached by recipient) | |
662 | * @param sum checksum (0 for libnet to autofill) | |
663 | * @param type type of data contained in value | |
664 | * @param len length of value arugment | |
665 | * @param value the CDP information string | |
666 | * @param payload optional payload or NULL | |
667 | * @param payload_s payload length or 0 | |
668 | * @param l pointer to a libnet context | |
669 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
670 | * @return protocol tag value on success, -1 on error | |
671 | */ | |
672 | libnet_ptag_t | |
673 | libnet_build_cdp(u_int8_t version, u_int8_t ttl, u_int16_t sum, u_int16_t type, | |
674 | u_int16_t len, u_int8_t *value, u_int8_t *payload, u_int32_t payload_s, | |
675 | libnet_t *l, libnet_ptag_t ptag); | |
676 | ||
677 | /** | |
678 | * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) | |
679 | * echo request/reply header | |
680 | * @param type type of ICMP packet (should be ICMP_ECHOREPLY or ICMP_ECHO) | |
681 | * @param code code of ICMP packet (should be 0) | |
682 | * @param sum checksum (0 for libnet to autofill) | |
683 | * @param id identification number | |
684 | * @param seq packet sequence number | |
685 | * @param payload optional payload or NULL | |
686 | * @param payload_s payload length or 0 | |
687 | * @param l pointer to a libnet context | |
688 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
689 | * @return protocol tag value on success, -1 on error | |
690 | */ | |
691 | libnet_ptag_t | |
692 | libnet_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum, | |
693 | u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, | |
694 | libnet_t *l, libnet_ptag_t ptag); | |
695 | ||
696 | /** | |
697 | * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) | |
698 | * IP netmask request/reply header. | |
699 | * @param type type of ICMP packet (should be ICMP_MASKREQ or ICMP_MASKREPLY) | |
700 | * @param code code of ICMP packet (should be 0) | |
701 | * @param sum checksum (0 for libnet to autofill) | |
702 | * @param id identification number | |
703 | * @param seq packet sequence number | |
704 | * @param mask subnet mask | |
705 | * @param payload optional payload or NULL | |
706 | * @param payload_s payload length or 0 | |
707 | * @param l pointer to a libnet context | |
708 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
709 | * @return protocol tag value on success, -1 on error | |
710 | */ | |
711 | libnet_ptag_t | |
712 | libnet_build_icmpv4_mask(u_int8_t type, u_int8_t code, u_int16_t sum, | |
713 | u_int16_t id, u_int16_t seq, u_int32_t mask, u_int8_t *payload, | |
714 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
715 | ||
716 | /** | |
717 | * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) | |
718 | * unreachable header. The IP header that caused the error message should be | |
719 | * built by a previous call to libnet_build_ipv4(). | |
720 | * @param type type of ICMP packet (should be ICMP_UNREACH) | |
721 | * @param code code of ICMP packet (should be one of the 16 unreachable codes) | |
722 | * @param sum checksum (0 for libnet to autofill) | |
723 | * @param payload optional payload or NULL | |
724 | * @param payload_s payload length or 0 | |
725 | * @param l pointer to a libnet context | |
726 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
727 | * @return protocol tag value on success, -1 on error | |
728 | */ | |
729 | libnet_ptag_t | |
730 | libnet_build_icmpv4_unreach(u_int8_t type, u_int8_t code, u_int16_t sum, | |
731 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
732 | ||
733 | /** | |
734 | * Builds an IP version 4 RFC 792 Internet Message Control Protocol (ICMP) | |
735 | * redirect header. The IP header that caused the error message should be | |
736 | * built by a previous call to libnet_build_ipv4(). | |
737 | * @param type type of ICMP packet (should be ICMP_REDIRECT) | |
738 | * @param code code of ICMP packet (should be one of the four redirect codes) | |
739 | * @param sum checksum (0 for libnet to autofill) | |
740 | * @param payload optional payload or NULL | |
741 | * @param payload_s payload length or 0 | |
742 | * @param l pointer to a libnet context | |
743 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
744 | * @return protocol tag value on success, -1 on error | |
745 | */ | |
746 | libnet_ptag_t | |
747 | libnet_build_icmpv4_redirect(u_int8_t type, u_int8_t code, u_int16_t sum, | |
748 | u_int32_t gateway, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
749 | libnet_ptag_t ptag); | |
750 | ||
751 | /** | |
752 | * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) time | |
753 | * exceeded header. The IP header that caused the error message should be | |
754 | * built by a previous call to libnet_build_ipv4(). | |
755 | * @param type type of ICMP packet (should be ICMP_TIMXCEED) | |
756 | * @param code code of ICMP packet (ICMP_TIMXCEED_INTRANS / ICMP_TIMXCEED_REASS) | |
757 | * @param sum checksum (0 for libnet to autofill) | |
758 | * @param payload optional payload or NULL | |
759 | * @param payload optional payload or NULL | |
760 | * @param payload_s payload length or 0 | |
761 | * @param l pointer to a libnet context | |
762 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
763 | * @return protocol tag value on success, -1 on error | |
764 | */ | |
765 | libnet_ptag_t | |
766 | libnet_build_icmpv4_timeexceed(u_int8_t type, u_int8_t code, u_int16_t sum, | |
767 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
768 | ||
769 | /** | |
770 | * Builds an IP version 4 RFC 792 Internet Control Message Protocol (ICMP) | |
771 | * timestamp request/reply header. | |
772 | * @param type type of ICMP packet (should be ICMP_TSTAMP or ICMP_TSTAMPREPLY) | |
773 | * @param code code of ICMP packet (should be 0) | |
774 | * @param sum checksum (0 for libnet to autofill) | |
775 | * @param id identification number | |
776 | * @param seq sequence number | |
777 | * @param otime originate timestamp | |
778 | * @param rtime receive timestamp | |
779 | * @param ttime transmit timestamp | |
780 | * @param payload optional payload or NULL | |
781 | * @param payload_s payload length or 0 | |
782 | * @param l pointer to a libnet context | |
783 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
784 | * @return protocol tag value on success, -1 on error | |
785 | */ | |
786 | libnet_ptag_t | |
787 | libnet_build_icmpv4_timestamp(u_int8_t type, u_int8_t code, u_int16_t sum, | |
788 | u_int16_t id, u_int16_t seq, n_time otime, n_time rtime, n_time ttime, | |
789 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
790 | ||
791 | /** | |
792 | * Builds an RFC 1112 Internet Group Memebership Protocol (IGMP) header. | |
793 | * @param type packet type | |
794 | * @param code packet code (should be 0) | |
795 | * @param sum checksum (0 for libnet to autofill) | |
796 | * @param ip IPv4 address | |
797 | * @param payload optional payload or NULL | |
798 | * @param payload_s payload length or 0 | |
799 | * @param l pointer to a libnet context | |
800 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
801 | * @return protocol tag value on success, -1 on error | |
802 | */ | |
803 | libnet_ptag_t | |
804 | libnet_build_igmp(u_int8_t type, u_int8_t code, u_int16_t sum, u_int32_t ip, | |
805 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
806 | ||
807 | /** | |
808 | * Builds an RFC 2362 Protocol Independent Multicast (PIM) header. | |
809 | * @param vers packet protocol version | |
810 | * @param type packet type | |
811 | * @param sum checksum (0 for libnet to autofill) | |
812 | * @param payload optional payload or NULL | |
813 | * @param payload_s payload length or 0 | |
814 | * @param l pointer to a libnet context | |
815 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
816 | * @return protocol tag value on success, -1 on error | |
817 | */ | |
818 | libnet_ptag_t | |
819 | libnet_build_pim(u_int8_t vers, u_int8_t type, u_int16_t sum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
820 | ||
821 | /** | |
822 | * Builds a version 4 RFC 791 Internet Protocol (IP) header. | |
823 | * @param len total length of the IP packet including all subsequent data | |
824 | * @param tos type of service bits | |
825 | * @param id IP identification number | |
826 | * @param frag fragmentation bits and offset | |
827 | * @param ttl time to live in the network | |
828 | * @param prot upper layer protocol | |
829 | * @param sum checksum (0 for libnet to autofill) | |
830 | * @param src source IPv4 address (little endian) | |
831 | * @param dst destination IPv4 address (little endian) | |
832 | * @param payload optional payload or NULL | |
833 | * @param payload_s payload length or 0 | |
834 | * @param l pointer to a libnet context | |
835 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
836 | * @return protocol tag value on success, -1 on error | |
837 | */ | |
838 | libnet_ptag_t | |
839 | libnet_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag, | |
840 | u_int8_t ttl, u_int8_t prot, u_int16_t sum, u_int32_t src, u_int32_t dst, | |
841 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
842 | ||
843 | /** | |
844 | * Builds an version 4 Internet Protocol (IP) options header. The function | |
845 | * expects options to be a valid IP options string of size options_s, no larger | |
846 | * than 40 bytes (the maximum size of an options string). The function checks | |
847 | * to make sure that the preceding header is an IPv4 header and that the | |
848 | * options string would not result in a packet larger than 65,535 bytes | |
849 | * (IPMAXPACKET). The function counts up the number of 32-bit words in the | |
850 | * options string and adjusts the IP header length value as necessary. | |
851 | * @param options byte string of IP options | |
852 | * @param options_s length of options string | |
853 | * @param l pointer to a libnet context | |
854 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
855 | * @return protocol tag value on success, -1 on error | |
856 | */ | |
857 | libnet_ptag_t | |
858 | libnet_build_ipv4_options(u_int8_t *options, u_int32_t options_s, libnet_t *l, | |
859 | libnet_ptag_t ptag); | |
860 | ||
861 | /** | |
862 | * Autobuilds a version 4 Internet Protocol (IP) header. The function is useful * to build an IP header quickly when you do not need a granular level of | |
863 | * control. The function takes the same len, prot, and dst arguments as | |
864 | * libnet_build_ipv4(). The function does not accept a ptag argument, but it | |
865 | * does return a ptag. In other words, you can use it to build a new IP header | |
866 | * but not to modify an existing one. | |
867 | * @param len total length of the IP packet including all subsequent data | |
868 | * @param prot upper layer protocol | |
869 | * @param dst destination IPv4 address (little endian) | |
870 | * @param l pointer to a libnet context | |
871 | * @return protocol tag value on success, -1 on error | |
872 | */ | |
873 | libnet_ptag_t | |
874 | libnet_autobuild_ipv4(u_int16_t len, u_int8_t prot, u_int32_t dst, libnet_t *l); | |
875 | ||
876 | /** | |
877 | * Builds a version 6 RFC 2460 Internet Protocol (IP) header. | |
878 | * @param tc traffic class | |
879 | * @param fl flow label | |
880 | * @param len total length of the IP packet | |
881 | * @param nh next header | |
882 | * @param hl hop limit | |
883 | * @param src source IPv6 address | |
884 | * @param dst destination IPv6 address | |
885 | * @param payload optional payload or NULL | |
886 | * @param payload_s payload length or 0 | |
887 | * @param l pointer to a libnet context | |
888 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
889 | * @return protocol tag value on success, -1 on error | |
890 | */ | |
891 | libnet_ptag_t | |
892 | libnet_build_ipv6(u_int8_t tc, u_int32_t fl, u_int16_t len, u_int8_t nh, | |
893 | u_int8_t hl, struct libnet_in6_addr src, struct libnet_in6_addr dst, | |
894 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
895 | ||
896 | /** | |
897 | * Builds a version 6 RFC 2460 Internet Protocol (IP) fragmentation header. | |
898 | * @param nh next header | |
899 | * @param reserved unused value... OR IS IT! | |
900 | * @param frag fragmentation bits (ala ipv4) | |
901 | * @param id packet identification | |
902 | * @param payload optional payload or NULL | |
903 | * @param payload_s payload length or 0 | |
904 | * @param l pointer to a libnet context | |
905 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
906 | * @return protocol tag value on success, -1 on error | |
907 | */ | |
908 | libnet_ptag_t | |
909 | libnet_build_ipv6_frag(u_int8_t nh, u_int8_t reserved, u_int16_t frag, | |
910 | u_int32_t id, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
911 | libnet_ptag_t ptag); | |
912 | ||
913 | /** | |
914 | * Builds a version 6 RFC 2460 Internet Protocol (IP) routing header. This | |
915 | * function is special in that it uses the payload interface to include the | |
916 | * "type-specific data"; that is the routing information. Most often this will | |
917 | * be a number of 128-bit IPv6 addresses. The application programmer will build | |
918 | * a byte string of IPv6 address and pass them to the function using the | |
919 | * payload interface. | |
920 | * @param nh next header | |
921 | * @param len length of the header in 8-byte octets not including the first 8 octets | |
922 | * @rtype routing header type | |
923 | * @param segments number of routing segments that follow | |
924 | * @param payload optional payload of routing information | |
925 | * @param payload_s payload length | |
926 | * @param l pointer to a libnet context | |
927 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
928 | * @return protocol tag value on success, -1 on error | |
929 | */ | |
930 | libnet_ptag_t | |
931 | libnet_build_ipv6_routing(u_int8_t nh, u_int8_t len, u_int8_t rtype, | |
932 | u_int8_t segments, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
933 | libnet_ptag_t ptag); | |
934 | ||
935 | /** | |
936 | * Builds a version 6 RFC 2460 Internet Protocol (IP) destination options | |
937 | * header. This function is special in that it uses the payload interface to | |
938 | * include the options data. The application programmer will build an IPv6 | |
939 | * options byte string and pass it to the function using the payload interface. | |
940 | * @param nh next header | |
941 | * @param len length of the header in 8-byte octets not including the first 8 octets | |
942 | * @param payload options payload | |
943 | * @param payload_s payload length | |
944 | * @param l pointer to a libnet context | |
945 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
946 | * @return protocol tag value on success, -1 on error | |
947 | */ | |
948 | libnet_ptag_t | |
949 | libnet_build_ipv6_destopts(u_int8_t nh, u_int8_t len, u_int8_t *payload, | |
950 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
951 | ||
952 | /** | |
953 | * Builds a version 6 RFC 2460 Internet Protocol (IP) hop by hop options | |
954 | * header. This function is special in that it uses the payload interface to | |
955 | * include the options data. The application programmer will build an IPv6 | |
956 | * hop by hop options byte string and pass it to the function using the payload | |
957 | * interface. | |
958 | * @param nh next header | |
959 | * @param len length of the header in 8-byte octets not including the first 8 octets | |
960 | * @param payload options payload | |
961 | * @param payload_s payload length | |
962 | * @param l pointer to a libnet context | |
963 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
964 | * @return protocol tag value on success, -1 on error | |
965 | */ | |
966 | libnet_ptag_t | |
967 | libnet_build_ipv6_hbhopts(u_int8_t nh, u_int8_t len, u_int8_t *payload, | |
968 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
969 | ||
970 | /** | |
971 | * This function is not yet implement and is a NONOP. | |
972 | * @param len length | |
973 | * @param nh next header | |
974 | * @param dst destination IPv6 address | |
975 | * @param payload optional payload or NULL | |
976 | * @param payload_s payload length or 0 | |
977 | * @param l pointer to a libnet context | |
978 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
979 | * @return protocol tag value on success, -1 on error | |
980 | */ | |
981 | libnet_ptag_t | |
982 | libnet_autobuild_ipv6(u_int16_t len, u_int8_t nh, struct libnet_in6_addr dst, | |
983 | libnet_t *l); | |
984 | ||
985 | /** | |
986 | * Builds a Cisco Inter-Switch Link (ISL) header. | |
987 | * @param dhost destination address (should be 01:00:0c:00:00) | |
988 | * @param type type of frame | |
989 | * @param user user defined data | |
990 | * @param shost source mac address | |
991 | * @param len total length of the encapuslated packet less 18 bytes | |
992 | * @param snap SNAP information (0xaaaa03 + vendor code) | |
993 | * @param vid 15 bit VLAN ID, 1 bit BPDU or CDP indicator | |
994 | * @param index port index | |
995 | * @param reserved used for FDDI and token ring | |
996 | * @param payload optional payload or NULL | |
997 | * @param payload_s payload length or 0 | |
998 | * @param l pointer to a libnet context | |
999 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1000 | * @return protocol tag value on success, -1 on error | |
1001 | */ | |
1002 | libnet_ptag_t | |
1003 | libnet_build_isl(u_int8_t *dhost, u_int8_t type, u_int8_t user, u_int8_t *shost, | |
1004 | u_int16_t len, u_int8_t *snap, u_int16_t vid, u_int16_t index, | |
1005 | u_int16_t reserved, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1006 | libnet_ptag_t ptag); | |
1007 | ||
1008 | /** | |
1009 | * Builds an Internet Protocol Security Encapsulating Security Payload header. | |
1010 | * @param spi security parameter index | |
1011 | * @param seq ESP sequence number | |
1012 | * @param iv initialization vector | |
1013 | * @param payload optional payload or NULL | |
1014 | * @param payload_s payload length or 0 | |
1015 | * @param l pointer to a libnet context | |
1016 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1017 | * @return protocol tag value on success, -1 on error | |
1018 | */ | |
1019 | libnet_ptag_t | |
1020 | libnet_build_ipsec_esp_hdr(u_int32_t spi, u_int32_t seq, u_int32_t iv, | |
1021 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1022 | ||
1023 | /** | |
1024 | * Builds an Internet Protocol Security Encapsulating Security Payload footer. | |
1025 | * @param len padding length | |
1026 | * @param nh next header | |
1027 | * @param auth authentication data | |
1028 | * @param payload optional payload or NULL | |
1029 | * @param payload_s payload length or 0 | |
1030 | * @param l pointer to a libnet context | |
1031 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1032 | * @return protocol tag value on success, -1 on error | |
1033 | */ | |
1034 | libnet_ptag_t | |
1035 | libnet_build_ipsec_esp_ftr(u_int8_t len, u_int8_t nh, int8_t *auth, | |
1036 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1037 | ||
1038 | /** | |
1039 | * Builds an Internet Protocol Security Authentication header. | |
1040 | * @param nh next header | |
1041 | * @param len payload length | |
1042 | * @param res reserved | |
1043 | * @param spi security parameter index | |
1044 | * @param seq sequence number | |
1045 | * @param auth authentication data | |
1046 | * @param payload optional payload or NULL | |
1047 | * @param payload_s payload length or 0 | |
1048 | * @param l pointer to a libnet context | |
1049 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1050 | * @return protocol tag value on success, -1 on error | |
1051 | */ | |
1052 | libnet_ptag_t | |
1053 | libnet_build_ipsec_ah(u_int8_t nh, u_int8_t len, u_int16_t res, | |
1054 | u_int32_t spi, u_int32_t seq, u_int32_t auth, u_int8_t *payload, | |
1055 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1056 | ||
1057 | /** | |
1058 | * Builds an RFC 1035 version 4 DNS header. Additional DNS payload information | |
1059 | * should be specified using the payload interface. | |
1060 | * @param id DNS packet id | |
1061 | * @param flags control flags | |
1062 | * @param num_q number of questions | |
1063 | * @param num_anws_rr number of answer resource records | |
1064 | * @param num_auth_rr number of authority resource records | |
1065 | * @param num_addi_rr number of additional resource records | |
1066 | * @param payload optional payload or NULL | |
1067 | * @param payload_s payload length or 0 | |
1068 | * @param l pointer to a libnet context | |
1069 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1070 | * @return protocol tag value on success, -1 on error | |
1071 | */ | |
1072 | libnet_ptag_t | |
1073 | libnet_build_dnsv4(u_int16_t h_len, u_int16_t id, u_int16_t flags, | |
1074 | u_int16_t num_q, u_int16_t num_anws_rr, u_int16_t num_auth_rr, | |
1075 | u_int16_t num_addi_rr, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1076 | libnet_ptag_t ptag); | |
1077 | ||
1078 | /** | |
1079 | * Builds a Routing Information Protocol header (RFCs 1058 and 2453). | |
1080 | * @param cmd command | |
1081 | * @param version protocol version | |
1082 | * @param rd version one: 0, version two: routing domain | |
1083 | * @param af address family | |
1084 | * @param rt version one: 0, version two: route tag | |
1085 | * @param addr IPv4 address | |
1086 | * @param mask version one: 0, version two: subnet mask | |
1087 | * @param next_hop version one: 0, version two: next hop address | |
1088 | * @param metric routing metric | |
1089 | * @param payload optional payload or NULL | |
1090 | * @param payload_s payload length or 0 | |
1091 | * @param l pointer to a libnet context | |
1092 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1093 | * @return protocol tag value on success, -1 on error | |
1094 | */ | |
1095 | libnet_ptag_t | |
1096 | libnet_build_rip(u_int8_t cmd, u_int8_t version, u_int16_t rd, u_int16_t af, | |
1097 | u_int16_t rt, u_int32_t addr, u_int32_t mask, u_int32_t next_hop, | |
1098 | u_int32_t metric, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1099 | libnet_ptag_t ptag); | |
1100 | ||
1101 | /** | |
1102 | * Builds an Remote Procedure Call (Version 2) Call message header as | |
1103 | * specified in RFC 1831. This builder provides the option for | |
1104 | * specifying the record marking which is required when used with | |
1105 | * streaming protocols (TCP). | |
1106 | * @param rm record marking indicating the position in a stream, 0 otherwise | |
1107 | * @param xid transaction identifier used to link calls and replies | |
1108 | * @param prog_num remote program specification typically between 0 - 1fffffff | |
1109 | * @param prog_vers remote program version specification | |
1110 | * @param procedure procedure to be performed by remote program | |
1111 | * @param cflavor authentication credential type | |
1112 | * @param clength credential length (should be 0) | |
1113 | * @param cdata opaque credential data (currently unused) | |
1114 | * @param vflavor authentication verifier type | |
1115 | * @param vlength verifier length (should be 0) | |
1116 | * @param vdata opaque verifier data (currently unused) | |
1117 | * @param payload optional payload or NULL | |
1118 | * @param payload_s payload length or 0 | |
1119 | * @param l pointer to a libnet context | |
1120 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1121 | * @return protocol tag value on success, -1 on error | |
1122 | */ | |
1123 | libnet_ptag_t | |
1124 | libnet_build_rpc_call(u_int32_t rm, u_int32_t xid, u_int32_t prog_num, | |
1125 | u_int32_t prog_vers, u_int32_t procedure, u_int32_t cflavor, u_int32_t clength, | |
1126 | u_int8_t *cdata, u_int32_t vflavor, u_int32_t vlength, u_int8_t *vdata, | |
1127 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1128 | ||
1129 | /** | |
1130 | * Builds an IEEE 802.1d Spanning Tree Protocol (STP) configuration header. | |
1131 | * STP frames are usually encapsulated inside of an 802.2 + 802.3 frame | |
1132 | * combination. | |
1133 | * @param id protocol id | |
1134 | * @param version protocol version | |
1135 | * @param bpdu_type bridge protocol data unit type | |
1136 | * @param flags flags | |
1137 | * @param root_id root id | |
1138 | * @param root_pc root path cost | |
1139 | * @param bridge_id bridge id | |
1140 | * @param port_id port id | |
1141 | * @param message_age message age | |
1142 | * @param max_age max age | |
1143 | * @param hello_time hello time | |
1144 | * @param f_delay forward delay | |
1145 | * @param payload optional payload or NULL | |
1146 | * @param payload_s payload length or 0 | |
1147 | * @param l pointer to a libnet context | |
1148 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1149 | * @return protocol tag value on success, -1 on error | |
1150 | */ | |
1151 | libnet_ptag_t | |
1152 | libnet_build_stp_conf(u_int16_t id, u_int8_t version, u_int8_t bpdu_type, | |
1153 | u_int8_t flags, u_int8_t *root_id, u_int32_t root_pc, u_int8_t *bridge_id, | |
1154 | u_int16_t port_id, u_int16_t message_age, u_int16_t max_age, | |
1155 | u_int16_t hello_time, u_int16_t f_delay, u_int8_t *payload, | |
1156 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1157 | ||
1158 | /** | |
1159 | * Builds an IEEE 802.1d Spanning Tree Protocol (STP) topology change | |
1160 | * notification header. STP frames are usually encapsulated inside of an | |
1161 | * 802.2 + 802.3 frame combination. | |
1162 | * @param id protocol id | |
1163 | * @param version protocol version | |
1164 | * @param bpdu_type bridge protocol data unit type | |
1165 | * @param payload optional payload or NULL | |
1166 | * @param payload_s payload length or 0 | |
1167 | * @param l pointer to a libnet context | |
1168 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1169 | * @return protocol tag value on success, -1 on error | |
1170 | */ | |
1171 | libnet_ptag_t | |
1172 | libnet_build_stp_tcn(u_int16_t id, u_int8_t version, u_int8_t bpdu_type, | |
1173 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1174 | ||
1175 | /** | |
1176 | * Builds a token ring header. | |
1177 | * @param ac access control | |
1178 | * @param fc frame control | |
1179 | * @param dst destination address | |
1180 | * @param src source address | |
1181 | * @param dsap destination service access point | |
1182 | * @param ssap source service access point | |
1183 | * @param cf control field | |
1184 | * @param oui Organizationally Unique Identifier | |
1185 | * @param type upper layer protocol type | |
1186 | * @param payload optional payload or NULL | |
1187 | * @param payload_s payload length or 0 | |
1188 | * @param l pointer to a libnet context | |
1189 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1190 | * @return protocol tag value on success, -1 on error | |
1191 | */ | |
1192 | libnet_ptag_t | |
1193 | libnet_build_token_ring(u_int8_t ac, u_int8_t fc, u_int8_t *dst, u_int8_t *src, | |
1194 | u_int8_t dsap, u_int8_t ssap, u_int8_t cf, u_int8_t *oui, u_int16_t type, | |
1195 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1196 | ||
1197 | /** | |
1198 | * Auto-builds a token ring header. | |
1199 | * @param ac access control | |
1200 | * @param fc frame control | |
1201 | * @param dst destination address | |
1202 | * @param dsap destination service access point | |
1203 | * @param ssap source service access point | |
1204 | * @param cf control field | |
1205 | * @param oui Organizationally Unique Identifier | |
1206 | * @param type upper layer protocol type | |
1207 | * @param l pointer to a libnet context | |
1208 | * @return protocol tag value on success, -1 on error | |
1209 | */ | |
1210 | libnet_ptag_t | |
1211 | libnet_autobuild_token_ring(u_int8_t ac, u_int8_t fc, u_int8_t *dst, | |
1212 | u_int8_t dsap, u_int8_t ssap, u_int8_t cf, u_int8_t *oui, u_int16_t type, | |
1213 | libnet_t *l); | |
1214 | ||
1215 | /** | |
1216 | * Builds an RFC 2338 Virtual Router Redundacy Protool (VRRP) header. Use the | |
1217 | * payload interface to specify address and autthentication information. To | |
1218 | * build a "legal" packet, the destination IPv4 address should be the multicast * address 224.0.0.18, the IP TTL should be set to 255, and the IP protocol | |
1219 | * should be set to 112. | |
1220 | * @param version VRRP version (should be 2) | |
1221 | * @param type VRRP packet type (should be 1 -- ADVERTISEMENT) | |
1222 | * @param vrouter_id virtual router identification | |
1223 | * @param priority priority (higher numbers indicate higher priority) | |
1224 | * @param ip_count number of IPv4 addresses contained in this advertisement | |
1225 | * @param auth_type type of authentication (0, 1, 2 -- see RFC) | |
1226 | * @param advert_int interval between advertisements | |
1227 | * @param sum checksum (0 for libnet to autofill) | |
1228 | * @param payload optional payload or NULL | |
1229 | * @param payload_s payload length or 0 | |
1230 | * @param l pointer to a libnet context | |
1231 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1232 | * @return protocol tag value on success, -1 on error | |
1233 | */ | |
1234 | libnet_ptag_t | |
1235 | libnet_build_vrrp(u_int8_t version, u_int8_t type, u_int8_t vrouter_id, | |
1236 | u_int8_t priority, u_int8_t ip_count, u_int8_t auth_type, u_int8_t advert_int, | |
1237 | u_int16_t sum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1238 | libnet_ptag_t ptag); | |
1239 | ||
1240 | /** | |
1241 | * Builds an RFC 3032 Multi-Protocol Label Switching (MPLS) header. | |
1242 | * @param label 20-bit label value | |
1243 | * @param experimental 3-bit reserved field | |
1244 | * @param bos 1-bit bottom of stack identifier | |
1245 | * @param ttl time to live | |
1246 | * @param payload optional payload or NULL | |
1247 | * @param payload_s payload length or 0 | |
1248 | * @param l pointer to a libnet context | |
1249 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1250 | * @return protocol tag value on success, -1 on error | |
1251 | */ | |
1252 | libnet_ptag_t | |
1253 | libnet_build_mpls(u_int32_t label, u_int8_t experimental, u_int8_t bos, | |
1254 | u_int8_t ttl, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1255 | libnet_ptag_t ptag); | |
1256 | ||
1257 | /** | |
1258 | * Builds an RFC 958 Network Time Protocol (NTP) header. | |
1259 | * @param leap_indicator the leap indicator | |
1260 | * @param version NTP protocol version | |
1261 | * @param mode NTP mode | |
1262 | * @param stratum stratum | |
1263 | * @param poll polling interval | |
1264 | * @param precision precision | |
1265 | * @param delay_interval delay interval | |
1266 | * @param delay_frac delay fraction | |
1267 | * @param dispersion_int dispersion interval | |
1268 | * @param dispersion_frac dispersion fraction | |
1269 | * @param reference_id reference id | |
1270 | * @param ref_ts_int reference timestamp integer | |
1271 | * @param ref_ts_frac reference timestamp fraction | |
1272 | * @param orig_ts_int original timestamp integer | |
1273 | * @param orig_ts_frac original timestamp fraction | |
1274 | * @param rec_ts_int receiver timestamp integer | |
1275 | * @param rec_ts_frac reciever timestamp fraction | |
1276 | * @param xmt_ts_int transmit timestamp integer | |
1277 | * @param xmt_ts_frac transmit timestamp integer | |
1278 | * @param payload optional payload or NULL | |
1279 | * @param payload_s payload length or 0 | |
1280 | * @param l pointer to a libnet context | |
1281 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1282 | * @return protocol tag value on success, -1 on error | |
1283 | */ | |
1284 | libnet_ptag_t | |
1285 | libnet_build_ntp(u_int8_t leap_indicator, u_int8_t version, u_int8_t mode, | |
1286 | u_int8_t stratum, u_int8_t poll, u_int8_t precision, u_int16_t delay_int, | |
1287 | u_int16_t delay_frac, u_int16_t dispersion_int, u_int16_t dispersion_frac, | |
1288 | u_int32_t reference_id, u_int32_t ref_ts_int, u_int32_t ref_ts_frac, | |
1289 | u_int32_t orig_ts_int, u_int32_t orig_ts_frac, u_int32_t rec_ts_int, | |
1290 | u_int32_t rec_ts_frac, u_int32_t xmt_ts_int, u_int32_t xmt_ts_frac, | |
1291 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1292 | ||
1293 | /** | |
1294 | * @param payload optional payload or NULL | |
1295 | * @param payload_s payload length or 0 | |
1296 | * @param l pointer to a libnet context | |
1297 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1298 | * @return protocol tag value on success, -1 on error | |
1299 | */ | |
1300 | libnet_ptag_t | |
1301 | libnet_build_ospfv2(u_int16_t len, u_int8_t type, u_int32_t rtr_id, | |
1302 | u_int32_t area_id, u_int16_t sum, u_int16_t autype, u_int8_t *payload, | |
1303 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1304 | ||
1305 | /** | |
1306 | * @param payload optional payload or NULL | |
1307 | * @param payload_s payload length or 0 | |
1308 | * @param l pointer to a libnet context | |
1309 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1310 | * @return protocol tag value on success, -1 on error | |
1311 | */ | |
1312 | libnet_ptag_t | |
1313 | libnet_build_ospfv2_hello(u_int32_t netmask, u_int16_t interval, u_int8_t opts, | |
1314 | u_int8_t priority, u_int dead_int, u_int32_t des_rtr, u_int32_t bkup_rtr, | |
1315 | u_int32_t neighbor, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1316 | libnet_ptag_t ptag); | |
1317 | ||
1318 | /** | |
1319 | * @param payload optional payload or NULL | |
1320 | * @param payload_s payload length or 0 | |
1321 | * @param l pointer to a libnet context | |
1322 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1323 | * @return protocol tag value on success, -1 on error | |
1324 | */ | |
1325 | libnet_ptag_t | |
1326 | libnet_build_ospfv2_dbd(u_int16_t dgram_len, u_int8_t opts, u_int8_t type, | |
1327 | u_int seqnum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1328 | libnet_ptag_t ptag); | |
1329 | ||
1330 | /** | |
1331 | * @param payload optional payload or NULL | |
1332 | * @param payload_s payload length or 0 | |
1333 | * @param l pointer to a libnet context | |
1334 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1335 | * @return protocol tag value on success, -1 on error | |
1336 | */ | |
1337 | libnet_ptag_t | |
1338 | libnet_build_ospfv2_lsr(u_int type, u_int lsid, u_int32_t advrtr, | |
1339 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1340 | ||
1341 | /** | |
1342 | * @param payload optional payload or NULL | |
1343 | * @param payload_s payload length or 0 | |
1344 | * @param l pointer to a libnet context | |
1345 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1346 | * @return protocol tag value on success, -1 on error | |
1347 | */ | |
1348 | libnet_ptag_t | |
1349 | libnet_build_ospfv2_lsu(u_int num, u_int8_t *payload, u_int32_t payload_s, | |
1350 | libnet_t *l, libnet_ptag_t ptag); | |
1351 | ||
1352 | /** | |
1353 | * @param payload optional payload or NULL | |
1354 | * @param payload_s payload length or 0 | |
1355 | * @param l pointer to a libnet context | |
1356 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1357 | * @return protocol tag value on success, -1 on error | |
1358 | */ | |
1359 | libnet_ptag_t | |
1360 | libnet_build_ospfv2_lsa(u_int16_t age, u_int8_t opts, u_int8_t type, | |
1361 | u_int lsid, u_int32_t advrtr, u_int seqnum, u_int16_t sum, u_int16_t len, | |
1362 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1363 | ||
1364 | /** | |
1365 | * @param payload optional payload or NULL | |
1366 | * @param payload_s payload length or 0 | |
1367 | * @param l pointer to a libnet context | |
1368 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1369 | * @return protocol tag value on success, -1 on error | |
1370 | */ | |
1371 | libnet_ptag_t | |
1372 | libnet_build_ospfv2_lsa_rtr(u_int16_t flags, u_int16_t num, u_int id, | |
1373 | u_int data, u_int8_t type, u_int8_t tos, u_int16_t metric, u_int8_t *payload, | |
1374 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1375 | ||
1376 | /** | |
1377 | * @param payload optional payload or NULL | |
1378 | * @param payload_s payload length or 0 | |
1379 | * @param l pointer to a libnet context | |
1380 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1381 | * @return protocol tag value on success, -1 on error | |
1382 | */ | |
1383 | libnet_ptag_t | |
1384 | libnet_build_ospfv2_lsa_net(u_int32_t nmask, u_int rtrid, u_int8_t *payload, | |
1385 | u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1386 | ||
1387 | /** | |
1388 | * @param payload optional payload or NULL | |
1389 | * @param payload_s payload length or 0 | |
1390 | * @param l pointer to a libnet context | |
1391 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1392 | * @return protocol tag value on success, -1 on error | |
1393 | */ | |
1394 | libnet_ptag_t | |
1395 | libnet_build_ospfv2_lsa_sum(u_int32_t nmask, u_int metric, u_int tos, | |
1396 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1397 | ||
1398 | /** | |
1399 | * @param payload optional payload or NULL | |
1400 | * @param payload_s payload length or 0 | |
1401 | * @param l pointer to a libnet context | |
1402 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1403 | * @return protocol tag value on success, -1 on error | |
1404 | */ | |
1405 | libnet_ptag_t | |
1406 | libnet_build_ospfv2_lsa_as(u_int32_t nmask, u_int metric, u_int32_t fwdaddr, | |
1407 | u_int tag, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1408 | libnet_ptag_t ptag); | |
1409 | ||
1410 | /** | |
1411 | * Builds a generic libnet protocol header. This is useful for including an | |
1412 | * optional payload to a packet that might need to change repeatedly inside | |
1413 | * of a loop. | |
1414 | * @param payload optional payload or NULL | |
1415 | * @param payload_s payload length or 0 | |
1416 | * @param l pointer to a libnet context | |
1417 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1418 | * @return protocol tag value on success, -1 on error | |
1419 | */ | |
1420 | libnet_ptag_t | |
1421 | libnet_build_data(u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1422 | libnet_ptag_t ptag); | |
1423 | ||
1424 | /** | |
1425 | * @param payload optional payload or NULL | |
1426 | * @param payload_s payload length or 0 | |
1427 | * @param l pointer to a libnet context | |
1428 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1429 | * @return protocol tag value on success, -1 on error | |
1430 | */ | |
1431 | libnet_ptag_t | |
1432 | libnet_build_dhcpv4(u_int8_t opcode, u_int8_t htype, u_int8_t hlen, | |
1433 | u_int8_t hopcount, u_int32_t xid, u_int16_t secs, u_int16_t flags, | |
1434 | u_int32_t cip, u_int32_t yip, u_int32_t sip, u_int32_t gip, u_int8_t *chaddr, | |
1435 | u_int8_t *sname, u_int8_t *file, u_int8_t *payload, u_int32_t payload_s, | |
1436 | libnet_t *l, libnet_ptag_t ptag); | |
1437 | ||
1438 | /** | |
1439 | * @param payload optional payload or NULL | |
1440 | * @param payload_s payload length or 0 | |
1441 | * @param l pointer to a libnet context | |
1442 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1443 | * @return protocol tag value on success, -1 on error | |
1444 | */ | |
1445 | libnet_ptag_t | |
1446 | libnet_build_bootpv4(u_int8_t opcode, u_int8_t htype, u_int8_t hlen, | |
1447 | u_int8_t hopcount, u_int32_t xid, u_int16_t secs, u_int16_t flags, | |
1448 | u_int32_t cip, u_int32_t yip, u_int32_t sip, u_int32_t gip, u_int8_t *chaddr, | |
1449 | u_int8_t *sname, u_int8_t *file, u_int8_t *payload, u_int32_t payload_s, | |
1450 | libnet_t *l, libnet_ptag_t ptag); | |
1451 | ||
1452 | /** | |
1453 | * @param payload optional payload or NULL | |
1454 | * @param payload_s payload length or 0 | |
1455 | * @param l pointer to a libnet context | |
1456 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1457 | * @return protocol tag value on success, -1 on error | |
1458 | */ | |
1459 | inline u_int32_t | |
1460 | libnet_getgre_length(u_int16_t fv); | |
1461 | ||
1462 | /** | |
1463 | * Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate any | |
1464 | * protocol. Hence, the IP part of the packet is usually referred as "delivery | |
1465 | * header". It is then followed by the GRE header and finally the encapsulated | |
1466 | * packet (IP or whatever). | |
1467 | * As GRE is very modular, the first GRE header describes the structure of the | |
1468 | * header, using bits and flag to specify which fields will be present in the | |
1469 | * header. | |
1470 | * @param fv the 16 0 to 7: which fields are included in the header (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to 15: version. | |
1471 | * @param payload optional payload or NULL | |
1472 | * @param type which protocol is encapsulated (PPP, IP, ...) | |
1473 | * @param sum checksum (0 for libnet to autofill). | |
1474 | * @param offset byte offset from the start of the routing field to the first byte of the SRE | |
1475 | * @param key inserted by the encapsulator to authenticate the source | |
1476 | * @param seq sequence number used by the receiver to sort the packets | |
1477 | * @param len size of the GRE packet | |
1478 | * @param payload_s payload length or 0 | |
1479 | * @param l pointer to a libnet context | |
1480 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1481 | * @return protocol tag value on success, -1 on error | |
1482 | */ | |
1483 | libnet_ptag_t | |
1484 | libnet_build_gre(u_int16_t fv, u_int16_t type, u_int16_t sum, | |
1485 | u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, | |
1486 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1487 | ||
1488 | /** | |
1489 | * Generic Routing Encapsulation (GRE - RFC 1701) is used to encapsulate any | |
1490 | * protocol. Hence, the IP part of the packet is usually referred as "delivery | |
1491 | * header". It is then followed by the GRE header and finally the encapsulated | |
1492 | * packet (IP or whatever). | |
1493 | * As GRE is very modular, the first GRE header describes the structure of the | |
1494 | * header, using bits and flag to specify which fields will be present in the | |
1495 | * header. | |
1496 | * @param fv the 16 0 to 7: which fields are included in the header (checksum, seq. number, key, ...), bits 8 to 12: flag, bits 13 to 15: version. | |
1497 | * @param payload optional payload or NULL | |
1498 | * @param type which protocol is encapsulated (PPP, IP, ...) | |
1499 | * @param sum checksum (0 for libnet to autofill). | |
1500 | * @param offset byte offset from the start of the routing field to the first byte of the SRE | |
1501 | * @param key inserted by the encapsulator to authenticate the source | |
1502 | * @param seq sequence number used by the receiver to sort the packets | |
1503 | * @param len size of the GRE packet | |
1504 | * @param payload_s payload length or 0 | |
1505 | * @param l pointer to a libnet context | |
1506 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1507 | * @return protocol tag value on success, -1 on error | |
1508 | */ | |
1509 | libnet_ptag_t | |
1510 | libnet_build_egre(u_int16_t fv, u_int16_t type, u_int16_t sum, | |
1511 | u_int16_t offset, u_int32_t key, u_int32_t seq, u_int16_t len, | |
1512 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1513 | ||
1514 | /** | |
1515 | * @param payload optional payload or NULL | |
1516 | * @param payload_s payload length or 0 | |
1517 | * @param l pointer to a libnet context | |
1518 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1519 | * @return protocol tag value on success, -1 on error | |
1520 | */ | |
1521 | libnet_ptag_t | |
1522 | libnet_build_gre_sre(u_int16_t af, u_int8_t offset, u_int8_t length, | |
1523 | u_int8_t *routing, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, | |
1524 | libnet_ptag_t ptag); | |
1525 | ||
1526 | /** | |
1527 | * @param payload optional payload or NULL | |
1528 | * @param payload_s payload length or 0 | |
1529 | * @param l pointer to a libnet context | |
1530 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1531 | * @return protocol tag value on success, -1 on error | |
1532 | */ | |
1533 | libnet_ptag_t | |
1534 | libnet_build_gre_last_sre(libnet_t *l, libnet_ptag_t ptag); | |
1535 | ||
1536 | /** | |
1537 | * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) header. The primary | |
1538 | * function of a BGP speaking system is to exchange network reachability | |
1539 | * information with other BGP systems. This network reachability information | |
1540 | * includes information on the list of Autonomous Systems (ASs) that | |
1541 | * reachability information traverses. This information is sufficient to | |
1542 | * construct a graph of AS connectivity from which routing loops may be pruned | |
1543 | * and some policy decisions at the AS level may be enforced. | |
1544 | * This function builds the base BGP header which is used as a preamble before | |
1545 | * any other BGP header. For example, a BGP KEEPALIVE message may be built with | |
1546 | * only this function, while an error notification requires a subsequent call | |
1547 | * to libnet_build_bgp4_notification. | |
1548 | * @param marker a value the receiver can predict (if the message type is not BGP OPEN, or no authentication is used, these 16 bytes are normally set as all ones) | |
1549 | * @param len total length of the BGP message, including the header | |
1550 | * @param type type code of the message (OPEN, UPDATE, NOTIFICATION or KEEPALIVE) | |
1551 | * @param payload optional payload or NULL | |
1552 | * @param payload_s payload length or 0 | |
1553 | * @param l pointer to a libnet context | |
1554 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1555 | * @return protocol tag value on success, -1 on error | |
1556 | */ | |
1557 | libnet_ptag_t | |
1558 | libnet_build_bgp4_header(u_int8_t marker[LIBNET_BGP4_MARKER_SIZE], | |
1559 | u_int16_t len, u_int8_t type, u_int8_t *payload, u_int32_t payload_s, | |
1560 | libnet_t *l, libnet_ptag_t ptag); | |
1561 | ||
1562 | /** | |
1563 | * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) OPEN header. This is | |
1564 | * the first message sent by each side of a BGP connection. The optional | |
1565 | * parameters options should be constructed using the payload interface (see | |
1566 | * RFC 1771 for the options structures). | |
1567 | * @param version protocol version (should be set to 4) | |
1568 | * @param src_as Autonomous System of the sender | |
1569 | * @param hold_time used to compute the maximum allowed time between the receipt of KEEPALIVE, and/or UPDATE messages by the sender | |
1570 | * @param bgp_id BGP identifier of the sender | |
1571 | * @param opt_len total length of the optional parameters field in bytes | |
1572 | * @param payload optional payload or NULL | |
1573 | * @param payload_s payload length or 0 | |
1574 | * @param l pointer to a libnet context | |
1575 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1576 | * @return protocol tag value on success, -1 on error | |
1577 | */ | |
1578 | libnet_ptag_t | |
1579 | libnet_build_bgp4_open(u_int8_t version, u_int16_t src_as, u_int16_t hold_time, | |
1580 | u_int32_t bgp_id, u_int8_t opt_len, u_int8_t *payload, u_int32_t payload_s, | |
1581 | libnet_t *l, libnet_ptag_t ptag); | |
1582 | ||
1583 | /** | |
1584 | * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) update header. Update | |
1585 | * messages are used to transfer routing information between BGP peers. | |
1586 | * @param unfeasible_rt_len indicates the length of the (next) "withdrawn routes" field in bytes | |
1587 | * @param withdrawn_rt list of IP addresses prefixes for the routes that are being withdrawn; each IP address prefix is built as a 2-tuple <length (1 byte), prefix (variable)> | |
1588 | * @param total_path_attr_len indicates the length of the (next) "path attributes" field in bytes | |
1589 | * @param path_attributes each attribute is a 3-tuple <type (2 bytes), length, value> | |
1590 | * @param info_len indicates the length of the (next) "network layer reachability information" field in bytes (needed for internal memory size calculation) | |
1591 | * @param reachability_info 2-tuples <length (1 byte), prefix (variable)>. | |
1592 | * @param payload optional payload or NULL | |
1593 | * @param payload_s payload length or 0 | |
1594 | * @param l pointer to a libnet context | |
1595 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1596 | * @return protocol tag value on success, -1 on error | |
1597 | */ | |
1598 | libnet_ptag_t | |
1599 | libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, u_int8_t *withdrawn_rt, | |
1600 | u_int16_t total_path_attr_len, u_int8_t *path_attributes, u_int16_t info_len, | |
1601 | u_int8_t *reachability_info, u_int8_t *payload, u_int32_t payload_s, | |
1602 | libnet_t *l, libnet_ptag_t ptag); | |
1603 | ||
1604 | /** | |
1605 | * Builds an RFC 1771 Border Gateway Protocol 4 (BGP-4) notification header. | |
1606 | * A NOTIFICATION message is sent when an error condition is detected. Specific | |
1607 | * error information may be passed through the payload interface. | |
1608 | * @param err_code type of notification | |
1609 | * @param err_subcode more specific information about the reported error. | |
1610 | * @param payload optional payload or NULL | |
1611 | * @param payload_s payload length or 0 | |
1612 | * @param l pointer to a libnet context | |
1613 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1614 | * @return protocol tag value on success, -1 on error | |
1615 | */ | |
1616 | libnet_ptag_t | |
1617 | libnet_build_bgp4_notification(u_int8_t err_code, u_int8_t err_subcode, | |
1618 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1619 | ||
1620 | /** | |
1621 | * Builds a Sebek header. The Sebek protocol was designed by the Honeynet | |
1622 | * Project as a transport mechanism for post-intrusion forensic data. More | |
1623 | * information may be found here: http://www.honeynet.org/papers/sebek.pdf. | |
1624 | * @param magic identify packets that should be hidden | |
1625 | * @param version protocol version, currently 1 | |
1626 | * @param type type of record (read data is type 0, write data is type 1) | |
1627 | * @param counter PDU counter used to identify when packet are lost | |
1628 | * @param time_sec seconds since EPOCH according to the honeypot | |
1629 | * @param time_usec residual microseconds | |
1630 | * @param pid PID | |
1631 | * @param uid UID | |
1632 | * @param fd FD | |
1633 | * @param cmd[SEBEK_CMD_LENGTH] 12 first characters of the command | |
1634 | * @param length length in bytes of the PDU's body | |
1635 | * @param payload optional payload or NULL | |
1636 | * @param payload_s payload length or 0 | |
1637 | * @param l pointer to a libnet context | |
1638 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1639 | * @return protocol tag value on success, -1 on error | |
1640 | */ | |
1641 | libnet_ptag_t | |
1642 | libnet_build_sebek(u_int32_t magic, u_int16_t version, u_int16_t type, | |
1643 | u_int32_t counter, u_int32_t time_sec, u_int32_t time_usec, u_int32_t pid, | |
1644 | u_int32_t uid, u_int32_t fd, u_int8_t cmd[SEBEK_CMD_LENGTH], u_int32_t length, | |
1645 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1646 | ||
1647 | /** | |
1648 | * Builds a link layer header for an initialized l. The function | |
1649 | * determines the proper link layer header format from how l was initialized. | |
1650 | * The function current supports Ethernet and Token Ring link layers. | |
1651 | * @param dst the destination MAC address | |
1652 | * @param src the source MAC address | |
1653 | * @param oui Organizationally Unique Identifier (unused for Ethernet) | |
1654 | * @param type the upper layer protocol type | |
1655 | * @param payload optional payload or NULL | |
1656 | * @param payload_s payload length or 0 | |
1657 | * @param l pointer to a libnet context | |
1658 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1659 | * @return protocol tag value on success, -1 on error | |
1660 | */ | |
1661 | libnet_ptag_t | |
1662 | libnet_build_link(u_int8_t *dst, u_int8_t *src, u_int8_t *oui, u_int16_t type, | |
1663 | u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1664 | ||
1665 | /** | |
1666 | * Automatically builds a link layer header for an initialized l. The function | |
1667 | * determines the proper link layer header format from how l was initialized. | |
1668 | * The function current supports Ethernet and Token Ring link layers. | |
1669 | * @param dst the destination MAC address | |
1670 | * @param oui Organizationally Unique Identifier (unused for Ethernet) | |
1671 | * @param type the upper layer protocol type | |
1672 | * @param l pointer to a libnet context | |
1673 | * @return protocol tag value on success, -1 on error | |
1674 | */ | |
1675 | libnet_ptag_t | |
1676 | libnet_autobuild_link(u_int8_t *dst, u_int8_t *oui, u_int16_t type, | |
1677 | libnet_t *l); | |
1678 | ||
1679 | /** | |
1680 | * Builds an Stream Control Transmission Protocol (SCTP) header. | |
1681 | * @param sp source port | |
1682 | * @param dp destination port | |
1683 | * @param vtag verification tag | |
1684 | * @param chksum checksum (0 for libnet to autofill) | |
1685 | * @param payload pointer to the payload (i.e. the first data chunk hdr) | |
1686 | * @param payload_s payload length or 0 | |
1687 | * @param l pointer to a libnet context | |
1688 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1689 | * @return protocol tag value on success, -1 on error | |
1690 | */ | |
1691 | libnet_ptag_t | |
1692 | libnet_build_sctp(u_int16_t sp, u_int16_t dp, u_int32_t vtag, u_int32_t chksum, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1693 | ||
1694 | u_int32_t | |
1695 | libnet_sctp_cksum(u_int8_t *buffer, u_int16_t length); | |
1696 | ||
1697 | /** | |
1698 | * Builds an RFC 2205 Resource Reservation Protocol (RSVP) header. | |
1699 | * @param version RSVP protocol version | |
1700 | * @param flags RSVP flags | |
1701 | * @param type RSVP message type | |
1702 | * @param do_chksum 0 if no chksum reqd, 1 otherwise | |
1703 | * @param chksum checksum (0 for libnet to autofill) | |
1704 | * @param ttl IP TTL field value | |
1705 | * @param len RSVP message length (header + all objects) | |
1706 | * @param payload pointer to the payload (i.e. the first object hdr) | |
1707 | * @param payload_s payload length or 0 | |
1708 | * @param l pointer to a libnet context | |
1709 | * @param ptag protocol tag to modify an existing header, 0 to build a new one | |
1710 | * @return protocol tag value on success, -1 on error | |
1711 | */ | |
1712 | libnet_ptag_t | |
1713 | libnet_build_rsvp(u_int8_t version, u_int8_t flags, u_int8_t type, int do_chksum, u_int16_t chksum, u_int8_t ttl, u_int16_t len, u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag); | |
1714 | ||
1715 | /** | |
1716 | * Writes a prebuilt packet to the network. The function assumes that l was | |
1717 | * previously initialized (via a call to libnet_init()) and that a | |
1718 | * previously constructed packet has been built inside this context (via one or | |
1719 | * more calls to the libnet_build* family of functions) and is ready to go. | |
1720 | * Depending on how libnet was initialized, the function will write the packet | |
1721 | * to the wire either via the raw or link layer interface. The function will | |
1722 | * also bump up the internal libnet stat counters which are retrievable via | |
1723 | * libnet_stats(). | |
1724 | * @param l pointer to a libnet context | |
1725 | * @return the number of bytes written, -1 on error | |
1726 | */ | |
1727 | int | |
1728 | libnet_write(libnet_t *l); | |
1729 | ||
1730 | /** | |
1731 | * Returns the IP address for the device libnet was initialized with. If | |
1732 | * libnet was initialized without a device (in raw socket mode) the function | |
1733 | * will attempt to find one. If the function fails and returns -1 a call to | |
1734 | * libnet_geterrror() will tell you why. | |
1735 | * @param l pointer to a libnet context | |
1736 | * @return a big endian IP address suitable for use in a libnet_build function or -1 | |
1737 | */ | |
1738 | ||
1739 | u_int32_t | |
1740 | libnet_get_ipaddr4(libnet_t *l); | |
1741 | ||
1742 | /** | |
1743 | * This function is not yet implemented under IPv6. | |
1744 | * @param l pointer to a libnet context | |
1745 | * @return well, nothing yet | |
1746 | */ | |
1747 | struct libnet_in6_addr | |
1748 | libnet_get_ipaddr6(libnet_t *l); | |
1749 | ||
1750 | /** | |
1751 | * Returns the MAC address for the device libnet was initialized with. If | |
1752 | * libnet was initialized without a device the function will attempt to find | |
1753 | * one. If the function fails and returns NULL a call to libnet_geterror() will | |
1754 | * tell you why. | |
1755 | * @param l pointer to a libnet context | |
1756 | * @return a pointer to the MAC address or NULL | |
1757 | */ | |
1758 | struct libnet_ether_addr * | |
1759 | libnet_get_hwaddr(libnet_t *l); | |
1760 | ||
1761 | /** | |
1762 | * Takes a colon separated hexidecimal address (from the command line) and | |
1763 | * returns a bytestring suitable for use in a libnet_build function. Note this | |
1764 | * function performs an implicit malloc and the return value should be freed | |
1765 | * after its use. | |
1766 | * @param s the string to be parsed | |
1767 | * @param len the resulting size of the returned byte string | |
1768 | * @return a byte string or NULL on failure | |
1769 | */ | |
1770 | u_int8_t * | |
1771 | libnet_hex_aton(int8_t *s, int *len); | |
1772 | ||
1773 | /** | |
1774 | * [Advanced Interface] | |
1775 | * Yanks a prebuilt, wire-ready packet from the given libnet context. If | |
1776 | * libnet was configured to do so (which it is by default) the packet will have | |
1777 | * all checksums written in. This function is part of the advanced interface | |
1778 | * and is only available when libnet is initialized in advanced mode. It is | |
1779 | * important to note that the function performs an implicit malloc() and a | |
1780 | * corresponding call to libnet_adv_free_packet() should be made to free the | |
1781 | * memory packet occupies. If the function fails libnet_geterror() can tell you | |
1782 | * why. | |
1783 | * @param l pointer to a libnet context | |
1784 | * @param packet will contain the wire-ready packet | |
1785 | * @param packet_s will contain the packet size | |
1786 | * @return 1 on success, -1 on failure | |
1787 | */ | |
1788 | int | |
1789 | libnet_adv_cull_packet(libnet_t *l, u_int8_t **packet, u_int32_t *packet_s); | |
1790 | ||
1791 | /** | |
1792 | * [Advanced Interface] | |
1793 | * Pulls the header from the specified ptag from the given libnet context. This | |
1794 | * function is part of the advanced interface and is only available when libnet | |
1795 | * is initialized in advanced mode. If the function fails libnet_geterror() can | |
1796 | * tell you why. | |
1797 | * @param l pointer to a libnet context | |
1798 | * @param ptag the ptag referencing the header to pull | |
1799 | * @param header will contain the header | |
1800 | * @param header_s will contain the header size | |
1801 | * @return 1 on success, -1 on failure | |
1802 | */ | |
1803 | int | |
1804 | libnet_adv_cull_header(libnet_t *l, libnet_ptag_t ptag, u_int8_t **header, | |
1805 | u_int32_t *header_s); | |
1806 | ||
1807 | /** | |
1808 | * [Advanced Interface] | |
1809 | * Writes a packet the network at the link layer. This function is useful to | |
1810 | * write a packet that has been constructed by hand by the application | |
1811 | * programmer or, more commonly, to write a packet that has been returned by | |
1812 | * a call to libnet_adv_cull_packet(). This function is part of the advanced | |
1813 | * interface and is only available when libnet is initialized in advanced mode. | |
1814 | * If the function fails libnet_geterror() can tell you why. | |
1815 | * @param l pointer to a libnet context | |
1816 | * @param packet a pointer to the packet to inject | |
1817 | * @param packet_s the size of the packet | |
1818 | * @return the number of bytes written, or -1 on failure | |
1819 | */ | |
1820 | int | |
1821 | libnet_adv_write_link(libnet_t *l, u_int8_t *packet, u_int32_t packet_s); | |
1822 | ||
1823 | /** | |
1824 | * [Advanced Interface] | |
1825 | * Frees the memory allocated when libnet_adv_cull_packet() is called. | |
1826 | * @param l pointer to a libnet context | |
1827 | * @param packet a pointer to the packet to free | |
1828 | */ | |
1829 | void | |
1830 | libnet_adv_free_packet(libnet_t *l, u_int8_t *packet); | |
1831 | ||
1832 | /** | |
1833 | * [Context Queue] | |
1834 | * Adds a new context to the libnet context queue. If no queue exists, this | |
1835 | * function will create the queue and add the specified libnet context as the | |
1836 | * first entry on the list. The functions checks to ensure niether l nor label | |
1837 | * are NULL, and that label doesn't refer to an existing context already in the | |
1838 | * queue. Additionally, l should refer to a libnet context previously | |
1839 | * initialized with a call to libnet_init(). If the context queue in write | |
1840 | * locked, this function will fail. | |
1841 | * @param l pointer to a libnet context | |
1842 | * @param label a canonical name given to recognize the new context, no longer than LIBNET_LABEL_SIZE | |
1843 | * @return 1 on success, -1 on failure | |
1844 | */ | |
1845 | int | |
1846 | libnet_cq_add(libnet_t *l, char *label); | |
1847 | ||
1848 | /** | |
1849 | * [Context Queue] | |
1850 | * Removes a specified context from the libnet context queue by specifying the | |
1851 | * libnet context pointer. Note the function will remove the specified context | |
1852 | * from the context queue and cleanup internal memory from the queue, it is up | |
1853 | * to the application programmer to free the returned libnet context with a | |
1854 | * call to libnet_destroy(). Also, as it is not necessary to keep the libnet | |
1855 | * context pointer when initially adding it to the context queue, most | |
1856 | * application programmers will prefer to refer to entries on the context | |
1857 | * queue by canonical name and would use libnet_cq_remove_by_label(). If the | |
1858 | * context queue is write locked, this function will fail. | |
1859 | * @param l pointer to a libnet context | |
1860 | * @return the pointer to the removed libnet context, NULL on failure | |
1861 | */ | |
1862 | libnet_t * | |
1863 | libnet_cq_remove(libnet_t *l); | |
1864 | ||
1865 | /** | |
1866 | * [Context Queue] | |
1867 | * Removes a specified context from the libnet context queue by specifying the | |
1868 | * canonical name. Note the function will remove the specified context from | |
1869 | * the context queue and cleanup internal memory from the queue, it is up to | |
1870 | * the application programmer to free the returned libnet context with a call | |
1871 | * to libnet_destroy(). If the context queue is write locked, this function | |
1872 | * will fail. | |
1873 | * @param label canonical name of the context to remove | |
1874 | * @return the pointer to the removed libnet context, NULL on failure | |
1875 | */ | |
1876 | libnet_t * | |
1877 | libnet_cq_remove_by_label(char *label); | |
1878 | ||
1879 | /** | |
1880 | * [Context Queue] | |
1881 | * Returns the canonical label associated with the context. | |
1882 | * @param l pointer to a libnet context | |
1883 | * @return pointer to the libnet context's label | |
1884 | */ | |
1885 | int8_t * | |
1886 | libnet_cq_getlabel(libnet_t *l); | |
1887 | ||
1888 | /** | |
1889 | * [Context Queue] | |
1890 | * Locates a libnet context from the queue, indexed by a canonical label. | |
1891 | * @param label canonical label of the libnet context to retrieve | |
1892 | * @return the expected libnet context, NULL on failure | |
1893 | */ | |
1894 | libnet_t * | |
1895 | libnet_cq_find_by_label(char *label); | |
1896 | ||
1897 | /** | |
1898 | * [Context Queue] | |
1899 | * Destroys the entire context queue, calling libnet_destroy() on each | |
1900 | * member context. | |
1901 | */ | |
1902 | void | |
1903 | libnet_cq_destroy(); | |
1904 | ||
1905 | /** | |
1906 | * [Context Queue] | |
1907 | * Intiailizes the interator interface and set a write lock on the entire | |
1908 | * queue. This function is intended to be called just prior to interating | |
1909 | * through the entire list of contexts (with the probable intent of inject a | |
1910 | * series of packets in rapid succession). This function is often used as | |
1911 | * per the following: | |
1912 | * | |
1913 | * for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) | |
1914 | * { | |
1915 | * ... | |
1916 | * } | |
1917 | * | |
1918 | * Much of the time, the application programmer will use the iterator as it is | |
1919 | * written above; as such, libnet provides a macro to do exactly that, | |
1920 | * for_each_context_in_cq(l). Warning: do not call the iterator more than once | |
1921 | * in a single loop. | |
1922 | * @return the head of the context queue | |
1923 | */ | |
1924 | libnet_t * | |
1925 | libnet_cq_head(); | |
1926 | ||
1927 | /** | |
1928 | * [Context Queue] | |
1929 | * Check whether the iterator is at the last context in the queue. | |
1930 | * @return 1 if at the end of the context queue, 0 otherwise | |
1931 | */ | |
1932 | int | |
1933 | libnet_cq_last(); | |
1934 | ||
1935 | /** | |
1936 | * [Context Queue] | |
1937 | * Get next context from the context queue. | |
1938 | * @reutrn the next context from the context queue | |
1939 | */ | |
1940 | libnet_t * | |
1941 | libnet_cq_next(); | |
1942 | ||
1943 | /** | |
1944 | * [Context Queue] | |
1945 | * Function returns the number of libnet contexts that are in the queue. | |
1946 | * @return the number of libnet contexts currently in the queue | |
1947 | */ | |
1948 | u_int32_t | |
1949 | libnet_cq_size(); | |
1950 | ||
1951 | /** | |
1952 | * [Diagnostic] | |
1953 | * Prints the contents of the given context. | |
1954 | * @param l pointer to a libnet context | |
1955 | */ | |
1956 | void | |
1957 | libnet_diag_dump_context(libnet_t *l); | |
1958 | ||
1959 | /** | |
1960 | * [Diagnostic] | |
1961 | * Prints the contents of every pblock. | |
1962 | * @param l pointer to a libnet context | |
1963 | */ | |
1964 | void | |
1965 | libnet_diag_dump_pblock(libnet_t *l); | |
1966 | ||
1967 | /** | |
1968 | * [Diagnostic] | |
1969 | * Returns the canonical name of the pblock type. | |
1970 | * @param type pblock type | |
1971 | * @return a string representing the pblock type type or "unknown" for an unknown value | |
1972 | */ | |
1973 | char * | |
1974 | libnet_diag_dump_pblock_type(u_int8_t type); | |
1975 | ||
1976 | /** | |
1977 | * [Diagnostic] | |
1978 | * Function prints the contents of the supplied buffer to the supplied | |
1979 | * stream pointer. Will swap endianness based disposition of mode variable. | |
1980 | * Useful to be used in conjunction with the advanced interface and a culled | |
1981 | * packet. | |
1982 | * @param packet the packet to print | |
1983 | * @param len length of the packet in bytes | |
1984 | * @param swap 1 to swap byte order, 0 to not | |
1985 | * @param stream a stream pointer to print to | |
1986 | */ | |
1987 | void | |
1988 | libnet_diag_dump_hex(u_int8_t *packet, u_int32_t len, int swap, FILE *stream); | |
1989 | ||
1990 | /* | |
1991 | * [Internal] | |
1992 | */ | |
1993 | int | |
1994 | libnet_write_raw_ipv4(libnet_t *l, u_int8_t *packet, u_int32_t size); | |
1995 | ||
1996 | /* | |
1997 | * [Internal] | |
1998 | */ | |
1999 | int | |
2000 | libnet_write_raw_ipv6(libnet_t *l, u_int8_t *packet, u_int32_t size); | |
2001 | ||
2002 | /* | |
2003 | * [Internal] | |
2004 | */ | |
2005 | int | |
2006 | libnet_write_link(libnet_t *l, u_int8_t *packet, u_int32_t size); | |
2007 | ||
2008 | #if ((__WIN32__) && !(__CYGWIN__)) | |
2009 | /* | |
2010 | * [Internal] | |
2011 | */ | |
2012 | SOCKET | |
2013 | libnet_open_raw4(libnet_t *l); | |
2014 | #else | |
2015 | /* | |
2016 | * [Internal] | |
2017 | */ | |
2018 | int | |
2019 | libnet_open_raw4(libnet_t *l); | |
2020 | #endif | |
2021 | ||
2022 | /* | |
2023 | * [Internal] | |
2024 | */ | |
2025 | int | |
2026 | libnet_close_raw4(libnet_t *l); | |
2027 | ||
2028 | /* | |
2029 | * [Internal] | |
2030 | */ | |
2031 | int | |
2032 | libnet_open_raw6(libnet_t *l); | |
2033 | ||
2034 | /* | |
2035 | * [Internal] | |
2036 | */ | |
2037 | int | |
2038 | libnet_close_raw6(libnet_t *l); | |
2039 | ||
2040 | /* | |
2041 | * [Internal] | |
2042 | */ | |
2043 | int | |
2044 | libnet_select_device(libnet_t *l); | |
2045 | ||
2046 | /* | |
2047 | * [Internal] | |
2048 | */ | |
2049 | int | |
2050 | libnet_open_link(libnet_t *l); | |
2051 | ||
2052 | /* | |
2053 | * [Internal] | |
2054 | */ | |
2055 | int | |
2056 | libnet_close_link(libnet_t *l); | |
2057 | ||
2058 | /* | |
2059 | * [Internal] | |
2060 | */ | |
2061 | int | |
2062 | libnet_do_checksum(libnet_t *l, u_int8_t *packet, int protocol, int len); | |
2063 | ||
2064 | /* | |
2065 | * [Internal] | |
2066 | */ | |
2067 | u_int32_t | |
2068 | libnet_compute_crc(u_int8_t *buf, u_int32_t len); | |
2069 | ||
2070 | /* | |
2071 | * [Internal] | |
2072 | */ | |
2073 | u_int16_t | |
2074 | libnet_ip_check(u_int16_t *addr, int len); | |
2075 | ||
2076 | /* | |
2077 | * [Internal] | |
2078 | */ | |
2079 | int | |
2080 | libnet_in_cksum(u_int16_t *addr, int len); | |
2081 | ||
2082 | /* | |
2083 | * [Internal] | |
2084 | * If ptag is 0, function will create a pblock for the protocol unit type, | |
2085 | * append it to the list and return a pointer to it. If ptag is not 0, | |
2086 | * function will search the pblock list for the specified protocol block | |
2087 | * and return a pointer to it. | |
2088 | */ | |
2089 | libnet_pblock_t * | |
2090 | libnet_pblock_probe(libnet_t *l, libnet_ptag_t ptag, u_int32_t n, | |
2091 | u_int8_t type); | |
2092 | ||
2093 | /* | |
2094 | * [Internal] | |
2095 | * Function creates the pblock list if l->protocol_blocks == NULL or appends | |
2096 | * an entry to the doubly linked list. | |
2097 | */ | |
2098 | libnet_pblock_t * | |
2099 | libnet_pblock_new(libnet_t *l, u_int32_t size); | |
2100 | ||
2101 | /* | |
2102 | * [Internal] | |
2103 | * Function swaps two pblocks in memory. | |
2104 | */ | |
2105 | int | |
2106 | libnet_pblock_swap(libnet_t *l, libnet_ptag_t ptag1, libnet_ptag_t ptag2); | |
2107 | ||
2108 | /* | |
2109 | * [Internal] | |
2110 | * Function inserts a pblock into the doubly linked list. | |
2111 | */ | |
2112 | int | |
2113 | libnet_pblock_insert_before(libnet_t *l, libnet_ptag_t ptag1, | |
2114 | libnet_ptag_t ptag2); | |
2115 | ||
2116 | /* | |
2117 | * [Internal] | |
2118 | * Function removes a pblock from context | |
2119 | */ | |
2120 | void | |
2121 | libnet_pblock_delete(libnet_t *l, libnet_pblock_t *p); | |
2122 | ||
2123 | /* | |
2124 | * [Internal] | |
2125 | * Function updates the pblock meta-inforation. Internally it updates the | |
2126 | * ptag with a monotonically increasing variable kept in l. This way each | |
2127 | * pblock has a succesively increasing ptag identifier. | |
2128 | */ | |
2129 | libnet_ptag_t | |
2130 | libnet_pblock_update(libnet_t *l, libnet_pblock_t *p, u_int32_t h, | |
2131 | u_int8_t type); | |
2132 | ||
2133 | ||
2134 | /* | |
2135 | * [Internal] | |
2136 | * Checksums are a real pain in the <beep>!!! | |
2137 | * Function updates referer used to compute the checksum. All | |
2138 | * pblock need to know where is their referer (ie IP header). | |
2139 | * So, this function is called each time a new IP header is inserted. | |
2140 | * It updates the ip_pos field (referer) of each subsequent pblock. | |
2141 | */ | |
2142 | void | |
2143 | libnet_pblock_record_ip_offset(libnet_t *l, u_int32_t offset); | |
2144 | ||
2145 | /* | |
2146 | * [Internal] | |
2147 | * Function locates a given block by it's ptag. | |
2148 | */ | |
2149 | libnet_pblock_t * | |
2150 | libnet_pblock_find(libnet_t *l, libnet_ptag_t ptag); | |
2151 | ||
2152 | /* | |
2153 | * [Internal] | |
2154 | * Function copies protocol block data over. | |
2155 | */ | |
2156 | int | |
2157 | libnet_pblock_append(libnet_t *l, libnet_pblock_t *p, u_int8_t *buf, | |
2158 | u_int32_t len); | |
2159 | ||
2160 | /* | |
2161 | * [Internal] | |
2162 | * Function sets pblock flags. | |
2163 | */ | |
2164 | void | |
2165 | libnet_pblock_setflags(libnet_pblock_t *p, u_int8_t flags); | |
2166 | ||
2167 | /* | |
2168 | * [Internal] | |
2169 | * Function returns the protocol number for the protocol block type. If | |
2170 | * the type is unknown, the function defaults to returning IPPROTO_IP. | |
2171 | */ | |
2172 | int | |
2173 | libnet_pblock_p2p(u_int8_t type); | |
2174 | ||
2175 | /* | |
2176 | * [Internal] | |
2177 | * Function assembles the packet for subsequent writing. Function makes two | |
2178 | * passes through the pblock list: | |
2179 | */ | |
2180 | int | |
2181 | libnet_pblock_coalesce(libnet_t *l, u_int8_t **packet, u_int32_t *size); | |
2182 | ||
2183 | #if !(__WIN32__) | |
2184 | /* | |
2185 | * [Internal] | |
2186 | * By testing if we can retrieve the FLAGS of an iface | |
2187 | * we can know if it exists or not and if it is up. | |
2188 | */ | |
2189 | int | |
2190 | libnet_check_iface(libnet_t *l); | |
2191 | #endif | |
2192 | ||
2193 | #if defined(__WIN32__) | |
2194 | /* | |
2195 | * [Internal] | |
2196 | */ | |
2197 | BYTE * | |
2198 | libnet_win32_get_remote_mac(libnet_t *l, DWORD IP); | |
2199 | ||
2200 | /* | |
2201 | * [Internal] | |
2202 | */ | |
2203 | int | |
2204 | libnet_close_link_interface(libnet_t *l); | |
2205 | ||
2206 | /* | |
2207 | * [Internal] | |
2208 | */ | |
2209 | BYTE * | |
2210 | libnet_win32_read_arp_table(DWORD IP); | |
2211 | #endif | |
2212 | #endif /* __LIBNET_FUNCTIONS_H */ | |
2213 | ||
2214 | /* EOF */ |