M7350v7_en_gpl

This commit is contained in:
T
2024-09-09 08:59:52 +00:00
parent f75098198c
commit 46ba6f09ec
1372 changed files with 1231198 additions and 1184 deletions

View File

@ -0,0 +1,251 @@
/*
* $Id: libnet-asn1.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-asn1.h - Network routine library ASN.1 header file
*
* Definitions for Abstract Syntax Notation One, ASN.1
* As defined in ISO/IS 8824 and ISO/IS 8825
*
* Copyright 1988, 1989 by Carnegie Mellon University
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of CMU not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
*
* CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
* CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
* ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __LIBNET_ASN1_H
#define __LIBNET_ASN1_H
#ifndef EIGHTBIT_SUBIDS
typedef u_long oid;
#define MAX_SUBID 0xFFFFFFFF
#else
typedef u_char oid;
#define MAX_SUBID 0xFF
#endif
#define MAX_OID_LEN 64 /* max subid's in an oid */
#define ASN_BOOLEAN (0x01)
#define ASN_INTEGER (0x02)
#define ASN_BIT_STR (0x03)
#define ASN_OCTET_STR (0x04)
#define ASN_NULL (0x05)
#define ASN_OBJECT_ID (0x06)
#define ASN_SEQUENCE (0x10)
#define ASN_SET (0x11)
#define ASN_UNIVERSAL (0x00)
#define ASN_APPLICATION (0x40)
#define ASN_CONTEXT (0x80)
#define ASN_PRIVATE (0xC0)
#define ASN_PRIMITIVE (0x00)
#define ASN_CONSTRUCTOR (0x20)
#define ASN_LONG_LEN (0x80)
#define ASN_EXTENSION_ID (0x1F)
#define ASN_BIT8 (0x80)
#define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR)
#define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) = ASN_EXTENSION_ID)
/*
* All of the build_asn1_* (build_asn1_length being an exception) functions
* take the same first 3 arguments:
*
* u_char *data: This is a pointer to the start of the data object to be
* manipulated.
* int *datalen: This is a pointer to the number of valid bytes following
* "data". This should be not be exceeded in any function.
* Upon exiting a function, this value will reflect the
* changed "data" and then refer to the new number of valid
* bytes until the end of "data".
* u_char type: The ASN.1 object type.
*/
/*
* Builds an ASN object containing an integer.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_int(
u_char *, /* Pointer to the output buffer */
int *, /* Number of valid bytes left in the buffer */
u_char, /* ASN object type */
long *, /* Pointer to a long integer */
int /* Size of a long integer */
);
/*
* Builds an ASN object containing an unsigned integer.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_uint(
u_char *, /* Pointer to the output buffer */
int *, /* Number of valid bytes left in the buffer */
u_char, /* ASN object type */
u_long *, /* Pointer to an unsigned long integer */
int /* Size of a long integer */
);
/*
* Builds an ASN object containing an octect string.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_string(
u_char *, /* Pointer to the output buffer */
int *, /* Number of valid bytes left in the buffer */
u_char, /* ASN object type */
u_char *, /* Pointer to a string to be built into an object */
int /* Size of the string */
);
/*
* Builds an ASN header for an object with the ID and length specified. This
* only works on data types < 30, i.e. no extension octets. The maximum
* length is 0xFFFF;
*
* Returns a pointer to the first byte of the contents of this object or
* NULL upon error
*/
u_char *
libnet_build_asn1_header(
u_char *, /* Pointer to the start of the object */
int *, /* Number of valid bytes left in buffer */
u_char, /* ASN object type */
int /* ASN object length */
);
u_char *
libnet_build_asn1_length(
u_char *, /* Pointer to start of object */
int *, /* Number of valid bytes in buffer */
int /* Length of object */
);
/*
* Builds an ASN header for a sequence with the ID and length specified.
*
* This only works on data types < 30, i.e. no extension octets.
* The maximum length is 0xFFFF;
*
* Returns a pointer to the first byte of the contents of this object.
* Returns NULL on any error.
*/
u_char *
libnet_build_asn1_sequence(
u_char *,
int *,
u_char,
int
);
/*
* Builds an ASN object identifier object containing the input string.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_objid(
u_char *,
int *,
u_char,
oid *,
int
);
/*
* Builds an ASN null object.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_null(
u_char *,
int *,
u_char
);
/*
* Builds an ASN bitstring.
*
* Returns NULL upon error or a pointer to the first byte past the end of
* this object (the start of the next object).
*/
u_char *
libnet_build_asn1_bitstring(
u_char *,
int *,
u_char,
u_char *, /* Pointer to the input buffer */
int /* Length of the input buffer */
);
#endif /* __LIBNET_ASN1_H */
/* EOF */

View File

@ -0,0 +1,658 @@
/*
* $Id: libnet-functions.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-functions.h - Network routine library function prototype header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_FUNCTIONS_H
#define __LIBNET_FUNCTIONS_H
int /* 1 if good, -1 if bad */
libnet_plist_chain_new(
struct libnet_plist_chain **, /* pointer to the head of the list */
char * /* token list pointer */
);
int /* 1 if more nodes, 0 if not */
libnet_plist_chain_next_pair(
struct libnet_plist_chain *, /* pointer to the head of the list */
u_short *, /* holds bport */
u_short * /* holds eport */
);
int
libnet_plist_chain_dump(
struct libnet_plist_chain * /* pointer to the head of the list */
);
u_char *
libnet_plist_chain_dump_string(
struct libnet_plist_chain * /* pointer to the head of the list */
);
int
libnet_plist_chain_free(
struct libnet_plist_chain * /* pointer to the head of the list */
);
/*
* Standard error handling code.
*/
void
libnet_error(
int, /* severity */
char *, /* error message */
... /* varargs */
);
/*
* Seeds the pseudorandom number generator with gettimeofday.
*/
int
libnet_seed_prand();
/*
* Returns a psuedorandom positive integer.
*/
u_long
libnet_get_prand(
int /* One of the PR* constants */
);
/*
* Calculates IPv4 family checksum on packet headers.
*/
int /* 1 on success, -1 on failure */
libnet_do_checksum(
u_char *, /* Pointer to the packet buffer */
int, /* Protocol */
int /* Packet size */
);
/*
* Network byte order into IP address
* Previous versions had a memory leak (returned a strdup'd pointer -- strdup
* has an implicit malloc which wasn't getting freed). This static var hack
* thingy was used to preserve existing code without having to change much.
* You can simply use the return value of the function directly allowing you
* to write tighter, more obvious code (rather then having to do allocate an
* additional buffer for the output).
* Thanks to Red for the idea.
*/
u_char * /* Pointer to hostname or dotted decimal IP address */
libnet_host_lookup(
u_long, /* Network byte ordered (big endian) IP address */
u_short /* Use domain names or no */
);
/*
* Network byte order into IP address
* Threadsafe version.
*/
void
libnet_host_lookup_r(
u_long, /* Network byte ordered (big endian) IP address */
u_short, /* Use domain names or no */
u_char * /* Pointer to hostname or dotted decimal IP address */
);
/*
* IP address into network byte order
*/
u_long /* Network byte ordered IP address or -1 on error */
libnet_name_resolve(
u_char *, /* Pointer the hostname or dotted decimal IP address */
u_short /* Use domain names or no */
);
/*
* IP checksum wrapper.
*/
u_short /* Standard IP checksum of header and data */
libnet_ip_check(
u_short *, /* Pointer to the buffer to be summed */
int /* Packet length */
);
/*
* IP checksum.
*/
int /* Standard IP checksum */
libnet_in_cksum(
u_short *, /* Pointer to the buffer to be summed */
int /* Packet length */
);
/*
* Opens a socket for writing raw IP datagrams to. Set IP_HDRINCL to let the
* kernel know we've got it all under control.
*/
int /* Opened file desciptor, or -1 on error */
libnet_open_raw_sock(
int /* Protocol of raw socket (from /etc/protocols) */
);
int /* 1 upon success, or -1 on error */
libnet_close_raw_sock(
int /* File descriptor */
);
int
libnet_select_device(
struct sockaddr_in *,
char **,
char *
);
/*
* Ethernet packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_ethernet(
u_char *, /* Pointer to a 6 byte ethernet address */
u_char *, /* Pointer to a 6 byte ethernet address */
u_short, /* Packet IP type */
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Packet header buffer */
);
/*
* ARP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_arp(
u_short, /* hardware address type */
u_short, /* protocol address type */
u_char, /* hardware address length */
u_char, /* protocol address length */
u_short, /* ARP operation type */
u_char *, /* sender hardware address */
u_char *, /* sender protocol address */
u_char *, /* target hardware address */
u_char *, /* target protocol address */
const u_char *, /* payload or NULL if none */
int, /* payload length */
u_char * /* packet buffer memory */
);
/*
* TCP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_tcp(
u_short, /* Source port */
u_short, /* Destination port */
u_long, /* Sequence Number */
u_long, /* Acknowledgement Number */
u_char, /* Control bits */
u_short, /* Advertised Window Size */
u_short, /* Urgent Pointer */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* UDP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_udp(
u_short, /* Source port */
u_short, /* Destination port */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_ECHO packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_echo(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* id */
u_short, /* sequence number */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_MASK packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_mask(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* id */
u_short, /* sequence number */
u_long, /* address mask */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_UNREACH packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_unreach(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* Original Length of packet data */
u_char, /* Original IP tos */
u_short, /* Original IP ID */
u_short, /* Original Fragmentation flags and offset */
u_char, /* Original TTL */
u_char, /* Original Protocol */
u_long, /* Original Source IP Address */
u_long, /* Original Destination IP Address */
const u_char *, /* Pointer to original packet data (or NULL) */
int, /* Packet payload size (or 0) */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_REDIRECT packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_redirect(
u_char, /* icmp type */
u_char, /* icmp code */
u_long, /* Gateway host that should be used */
u_short, /* Original Length of packet data */
u_char, /* Original IP tos */
u_short, /* Original IP ID */
u_short, /* Original Fragmentation flags and offset */
u_char, /* Original TTL */
u_char, /* Original Protocol */
u_long, /* Original Source IP Address */
u_long, /* Original Destination IP Address */
const u_char *, /* Pointer to original packet data (or NULL) */
int, /* Packet payload size (or 0) */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_TIMXCEED packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_timeexceed(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* Original Length of packet data */
u_char, /* Original IP tos */
u_short, /* Original IP ID */
u_short, /* Original Fragmentation flags and offset */
u_char, /* Original TTL */
u_char, /* Original Protocol */
u_long, /* Original Source IP Address */
u_long, /* Original Destination IP Address */
const u_char *, /* Pointer to original packet data (or NULL) */
int, /* Packet payload size (or 0) */
u_char * /* Pointer to packet header memory */
);
/*
* ICMP_TIMESTAMP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_icmp_timestamp(
u_char, /* icmp type */
u_char, /* icmp code */
u_short, /* id */
u_short, /* sequence number */
n_time, /* original timestamp */
n_time, /* receive timestamp */
n_time, /* transmit timestamp */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* IGMP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_igmp(
u_char, /* igmp type */
u_char, /* igmp code */
u_long, /* ip addr */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* IPv4 packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_ip(
u_short, /* Length of packet data */
u_char, /* IP tos */
u_short, /* IP ID */
u_short, /* Fragmentation flags and offset */
u_char, /* TTL */
u_char, /* Protocol */
u_long, /* Source IP Address */
u_long, /* Destination IP Address */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_ipv4(
u_short, /* Length of packet data */
u_char, /* IP tos */
u_short, /* IP ID */
u_short, /* Fragmentation flags and offset */
u_char, /* TTL */
u_char, /* Protocol */
u_long, /* Source IP Address */
u_long, /* Destination IP Address */
const u_char *, /* Pointer to packet data (or NULL) */
int, /* Packet payload size */
u_char * /* Pointer to packet header memory */
);
/*
* DNS pacekt assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_dns(
u_short, /* Packet ID */
u_short, /* Flags */
u_short, /* Number of questions */
u_short, /* Number of answer resource records */
u_short, /* Number of authority resource records */
u_short, /* Number of additional resource records */
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Header memory */
);
/*
* RIP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_rip(
u_char, /* Command */
u_char, /* Version */
u_short, /* Zero (v1) or Routing Domain (v2) */
u_short, /* Address family */
u_short, /* Zero (v1) or Route Tag (v2) */
u_long, /* IP address */
u_long, /* Zero (v1) or Subnet Mask (v2) */
u_long, /* Zero (v1) or Next hop IP address (v2) */
u_long, /* Metric */
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Header memory */
);
/*
* VRRP packet assembler.
*/
int /* -1 on failure (null buf passed in), 1 on success */
libnet_build_vrrp(
u_char,
u_char,
u_char,
u_char,
u_char,
const u_char *, /* Payload (or NULL) */
int, /* Payload size */
u_char * /* Header memory */
);
int
libnet_init_vrrp_packet(size_t,
u_char **,
u_char
);
/*
* Insert IP options to a prebuilt IP packet.
*/
int /* 1 on success, -1 on failure */
libnet_insert_ipo(
struct ipoption *, /* Pointer to the ip options structure */
u_char, /* IP option list size */
u_char * /* Pointer to packet buf */
);
/*
* Insert TCP options to a prebuilt IP packet.
*/
int /* 1 on success, -1 on failure */
libnet_insert_tcpo(
struct tcpoption *, /* Pointer to the tcp options structure */
u_char, /* TCP option list size */
u_char * /* Pointer to packet buf */
);
/*
* Writes a prebuild IP packet to the network with a supplied raw socket.
* To write a link layer packet, use the write_link_layer function.
*/
int /* number of bytes written if successful, -1 on error */
libnet_write_ip(
int sock, /* Previously opened raw socket */
u_char *, /* Pointer a complete IP datagram */
int /* Packet size */
);
/*
* Writes a prebuild IP/ethernet packet to the network with a supplied
* link_layer interface. To write just an IP packet, use the write_link_layer
* function.
*/
int /* number of bytes written if successful, -1 on error */
libnet_write_link_layer(
struct libnet_link_int *, /* Pointer to a link interface structure */
const char *, /* Pointer to the device */
u_char *, /* Pointer the u_char buf (the packet)to be written */
int /* Packet length */
);
/*
* Opens a link layer interface. Analogous to open_raw_sock.
*/
struct libnet_link_int * /* Pointer to a link layer interface struct */
libnet_open_link_interface(
char *, /* Device name */
char * /* Error buffer */
);
int /* 1 on success, -1 on failure */
libnet_close_link_interface(
struct libnet_link_int * /* Pointer to a link layer interface struct */
);
char * /* String error message */
ll_strerror(
int /* Errno */
);
/*
* Returns the IP address of the interface.
*/
u_long /* 0 upon error, address upon success */
libnet_get_ipaddr(
struct libnet_link_int *, /* Pointer to a link interface structure */
const char *, /* Device */
char * /* Error buf */
);
/*
* Returns the MAC address of the interface.
*/
struct ether_addr * /* 0 upon error, address upon success */
libnet_get_hwaddr(
struct libnet_link_int *, /* Pointer to a link interface structure */
const char *, /* Device */
char * /* Error buf */
);
/*
* Simple interface for initializing a packet.
* Basically a malloc wrapper.
*/
int /* -1 on error, 1 on ok */
libnet_init_packet(
int, /* 0 and we make a good guess, otherwise you choose. */
u_char ** /* Pointer to the pointer to the packet */
);
/*
* Simple interface for destoying a packet.
* Don't call this without a corresponding call to init_packet() first.
*/
int /* -1 if arena is NULL, 1 if ok */
libnet_destroy_packet(
u_char ** /* Pointer to the packet addr. */
);
/*
* Memory pool initialization routine.
*/
int
libnet_init_packet_arena(
struct libnet_arena **, /* Pointer to an arena pointer */
int, /* 0 and we make a good guess, otherwise you choose. */
u_short
);
/*
* Returns the next chunk of memory from the pool.
*/
u_char *
libnet_next_packet_from_arena(
struct libnet_arena **, /* Pointer to an arena pointer */
int /* 0 and we make a good guess, otherwise you choose. */
);
/*
* Memory pool destructor routine.
*/
int /* -1 if arena is NULL, 1 if ok */
libnet_destroy_packet_arena(
struct libnet_arena ** /* Pointer to an arena pointer */
);
/*
* More or less taken from tcpdump code.
*/
void
libnet_hex_dump(
u_char *, /* Packet to be dumped */
int, /* Packet size (in bytes */
int, /* To swap or not to swap */
FILE * /* Stream pointer to dump to */
);
#endif /* __LIBNET_FUNCTIONS_H */
/* EOF */

View File

@ -0,0 +1,525 @@
/*
* $Id: libnet-headers.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-headers.h - Network routine library headers header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_HEADERS_H
#define __LIBNET_HEADERS_H
/*
* Standard (IPv4) header sizes in bytes.
*/
#define LIBNET_ARP_H 0x1c /* ARP header: 28 bytes */
#define LIBNET_DNS_H 0xc /* DNS header base: 12 bytes */
#define LIBNET_ETH_H 0xe /* Etherner header: 14 bytes */
#define LIBNET_ICMP_H 0x4 /* ICMP header base: 4 bytes */
#define LIBNET_ICMP_ECHO_H 0x8 /* ICMP_ECHO header: 8 bytes */
#define LIBNET_ICMP_MASK_H 0xc /* ICMP_MASK header: 12 bytes */
#define LIBNET_ICMP_UNREACH_H 0x8 /* ICMP_UNREACH header: 8 bytes */
#define LIBNET_ICMP_TIMXCEED_H 0x8 /* ICMP_TIMXCEED header: 8 bytes */
#define LIBNET_ICMP_REDIRECT_H 0x8 /* ICMP_REDIRECT header: 8 bytes */
#define LIBNET_ICMP_TS_H 0x14 /* ICMP_TIMESTAMP headr:20 bytes */
#define LIBNET_IGMP_H 0x8 /* IGMP header: 8 bytes */
#define LIBNET_IP_H 0x14 /* IP header: 20 bytes */
/* See libnet-ospf.h for OSPF related header sizes */
#define LIBNET_RIP_H 0x18 /* RIP header base: 24 bytes */
#define LIBNET_TCP_H 0x14 /* TCP header: 20 bytes */
#define LIBNET_UDP_H 0x8 /* UDP header: 8 bytes */
#define LIBNET_VRRP_H 0x8 /* VRRP header: 8 bytes */
/*
* Concession to legacy naming scheme.
*/
#define ARP_H LIBNET_ARP_H
#define DNS_H LIBNET_DNS_H
#define ETH_H LIBNET_ETH_H
#define ICMP_H LIBNET_ICMP_H
#define ICMP_ECHO_H LIBNET_ICMP_ECHO_H
#define ICMP_MASK_H LIBNET_ICMP_MASK_H
#define ICMP_UNREACH_H LIBNET_ICMP_UNREACH_H
#define ICMP_TIMXCEED_H LIBNET_ICMP_TIMXCEED_H
#define ICMP_REDIRECT_H LIBNET_ICMP_REDIRECT_H
#define ICMP_TS_H LIBNET_ICMP_TS_H
#define IGMP_H LIBNET_IGMP_H
#define IP_H LIBNET_IP_H
#define RIP_H LIBNET_RIP_H
#define TCP_H LIBNET_TCP_H
#define UDP_H LIBNET_UDP_H
/*
* IPv4 packet header prototype.
*/
struct libnet_ip_hdr
{
#if (LIBNET_LIL_ENDIAN)
u_char ip_hl:4, /* header length */
ip_v:4; /* version */
#endif
#if (LIBNET_BIG_ENDIAN)
u_char ip_v:4, /* version */
ip_hl:4; /* header length */
#endif
u_char ip_tos; /* type of service */
u_short ip_len; /* total length */
u_short ip_id; /* identification */
u_short ip_off;
#ifndef IP_RF
#define IP_RF 0x8000 /* reserved fragment flag */
#endif
#ifndef IP_DF
#define IP_DF 0x4000 /* dont fragment flag */
#endif
#ifndef IP_MF
#define IP_MF 0x2000 /* more fragments flag */
#endif
#ifndef IP_OFFMASK
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
#endif
u_char ip_ttl; /* time to live */
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src, ip_dst; /* source and dest address */
};
/*
* TCP packet header prototype.
*/
struct libnet_tcp_hdr
{
u_short th_sport; /* source port */
u_short th_dport; /* destination port */
u_long th_seq; /* sequence number */
u_long th_ack; /* acknowledgement number */
#if (LIBNET_LIL_ENDIAN)
u_char th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
#if (LIBNET_BIG_ENDIAN)
u_char th_off:4, /* data offset */
th_x2:4; /* (unused) */
#endif
u_char th_flags; /* control flags */
#ifndef TH_FIN
#define TH_FIN 0x01
#endif
#ifndef TH_SYN
#define TH_SYN 0x02
#endif
#ifndef TH_RST
#define TH_RST 0x04
#endif
#ifndef TH_PUSH
#define TH_PUSH 0x08
#endif
#ifndef TH_ACK
#define TH_ACK 0x10
#endif
#ifndef TH_URG
#define TH_URG 0x20
#endif
u_short th_win; /* window */
u_short th_sum; /* checksum */
u_short th_urp; /* urgent pointer */
};
/*
* UDP packet header prototype.
*/
struct libnet_udp_hdr
{
u_short uh_sport; /* soure port */
u_short uh_dport; /* destination port */
u_short uh_ulen; /* length */
u_short uh_sum; /* checksum */
};
/*
* ICMP packet header prototype.
*/
struct libnet_icmp_hdr
{
u_char icmp_type;
/*
* ICMP types.
*/
#ifndef ICMP_ECHOREPLY
#define ICMP_ECHOREPLY 0
#endif
#ifndef ICMP_UNREACH
#define ICMP_UNREACH 3
#endif
#ifndef ICMP_SOURCEQUENCH
#define ICMP_SOURCEQUENCH 4
#endif
#ifndef ICMP_REDIRECT
#define ICMP_REDIRECT 5
#endif
#ifndef ICMP_ECHO
#define ICMP_ECHO 8
#endif
#ifndef ICMP_ROUTERADVERT
#define ICMP_ROUTERADVERT 9
#endif
#ifndef ICMP_ROUTERSOLICIT
#define ICMP_ROUTERSOLICIT 10
#endif
#ifndef ICMP_TIMXCEED
#define ICMP_TIMXCEED 11
#endif
#ifndef ICMP_PARAMPROB
#define ICMP_PARAMPROB 12
#endif
#ifndef ICMP_TSTAMP
#define ICMP_TSTAMP 13
#endif
#ifndef ICMP_TSTAMPREPLY
#define ICMP_TSTAMPREPLY 14
#endif
#ifndef ICMP_IREQ
#define ICMP_IREQ 15
#endif
#ifndef ICMP_IREQREPLY
#define ICMP_IREQREPLY 16
#endif
#ifndef ICMP_MASKREQ
#define ICMP_MASKREQ 17
#endif
#ifndef ICMP_MASKREPLY
#define ICMP_MASKREPLY 18
#endif
u_char icmp_code;
/*
* ICMP codes.
*/
#ifndef ICMP_UNREACH_NET
#define ICMP_UNREACH_NET 0
#endif
#ifndef ICMP_UNREACH_HOST
#define ICMP_UNREACH_HOST 1
#endif
#ifndef ICMP_UNREACH_PROTOCOL
#define ICMP_UNREACH_PROTOCOL 2
#endif
#ifndef ICMP_UNREACH_PORT
#define ICMP_UNREACH_PORT 3
#endif
#ifndef ICMP_UNREACH_NEEDFRAG
#define ICMP_UNREACH_NEEDFRAG 4
#endif
#ifndef ICMP_UNREACH_SRCFAIL
#define ICMP_UNREACH_SRCFAIL 5
#endif
#ifndef ICMP_UNREACH_NET_UNKNOWN
#define ICMP_UNREACH_NET_UNKNOWN 6
#endif
#ifndef ICMP_UNREACH_HOST_UNKNOWN
#define ICMP_UNREACH_HOST_UNKNOWN 7
#endif
#ifndef ICMP_UNREACH_ISOLATED
#define ICMP_UNREACH_ISOLATED 8
#endif
#ifndef ICMP_UNREACH_NET_PROHIB
#define ICMP_UNREACH_NET_PROHIB 9
#endif
#ifndef ICMP_UNREACH_HOST_PROHIB
#define ICMP_UNREACH_HOST_PROHIB 10
#endif
#ifndef ICMP_UNREACH_TOSNET
#define ICMP_UNREACH_TOSNET 11
#endif
#ifndef ICMP_UNREACH_TOSHOST
#define ICMP_UNREACH_TOSHOST 12
#endif
#ifndef ICMP_UNREACH_FILTER_PROHIB
#define ICMP_UNREACH_FILTER_PROHIB 13
#endif
#ifndef ICMP_UNREACH_HOST_PRECEDENCE
#define ICMP_UNREACH_HOST_PRECEDENCE 14
#endif
#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
#endif
#ifndef ICMP_REDIRECT_NET
#define ICMP_REDIRECT_NET 0
#endif
#ifndef ICMP_REDIRECT_HOST
#define ICMP_REDIRECT_HOST 1
#endif
#ifndef ICMP_REDIRECT_TOSNET
#define ICMP_REDIRECT_TOSNET 2
#endif
#ifndef ICMP_REDIRECT_TOSHOST
#define ICMP_REDIRECT_TOSHOST 3
#endif
#ifndef ICMP_TIMXCEED_INTRANS
#define ICMP_TIMXCEED_INTRANS 0
#endif
#ifndef ICMP_TIMXCEED_REASS
#define ICMP_TIMXCEED_REASS 1
#endif
#ifndef ICMP_PARAMPROB_OPTABSENT
#define ICMP_PARAMPROB_OPTABSENT 1
#endif
u_short icmp_sum;
union
{
struct
{
u_short id;
u_short seq;
}echo;
#undef icmp_id
#undef icmp_seq
#define icmp_id hun.echo.id
#define icmp_seq hun.echo.seq
u_long gateway;
struct
{
u_short pad;
u_short mtu;
}frag;
}hun;
union
{
struct
{
n_time its_otime;
n_time its_rtime;
n_time its_ttime;
}ts;
struct
{
struct ip idi_ip;
/* options and then 64 bits of data */
}ip;
u_long mask;
char data[1];
#undef icmp_mask
#define icmp_mask dun.mask
#undef icmp_data
#define icmp_data dun.data
#undef icmp_otime
#define icmp_otime dun.ts.its_otime
#undef icmp_rtime
#define icmp_rtime dun.ts.its_rtime
#undef icmp_ttime
#define icmp_ttime dun.ts.its_ttime
}dun;
};
/*
* IGMP header.
*/
struct libnet_igmp_hdr
{
u_char igmp_type;
#ifndef IGMP_MEMBERSHIP_QUERY
#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */
#endif
#ifndef IGMP_V1_MEMBERSHIP_REPORT
#define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */
#endif
#ifndef IGMP_V2_MEMBERSHIP_REPORT
#define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */
#endif
#ifndef IGMP_LEAVE_GROUP
#define IGMP_LEAVE_GROUP 0x17 /* Leave-group message */
#endif
u_char igmp_code;
u_short igmp_sum;
struct in_addr igmp_group;
};
/*
* Ethernet packet header prototype. Too many O/S's define this differently.
* Easy enough to solve that and define it here.
*/
struct libnet_ethernet_hdr
{
#ifndef ETHER_ADDR_LEN
#define ETHER_ADDR_LEN 6
#endif
u_char ether_dhost[ETHER_ADDR_LEN]; /* destination ethernet address */
u_char ether_shost[ETHER_ADDR_LEN]; /* source ethernet address */
u_short ether_type; /* packet type ID */
};
#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
#define ETHERTYPE_IP 0x0800 /* IP protocol */
#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
#define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tagging */
#define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */
#ifndef __ANDROID__
#if !defined(__GLIBC__) || (!__GLIBC__)
struct ether_addr
{
u_char ether_addr_octet[6];
};
#endif
#endif
/*
* ARP packet header prototype. Too many O/S's define this differently.
* Easy enough to solve that and define it here.
*/
struct libnet_arp_hdr
{
u_short ar_hrd; /* format of hardware address */
#define ARPHRD_ETHER 1 /* ethernet hardware format */
u_short ar_pro; /* format of protocol address */
u_char ar_hln; /* length of hardware address */
u_char ar_pln; /* length of protocol addres */
u_short ar_op; /* operation type */
#define ARPOP_REQUEST 1 /* req to resolve address */
#define ARPOP_REPLY 2 /* resp to previous request */
#define ARPOP_REVREQUEST 3 /* req protocol address given hardware */
#define ARPOP_REVREPLY 4 /* resp giving protocol address */
#define ARPOP_INVREQUEST 8 /* req to identify peer */
#define ARPOP_INVREPLY 9 /* resp identifying peer */
/*
* These should implementation defined but I've hardcoded eth/IP.
*/
u_char ar_sha[6]; /* sender hardware address */
u_char ar_spa[4]; /* sender protocol address */
u_char ar_tha[6]; /* target hardware address */
u_char ar_tpa[4]; /* target protocol address */
};
/*
* Base DNS header.
*/
struct libnet_dns_hdr
{
u_short id; /* DNS packet ID */
u_short flags; /* DNS flags */
u_short num_q; /* Number of questions */
u_short num_answ_rr; /* Number of answer resource records */
u_short num_auth_rr; /* Number of authority resource records */
u_short num_addi_rr; /* Number of additional resource records */
};
/*
* Base RIP (routing information protocol) header.
*/
struct libnet_rip_hdr
{
u_char cmd; /* RIP command */
#define RIPCMD_REQUEST 1 /* want info */
#define RIPCMD_RESPONSE 2 /* responding to request */
#define RIPCMD_TRACEON 3 /* turn tracing on */
#define RIPCMD_TRACEOFF 4 /* turn it off */
#define RIPCMD_POLL 5 /* like request, but anyone answers */
#define RIPCMD_POLLENTRY 6 /* like poll, but for entire entry */
#define RIPCMD_MAX 7
u_char ver; /* RIP version */
#define RIPVER_0 0
#define RIPVER_1 1
#define RIPVER_2 2
u_short rd; /* Zero (v1) or Routing Domain (v2) */
u_short af; /* Address family */
u_short rt; /* Zero (v1) or Route Tag (v2) */
u_long addr; /* IP address */
u_long mask; /* Zero (v1) or Subnet Mask (v2) */
u_long next_hop; /* Zero (v1) or Next hop IP address (v2) */
u_long metric; /* Metric */
};
/*
* VRRP packet header prototype.
*/
#ifndef IPPROTO_VRRP
#define IPPROTO_VRRP 112
#endif
struct libnet_vrrp_hdr
{
#if (LIBNET_LIL_ENDIAN)
u_char vrrp_v:4, /* protocol version */
vrrp_t:4; /* packet type */
#endif
#if (LIBNET_BIG_ENDIAN)
u_char vrrp_t:4, /* packet type */
vrrp_v:4; /* protocol version */
#endif
#define LIBNET_VRRP_TYPE_ADVERT 0x1
u_char vrrp_vrouter_id; /* virtual router id */
u_char vrrp_priority; /* priority */
u_char vrrp_ip_count; /* number of IP addresses */
u_char vrrp_auth_type; /* authorization type */
#define LIBNET_VRRP_AUTH_NONE 0x1
#define LIBNET_VRRP_AUTH_PASSWD 0x2
#define LIBNET_VRRP_AUTH_IPAH 0x3
u_char vrrp_advert_int; /* advertisement interval */
u_short vrrp_sum; /* checksum */
};
#if 0
struct libnet_snmp_hdr
{
/* ASN.1 BER support first */
};
#endif
/*
* TCP options structure.
*/
struct tcpoption
{
u_char tcpopt_list[MAX_IPOPTLEN];
};
#ifdef __linux__
/*
* Linux has a radically different IP options structure from BSD.
*/
struct ipoption
{
struct in_addr ipopt_dst; /* first-hop dst if source routed */
char ipopt_list[MAX_IPOPTLEN]; /* options proper */
};
#endif
#endif /* __LIBNET_HEADERS_H */
/* EOF */

View File

@ -0,0 +1,146 @@
/*
* $Id: libnet-macros.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-macros.h - Network routine library macro header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_MACROS_H
#define __LIBNET_MACROS_H
/*
* for libnet_hostlookup
*/
#define LIBNET_DONT_RESOLVE 0
#define LIBNET_RESOLVE 1
/*
* prand constants
*/
#define LIBNET_PR2 0
#define LIBNET_PR8 1
#define LIBNET_PR16 2
#define LIBNET_PRu16 3
#define LIBNET_PR32 4
#define LIBNET_PRu32 5
#define LIBNET_PRAND_MAX 0xffffffff
/*
* Concession to legacy naming scheme
*/
#define PR2 LIBNET_PR2
#define PR8 LIBNET_PR8
#define PR16 LIBNET_PR16
#define PRu16 LIBNET_PRu16
#define PR32 LIBNET_PR32
#define PRu32 LIBNET_PRu32
#define PRAND_MAX LIBNET_PRAND_MAX
/*
* Misc packet sizes for malloc
*/
#define LIBNET_PACKET LIBNET_IP_H + LIBNET_TCP_H /* IP, UDP or TCP */
#define LIBNET_OPTS 0x34 /* options! options! options! */
#define LIBNET_MAX_PACKET 0xffff /* as big as we can get */
/*
* Error handling constants.
*/
#define LIBNET_ERR_WARNING 1
#define LIBNET_ERR_CRITICAL 2
#define LIBNET_ERR_FATAL 3
/*
* Concession to legacy naming scheme
*/
#define LN_ERR_WARNING LIBNET_ERR_WARNING
#define LN_ERR_CRITICAL LIBNET_ERR_CRITICAL
#define LN_ERR_FATAL LIBNET_ERR_FATAL
#define LIBNET_ERRBUF_SIZE 256
/*
* Some BSD variants have this endianess problem.
*/
#if (LIBNET_BSD_BYTE_SWAP)
#define FIX(n) ntohs(n)
#define UNFIX(n) htons(n)
#else
#define FIX(n) (n)
#define UNFIX(n) (n)
#endif
/*
* Arena stuff
*/
#define LIBNET_GET_ARENA_SIZE(a) (a.size)
#define LIBNET_GET_ARENA_REMAINING_BYTES(a) (a.size - a.current)
/*
* Checksum stuff
*/
#define LIBNET_CKSUM_CARRY(x) \
(x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
/*
* OSPF stuff
*/
#define LIBNET_OSPF_AUTHCPY(x,y) memcpy((u_char *)x, (u_char *)y, sizeof(y))
#define LIBNET_OSPF_CKSUMBUF(x,y) memcpy((u_char *)x, (u_char *)y, sizeof(y))
/*
* Not all systems have IFF_LOOPBACK
* Used by if_addr.c
*/
#ifdef IFF_LOOPBACK
#define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
#else
#define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
#endif
#define LIBNET_PRINT_ETH_ADDR(e) \
{ \
int i = 0; \
for (i = 0; i < 6; i++) \
{ \
printf("%x", e.ether_addr_octet[i]); \
if (i != 5) \
{ \
printf(":"); \
} \
} \
printf("\n"); \
}
#endif /* __LIBNET_MACROS_H */
/* EOF */

View File

@ -0,0 +1,394 @@
/*
* $Id: libnet-ospf.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-ospf.h - Network routine library headers header file
*
* Copyright (c) 1999 Andrew Reiter <areiter@bindview.com>
* Bindview Development
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_OSPF_H
#define __LIBNET_OSPF_H
#include <sys/types.h>
/*
* Not all OSes define this in /etc/protocols.. ie, solaris...
*/
#ifndef IPPROTO_OSPF
#define IPPROTO_OSPF 89
#endif
#define IPPROTO_OSPF_LSA 890 /* Made this up. Hope it's unused */
#define OSPFVERSION 2
#define LIBNET_MODX 4102 /* Used in LSA checksum */
/*
* OSPF header lengths.
*/
#define LIBNET_OSPF_H 0x10 /* 16 bytes */
#define LIBNET_HELLO_H 0x18 /* 24 bytes */
#define LIBNET_DBD_H 0x8 /* 8 bytes */
#define LIBNET_LSR_H 0xc /* 12 bytes */
#define LIBNET_LSU_H 0x4 /* 4 bytes */
#define LIBNET_LSA_H 0x14 /* 20 bytes */
#define LIBNET_AUTH_H 0x8 /* 8 bytes */
#define LIBNET_OSPF_CKSUM 0x10 /* 16 bytes */
/*
* Link State packet format lengths.
*/
#define LIBNET_LS_RTR_LEN 0x10 /* 16 bytes */
#define LIBNET_LS_NET_LEN 0x8 /* 8 bytes */
#define LIBNET_LS_SUM_LEN 0xc /* 12 bytes */
#define LIBNET_LS_AS_EXT_LEN 0x10 /* 16 bytes */
/*
* OSPFv2 Packet Header.
*/
struct libnet_ospf_hdr
{
u_char ospf_v; /* version */
u_char ospf_type; /* type */
#define LIBNET_OSPF_UMD 0 /* UMd monitoring packet */
#define LIBNET_OSPF_HELLO 1 /* HELLO packet */
#define LIBNET_OSPF_DBD 2 /* DataBase Description Packet */
#define LIBNET_OSPF_LSR 3 /* Link State Request Packet */
#define LIBNET_OSPF_LSU 4 /* Link State Update Packet */
#define LIBNET_OSPF_LSA 5 /* Link State Acknowledgement Packet */
u_short ospf_len; /* length */
struct in_addr ospf_rtr_id; /* source router ID */
struct in_addr ospf_area_id; /* roam ID */
u_short ospf_cksum; /* checksum */
u_short ospf_auth_type; /* authentication type */
#define LIBNET_OSPF_AUTH_NULL 0 /* Null password */
#define LIBNET_OSPF_AUTH_SIMPLE 1 /* Simple, plaintext, 8 char password */
#define LIBNET_OSPF_AUTH_MD5 2 /* MD5 */
};
/*
* OSPF authentication header.
*/
struct libnet_auth_hdr
{
u_short ospf_auth_null; /* NULL */
u_char ospf_auth_keyid; /* Authentication Key ID */
u_char ospf_auth_len; /* Auth data length */
u_int ospf_auth_seq; /* Cryptographic sequence number */
};
/*
* Options used in multiple OSPF packets.
* More info can be found in section A.2 of RFC 2328.
*/
#define LIBNET_OPT_EBIT 0x02 /* Describes the way AS-external-LSAs are flooded */
#define LIBNET_OPT_MCBIT 0x04 /* Whether or not IP multicast dgrams are fwdd */
#define LIBNET_OPT_NPBIT 0x08 /* Describes handling of type-7 LSAs */
#define LIBNET_OPT_EABIT 0x10 /* rtr's willingness to send/recv EA-LSAs */
#define LIBNET_OPT_DCBIT 0x20 /* Describes handling of demand circuits */
/*
* OSPF HELLO Packet Header.
*/
struct libnet_ospf_hello_hdr
{
struct in_addr hello_nmask; /* Netmask associated with the interface */
u_short hello_intrvl; /* Num of seconds between routers last packet */
u_char hello_opts; /* Options for HELLO packets (look above) */
u_char hello_rtr_pri; /* Router's priority (if 0, can't be backup) */
u_int hello_dead_intvl; /* # of secs a router is silent till deemed down */
struct in_addr hello_des_rtr; /* Designated router on the network */
struct in_addr hello_bkup_rtr; /* Backup router */
struct in_addr hello_nbr; /* neighbor router, memcpy more as needed */
};
/*
* Database Description header.
*/
struct libnet_dbd_hdr
{
u_short dbd_mtu_len; /* Max length of IP dgram that this 'if' can use */
u_char dbd_opts; /* DBD packet options (look above) */
u_char dbd_type; /* Type of exchange occurring (look below) */
#define LIBNET_DBD_IBIT 0x01 /* Init Bit */
#define LIBNET_DBD_MBIT 0x02 /* Says more DBD packets are to come */
#define LIBNET_DBD_MSBIT 0x04 /* If 1, sender is the master in the exchnge */
u_int dbd_seq; /* DBD sequence number */
};
/*
* Used for the LS type field in all LS* headers.
*/
#define LIBNET_LS_TYPE_RTR 1 /* Router-LSA */
#define LIBNET_LS_TYPE_NET 2 /* Network-LSA */
#define LIBNET_LS_TYPE_IP 3 /* Summary-LSA (IP Network) */
#define LIBNET_LS_TYPE_ASBR 4 /* Summary-LSA (ASBR) */
#define LIBNET_LS_TYPE_ASEXT 5 /* AS-External-LSA */
/*
* Link State Request header.
*/
struct libnet_lsr_hdr
{
u_int lsr_type; /* Type of LS being requested (see below) */
u_int lsr_lsid; /* Link State ID */
struct in_addr lsr_adrtr; /* advertising router (memcpy more as needed) */
};
/*
* Link State Update header.
*/
struct libnet_lsu_hdr
{
u_int lsu_num; /* Number of LSAs that will be broadcasted */
};
/*
* Link State Acknowledgement header.
*/
struct libnet_lsa_hdr
{
u_short lsa_age; /* Time in seconds since the LSA was originated */
u_char lsa_opts; /* Look above for OPTS_* */
u_char lsa_type; /* Look below for LS_TYPE_* */
u_int lsa_id; /* Link State ID */
struct in_addr lsa_adv; /* Router ID of Advertising router */
u_int lsa_seq; /* LSA sequence number to detect old/bad ones */
u_char lsa_cksum[2]; /* "Fletcher Checksum" of all fields minus age */
u_short lsa_len; /* Length in bytes including the 20 byte header */
};
/*
* Router LSA data format
*
* Other stuff for TOS can be added for backward compatability, for this
* version, only OSPFv2 is being FULLY supported.
*/
struct libnet_rtr_lsa_hdr
{
u_short rtr_flags; /* Set to help describe packet */
#define LIBNET_RTR_FLAGS_W 0x0100 /* W bit */
#define LIBNET_RTR_FLAGS_E 0x0200 /* E bit */
#define LIBNET_RTR_FLAGS_B 0x0400 /* B bit */
u_short rtr_num; /* Number of links within that packet */
u_int rtr_link_id; /* Describes link_data (look below) */
#define LIBNET_LINK_ID_NBR_ID 1 /* Neighbors router ID, also can be 4 */
#define LIBNET_LINK_ID_IP_DES 2 /* IP address of designated router */
#define LIBNET_LINK_ID_SUB 3 /* IP subnet number */
u_int rtr_link_data; /* Depending on link_id, info is here */
u_char rtr_type; /* Description of router link */
#define LIBNET_RTR_TYPE_PTP 1 /* Point-To-Point */
#define LIBNET_RTR_TYPE_TRANS 2 /* Connection to a "transit network" */
#define LIBNET_RTR_TYPE_STUB 3 /* Connectin to a "stub network" */
#define RTR_TYPE_VRTL 4 /* Connects to a "virtual link" */
u_char rtr_tos_num; /* Number of different TOS metrics for this link */
u_short rtr_metric; /* The "cost" of using this link */
};
/*
* Network LSA data format.
*/
struct libnet_net_lsa_hdr
{
struct in_addr net_nmask; /* Netmask for that network */
u_int net_rtr_id; /* ID of router attached to that network */
};
/*
* Summary LSA data format.
*/
struct libnet_sum_lsa_hdr
{
struct in_addr sum_nmask; /* Netmask of destination IP address */
u_int sum_metric; /* Same as in rtr_lsa (&0xfff to use last 24bit) */
u_int sum_tos_metric; /* first 8bits are TOS, 24bits are TOS Metric */
};
/*
* AS External LSA data format.
* & 0xfff logic operator for as_metric to get last 24bits.
*/
struct libnet_as_lsa_hdr
{
struct in_addr as_nmask; /* Netmask for advertised destination */
u_int as_metric; /* May have to set E bit in first 8bits */
#define LIBNET_AS_E_BIT_ON 0x80000000 /* as_metric */
struct in_addr as_fwd_addr; /* Forwarding address */
u_int as_rte_tag; /* External route tag */
};
int
libnet_build_ospf(
u_short,
u_char,
u_long,
u_long,
u_short,
const char *,
int,
u_char *
);
int
libnet_build_ospf_hello(
u_long,
u_short,
u_char,
u_char,
u_int,
u_long,
u_long,
u_long,
const char *,
int,
u_char *
);
int
libnet_build_ospf_dbd(
u_short,
u_char,
u_char,
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsr(
u_int,
u_int,
u_long,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsu(
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa(
u_short,
u_char,
u_char,
u_int,
u_long,
u_int,
u_short,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_rtr(
u_short,
u_short,
u_int,
u_int,
u_char,
u_char,
u_short,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_net(
u_long,
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_sum(
u_long,
u_int,
u_int,
const char *,
int,
u_char *
);
int
libnet_build_ospf_lsa_as(
u_long,
u_int,
u_long,
u_int,
const char *,
int,
u_char *
);
void
libnet_ospf_lsa_checksum(
u_char *,
int
);
#endif /* __LIBNET_OSPF_H */

View File

@ -0,0 +1,84 @@
/*
* $Id: libnet-structures.h,v 1.1.1.1 2007/08/06 10:04:42 root Exp $
*
* libnet-structures.h - Network routine library structures header file
*
* Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifndef __LIBNET_STRUCTURES_H
#define __LIBNET_STRUCTURES_H
/*
* Port list chain structure
*/
struct libnet_plist_chain
{
u_short node; /* node number */
u_short bport; /* beggining port */
u_short eport; /* terminating port */
u_char id; /* global array offset */
struct libnet_plist_chain *next; /* next node in the list */
};
/*
* Low level packet interface struct
*/
struct libnet_link_int
{
int fd; /* link layer file descriptor */
int linktype; /* link type */
int linkoffset; /* link header size (offset till network layer) */
u_char *device; /* device name */
};
/*
* Arena structure.
*/
struct libnet_arena
{
int tag; /* arena tag */
u_char *memory_pool; /* the memory */
u_long current; /* the current amount of memory allocated */
u_long size; /* the size of the pool in bytes */
};
/*
* Interface selection stuff
*/
struct libnet_ifaddr_list
{
u_long addr;
char *device;
};
#endif /* __LIBNET_STRUCTURES_H */
/* EOF */