2 * $Id: libnet-functions.h,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
4 * libnet-functions.h - Network routine library function prototype header file
6 * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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
32 #ifndef __LIBNET_FUNCTIONS_H
33 #define __LIBNET_FUNCTIONS_H
36 int /* 1 if good, -1 if bad */
37 libnet_plist_chain_new(
38 struct libnet_plist_chain **, /* pointer to the head of the list */
39 char * /* token list pointer */
43 int /* 1 if more nodes, 0 if not */
44 libnet_plist_chain_next_pair(
45 struct libnet_plist_chain *, /* pointer to the head of the list */
46 u_short *, /* holds bport */
47 u_short * /* holds eport */
52 libnet_plist_chain_dump(
53 struct libnet_plist_chain * /* pointer to the head of the list */
58 libnet_plist_chain_dump_string(
59 struct libnet_plist_chain * /* pointer to the head of the list */
64 libnet_plist_chain_free(
65 struct libnet_plist_chain * /* pointer to the head of the list */
69 * Standard error handling code.
75 char *, /* error message */
81 * Seeds the pseudorandom number generator with gettimeofday.
89 * Returns a psuedorandom positive integer.
94 int /* One of the PR* constants */
99 * Calculates IPv4 family checksum on packet headers.
102 int /* 1 on success, -1 on failure */
104 u_char *, /* Pointer to the packet buffer */
106 int /* Packet size */
111 * Network byte order into IP address
112 * Previous versions had a memory leak (returned a strdup'd pointer -- strdup
113 * has an implicit malloc which wasn't getting freed). This static var hack
114 * thingy was used to preserve existing code without having to change much.
115 * You can simply use the return value of the function directly allowing you
116 * to write tighter, more obvious code (rather then having to do allocate an
117 * additional buffer for the output).
118 * Thanks to Red for the idea.
121 u_char * /* Pointer to hostname or dotted decimal IP address */
123 u_long, /* Network byte ordered (big endian) IP address */
124 u_short /* Use domain names or no */
129 * Network byte order into IP address
130 * Threadsafe version.
134 libnet_host_lookup_r(
135 u_long, /* Network byte ordered (big endian) IP address */
136 u_short, /* Use domain names or no */
137 u_char * /* Pointer to hostname or dotted decimal IP address */
142 * IP address into network byte order
145 u_long /* Network byte ordered IP address or -1 on error */
147 u_char *, /* Pointer the hostname or dotted decimal IP address */
148 u_short /* Use domain names or no */
153 * IP checksum wrapper.
156 u_short /* Standard IP checksum of header and data */
158 u_short *, /* Pointer to the buffer to be summed */
159 int /* Packet length */
167 int /* Standard IP checksum */
169 u_short *, /* Pointer to the buffer to be summed */
170 int /* Packet length */
175 * Opens a socket for writing raw IP datagrams to. Set IP_HDRINCL to let the
176 * kernel know we've got it all under control.
179 int /* Opened file desciptor, or -1 on error */
180 libnet_open_raw_sock(
181 int /* Protocol of raw socket (from /etc/protocols) */
185 int /* 1 upon success, or -1 on error */
186 libnet_close_raw_sock(
187 int /* File descriptor */
192 libnet_select_device(
193 struct sockaddr_in *,
199 * Ethernet packet assembler.
202 int /* -1 on failure (null buf passed in), 1 on success */
203 libnet_build_ethernet(
204 u_char *, /* Pointer to a 6 byte ethernet address */
205 u_char *, /* Pointer to a 6 byte ethernet address */
206 u_short, /* Packet IP type */
207 const u_char *, /* Payload (or NULL) */
208 int, /* Payload size */
209 u_char * /* Packet header buffer */
214 * ARP packet assembler.
217 int /* -1 on failure (null buf passed in), 1 on success */
219 u_short, /* hardware address type */
220 u_short, /* protocol address type */
221 u_char, /* hardware address length */
222 u_char, /* protocol address length */
223 u_short, /* ARP operation type */
224 u_char *, /* sender hardware address */
225 u_char *, /* sender protocol address */
226 u_char *, /* target hardware address */
227 u_char *, /* target protocol address */
228 const u_char *, /* payload or NULL if none */
229 int, /* payload length */
230 u_char * /* packet buffer memory */
234 * TCP packet assembler.
237 int /* -1 on failure (null buf passed in), 1 on success */
239 u_short, /* Source port */
240 u_short, /* Destination port */
241 u_long, /* Sequence Number */
242 u_long, /* Acknowledgement Number */
243 u_char, /* Control bits */
244 u_short, /* Advertised Window Size */
245 u_short, /* Urgent Pointer */
246 const u_char *, /* Pointer to packet data (or NULL) */
247 int, /* Packet payload size */
248 u_char * /* Pointer to packet header memory */
253 * UDP packet assembler.
256 int /* -1 on failure (null buf passed in), 1 on success */
258 u_short, /* Source port */
259 u_short, /* Destination port */
260 const u_char *, /* Pointer to packet data (or NULL) */
261 int, /* Packet payload size */
262 u_char * /* Pointer to packet header memory */
266 * ICMP_ECHO packet assembler.
269 int /* -1 on failure (null buf passed in), 1 on success */
270 libnet_build_icmp_echo(
271 u_char, /* icmp type */
272 u_char, /* icmp code */
274 u_short, /* sequence number */
275 const u_char *, /* Pointer to packet data (or NULL) */
276 int, /* Packet payload size */
277 u_char * /* Pointer to packet header memory */
281 * ICMP_MASK packet assembler.
284 int /* -1 on failure (null buf passed in), 1 on success */
285 libnet_build_icmp_mask(
286 u_char, /* icmp type */
287 u_char, /* icmp code */
289 u_short, /* sequence number */
290 u_long, /* address mask */
291 const u_char *, /* Pointer to packet data (or NULL) */
292 int, /* Packet payload size */
293 u_char * /* Pointer to packet header memory */
298 * ICMP_UNREACH packet assembler.
301 int /* -1 on failure (null buf passed in), 1 on success */
302 libnet_build_icmp_unreach(
303 u_char, /* icmp type */
304 u_char, /* icmp code */
305 u_short, /* Original Length of packet data */
306 u_char, /* Original IP tos */
307 u_short, /* Original IP ID */
308 u_short, /* Original Fragmentation flags and offset */
309 u_char, /* Original TTL */
310 u_char, /* Original Protocol */
311 u_long, /* Original Source IP Address */
312 u_long, /* Original Destination IP Address */
313 const u_char *, /* Pointer to original packet data (or NULL) */
314 int, /* Packet payload size (or 0) */
315 u_char * /* Pointer to packet header memory */
319 * ICMP_REDIRECT packet assembler.
322 int /* -1 on failure (null buf passed in), 1 on success */
323 libnet_build_icmp_redirect(
324 u_char, /* icmp type */
325 u_char, /* icmp code */
326 u_long, /* Gateway host that should be used */
327 u_short, /* Original Length of packet data */
328 u_char, /* Original IP tos */
329 u_short, /* Original IP ID */
330 u_short, /* Original Fragmentation flags and offset */
331 u_char, /* Original TTL */
332 u_char, /* Original Protocol */
333 u_long, /* Original Source IP Address */
334 u_long, /* Original Destination IP Address */
335 const u_char *, /* Pointer to original packet data (or NULL) */
336 int, /* Packet payload size (or 0) */
337 u_char * /* Pointer to packet header memory */
342 * ICMP_TIMXCEED packet assembler.
345 int /* -1 on failure (null buf passed in), 1 on success */
346 libnet_build_icmp_timeexceed(
347 u_char, /* icmp type */
348 u_char, /* icmp code */
349 u_short, /* Original Length of packet data */
350 u_char, /* Original IP tos */
351 u_short, /* Original IP ID */
352 u_short, /* Original Fragmentation flags and offset */
353 u_char, /* Original TTL */
354 u_char, /* Original Protocol */
355 u_long, /* Original Source IP Address */
356 u_long, /* Original Destination IP Address */
357 const u_char *, /* Pointer to original packet data (or NULL) */
358 int, /* Packet payload size (or 0) */
359 u_char * /* Pointer to packet header memory */
363 * ICMP_TIMESTAMP packet assembler.
366 int /* -1 on failure (null buf passed in), 1 on success */
367 libnet_build_icmp_timestamp(
368 u_char, /* icmp type */
369 u_char, /* icmp code */
371 u_short, /* sequence number */
372 n_time, /* original timestamp */
373 n_time, /* receive timestamp */
374 n_time, /* transmit timestamp */
375 const u_char *, /* Pointer to packet data (or NULL) */
376 int, /* Packet payload size */
377 u_char * /* Pointer to packet header memory */
381 * IGMP packet assembler.
384 int /* -1 on failure (null buf passed in), 1 on success */
386 u_char, /* igmp type */
387 u_char, /* igmp code */
388 u_long, /* ip addr */
389 const u_char *, /* Pointer to packet data (or NULL) */
390 int, /* Packet payload size */
391 u_char * /* Pointer to packet header memory */
396 * IPv4 packet assembler.
399 int /* -1 on failure (null buf passed in), 1 on success */
401 u_short, /* Length of packet data */
404 u_short, /* Fragmentation flags and offset */
406 u_char, /* Protocol */
407 u_long, /* Source IP Address */
408 u_long, /* Destination IP Address */
409 const u_char *, /* Pointer to packet data (or NULL) */
410 int, /* Packet payload size */
411 u_char * /* Pointer to packet header memory */
414 int /* -1 on failure (null buf passed in), 1 on success */
416 u_short, /* Length of packet data */
419 u_short, /* Fragmentation flags and offset */
421 u_char, /* Protocol */
422 u_long, /* Source IP Address */
423 u_long, /* Destination IP Address */
424 const u_char *, /* Pointer to packet data (or NULL) */
425 int, /* Packet payload size */
426 u_char * /* Pointer to packet header memory */
431 * DNS pacekt assembler.
434 int /* -1 on failure (null buf passed in), 1 on success */
436 u_short, /* Packet ID */
438 u_short, /* Number of questions */
439 u_short, /* Number of answer resource records */
440 u_short, /* Number of authority resource records */
441 u_short, /* Number of additional resource records */
442 const u_char *, /* Payload (or NULL) */
443 int, /* Payload size */
444 u_char * /* Header memory */
449 * RIP packet assembler.
452 int /* -1 on failure (null buf passed in), 1 on success */
454 u_char, /* Command */
455 u_char, /* Version */
456 u_short, /* Zero (v1) or Routing Domain (v2) */
457 u_short, /* Address family */
458 u_short, /* Zero (v1) or Route Tag (v2) */
459 u_long, /* IP address */
460 u_long, /* Zero (v1) or Subnet Mask (v2) */
461 u_long, /* Zero (v1) or Next hop IP address (v2) */
463 const u_char *, /* Payload (or NULL) */
464 int, /* Payload size */
465 u_char * /* Header memory */
470 * VRRP packet assembler.
473 int /* -1 on failure (null buf passed in), 1 on success */
480 const u_char *, /* Payload (or NULL) */
481 int, /* Payload size */
482 u_char * /* Header memory */
486 libnet_init_vrrp_packet(size_t,
492 * Insert IP options to a prebuilt IP packet.
495 int /* 1 on success, -1 on failure */
497 struct ipoption *, /* Pointer to the ip options structure */
498 u_char, /* IP option list size */
499 u_char * /* Pointer to packet buf */
503 * Insert TCP options to a prebuilt IP packet.
506 int /* 1 on success, -1 on failure */
508 struct tcpoption *, /* Pointer to the tcp options structure */
509 u_char, /* TCP option list size */
510 u_char * /* Pointer to packet buf */
514 * Writes a prebuild IP packet to the network with a supplied raw socket.
515 * To write a link layer packet, use the write_link_layer function.
518 int /* number of bytes written if successful, -1 on error */
520 int sock, /* Previously opened raw socket */
521 u_char *, /* Pointer a complete IP datagram */
522 int /* Packet size */
526 * Writes a prebuild IP/ethernet packet to the network with a supplied
527 * link_layer interface. To write just an IP packet, use the write_link_layer
531 int /* number of bytes written if successful, -1 on error */
532 libnet_write_link_layer(
533 struct libnet_link_int *, /* Pointer to a link interface structure */
534 const char *, /* Pointer to the device */
535 u_char *, /* Pointer the u_char buf (the packet)to be written */
536 int /* Packet length */
541 * Opens a link layer interface. Analogous to open_raw_sock.
544 struct libnet_link_int * /* Pointer to a link layer interface struct */
545 libnet_open_link_interface(
546 char *, /* Device name */
547 char * /* Error buffer */
551 int /* 1 on success, -1 on failure */
552 libnet_close_link_interface(
553 struct libnet_link_int * /* Pointer to a link layer interface struct */
557 char * /* String error message */
564 * Returns the IP address of the interface.
567 u_long /* 0 upon error, address upon success */
569 struct libnet_link_int *, /* Pointer to a link interface structure */
570 const char *, /* Device */
571 char * /* Error buf */
576 * Returns the MAC address of the interface.
579 struct ether_addr * /* 0 upon error, address upon success */
581 struct libnet_link_int *, /* Pointer to a link interface structure */
582 const char *, /* Device */
583 char * /* Error buf */
588 * Simple interface for initializing a packet.
589 * Basically a malloc wrapper.
592 int /* -1 on error, 1 on ok */
594 int, /* 0 and we make a good guess, otherwise you choose. */
595 u_char ** /* Pointer to the pointer to the packet */
600 * Simple interface for destoying a packet.
601 * Don't call this without a corresponding call to init_packet() first.
604 int /* -1 if arena is NULL, 1 if ok */
605 libnet_destroy_packet(
606 u_char ** /* Pointer to the packet addr. */
611 * Memory pool initialization routine.
615 libnet_init_packet_arena(
616 struct libnet_arena **, /* Pointer to an arena pointer */
617 int, /* 0 and we make a good guess, otherwise you choose. */
623 * Returns the next chunk of memory from the pool.
627 libnet_next_packet_from_arena(
628 struct libnet_arena **, /* Pointer to an arena pointer */
629 int /* 0 and we make a good guess, otherwise you choose. */
634 * Memory pool destructor routine.
637 int /* -1 if arena is NULL, 1 if ok */
638 libnet_destroy_packet_arena(
639 struct libnet_arena ** /* Pointer to an arena pointer */
644 * More or less taken from tcpdump code.
649 u_char *, /* Packet to be dumped */
650 int, /* Packet size (in bytes */
651 int, /* To swap or not to swap */
652 FILE * /* Stream pointer to dump to */
656 #endif /* __LIBNET_FUNCTIONS_H */