⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libnet-headers.h

📁 Libnet is a generic networking API that provides access to several protocols. It is not designed as
💻 H
📖 第 1 页 / 共 3 页
字号:
/*
 *  $Id: libnet-headers.h,v 1.1.1.1 2002/09/16 12:58:05 robertol Exp $
 *
 *  libnet-headers.h - Network routine library headers header file
 *
 *  Copyright (c) 1998 - 2002 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

#define LIBNET_802_1Q_H         0x12    /* 802.1Q header:       18 bytes */
#define LIBNET_802_2_H          0x03    /* 802.2 LLC header:     3 bytes */
#define LIBNET_802_2SNAP_H      0x08    /* 802.2 LLC/SNAP header:8 bytes */
#define LIBNET_802_3_H          0x0e    /* 802.3 header:        14 bytes */
#define LIBNET_802_5_H          0x16    /* 802.5 header:        22 bytes */
#define LIBNET_ARP_H            0x08    /* ARP header w/o addrs: 8 bytes */
#define LIBNET_ARP_ETH_IP_H     0x1c    /* ARP w/ ETH and IP:   28 bytes */
#define LIBNET_CDP_H            0x08    /* CDP header base:      8 bytes */
#define LIBNET_DHCPV4_H         0xf0    /* DHCP v4 header:     240 bytes */
#define LIBNET_DNSV4_H          0x0c    /* DNS v4 header base:  12 bytes */
#define LIBNET_ETH_H            0x0e    /* Etherner header:     14 bytes */
#define LIBNET_TOK_H            0x16    /* Token Ring header:   22 bytes */
#define LIBNET_ICMPV4_H         0x04    /* ICMP header base:     4 bytes */
#define LIBNET_ICMPV4_ECHO_H    0x08    /* ICMP_ECHO header:     8 bytes */
#define LIBNET_ICMPV4_MASK_H    0x0c    /* ICMP_MASK header:    12 bytes */
#define LIBNET_ICMPV4_UNREACH_H  0x08   /* ICMP_UNREACH header:  8 bytes */
#define LIBNET_ICMPV4_TIMXCEED_H 0x08   /* ICMP_TIMXCEED header: 8 bytes */
#define LIBNET_ICMPV4_REDIRECT_H 0x08   /* ICMP_REDIRECT header: 8 bytes */
#define LIBNET_ICMPV4_TS_H      0x14    /* ICMP_TIMESTAMP headr:20 bytes */
#define LIBNET_ICMPV6_H         0x08    /* ICMP6 header base:    8 bytes */
#define LIBNET_IGMP_H           0x08    /* IGMP header:          8 bytes */
#define LIBNET_IPV4_H           0x14    /* IPv4 header:         20 bytes */
#define LIBNET_IPV6_H           0x28    /* IPv6 header:         40 bytes */
#define LIBNET_IPSEC_ESP_HDR_H  0x0c    /* IPSEC ESP header:    12 bytes */
#define LIBNET_IPSEC_ESP_FTR_H  0x02    /* IPSEC ESP footer:     2 bytes */
#define LIBNET_IPSEC_AH_H       0x10    /* IPSEC AH header:     16 bytes */
#define LIBNET_ISL_H            0x1a    /* ISL header:          26 bytes */
#define LIBNET_OSPF_H           0x10    /* OSPF header:         16 bytes */
#define LIBNET_OSPF_HELLO_H     0x18    /* OSPF hello header:   24 bytes */
#define LIBNET_OSPF_DBD_H       0x08    /* OSPF DBD header:      8 bytes */
#define LIBNET_OSPF_LSR_H       0x0c    /* OSPF LSR header:     12 bytes */
#define LIBNET_OSPF_LSU_H       0x04    /* OSPF LSU header:      4 bytes */
#define LIBNET_OSPF_LSA_H       0x14    /* OSPF LSA header:     20 bytes */
#define LIBNET_OSPF_AUTH_H      0x08    /* OSPF AUTH header:     8 bytes */
#define LIBNET_OSPF_CKSUM       0x10    /* OSPF CKSUM header:   16 bytes */
#define LIBNET_OSPF_LS_RTR_H    0x10    /* OSPF LS RTR header:  16 bytes */
#define LIBNET_OSPF_LS_NET_H    0x08    /* OSPF LS NET header:   8 bytes */
#define LIBNET_OSPF_LS_SUM_H    0x0c    /* OSPF LS SUM header:  12 bytes */
#define LIBNET_OSPF_LS_AS_EXT_H 0x10    /* OSPF LS AS header:   16 bytes */
#define LIBNET_NTP_H            0x30    /* NTP header:          48 bytes */
#define LIBNET_RIP_H            0x18    /* RIP header base:     24 bytes */
#define LIBNET_STP_CONF_H       0x23    /* STP conf header:     35 bytes */
#define LIBNET_STP_TCN_H        0x04    /* STP tcn header:       4 bytes */
#define LIBNET_TCP_H            0x14    /* TCP header:          20 bytes */
#define LIBNET_UDP_H            0x08    /* UDP header:           8 bytes */
#define LIBNET_VRRP_H           0x08    /* VRRP header:          8 bytes */

/*
 *  IEEE 802.1Q VLAN header (ethervlan)
 *  Virtual Local Area Network
 *  static header size: 18 bytes
 */
struct libnet_802_1q_hdr
{
    u_char vlan_dhost[ETHER_ADDR_LEN];  /* destination ethernet address */
    u_char vlan_shost[ETHER_ADDR_LEN];  /* source ethernet address */
    u_short vlan_tpi;                   /* tag protocol ID */
    u_short vlan_priority_c_vid;        /* priority | VLAN ID */
#define LIBNET_802_1Q_PRIMASK   0x0007  /* priority mask */
#define LIBNET_802_1Q_CFIMASK   0x0001  /* CFI mask */
#define LIBNET_802_1Q_VIDMASK   0x0fff  /* vid mask */
    u_short vlan_len;                   /* len / type (802.3 / Ethernet II) */
};  


/*
 *  IEEE 802.2 LLC header
 *  Link Layer Control
 *  static header size: 3 bytes
 */
struct libnet_802_2_hdr
{
    u_char llc_dsap;            /* destination service access point */
    u_char llc_ssap;            /* source service access point */
#define LIBNET_SAP_STP          0x42
#define LIBNET_SAP_SNAP         0xaa
    u_char llc_control;         /* control field */
};


/*
 *  IEEE 802.2 LLC/SNAP header
 *  SubNetwork Attachment Point
 *  static header size: 8 bytes
 */
struct libnet_802_2snap_hdr
{
    u_char snap_dsap;           /* destination service access point */
    u_char snap_ssap;           /* destination service access point */
    u_char snap_control;        /* control field */
    u_char snap_oui[3];         /* OUI */
    u_short snap_type;          /* type */
};


/*
 *  802.3 header
 *  IEEE Ethernet
 *  Static header size: 14 bytes
 */
struct libnet_802_3_hdr
{
    u_char  _802_3_dhost[ETHER_ADDR_LEN];/* destination ethernet address */
    u_char  _802_3_shost[ETHER_ADDR_LEN];/* source ethernet address */
    u_short _802_3_len;                 /* packet type ID */
};

/*
 *  802.5 header
 *  IEEE Token-Ring
 *  Static header size: 22 bytes
 */

struct libnet_802_5_hdr
{
    u_char	_802_5_accesscontrol;
	u_char	_802_5_framecontrol;
	u_char  _802_5_dhost[ETHER_ADDR_LEN];    /* destination address */
    u_char  _802_5_shost[ETHER_ADDR_LEN];    /* source address */
    
    struct libnet_802_2snap_hdr _802_5snap_hdr;
};

#define libnet_token_hdr libnet_802_5_hdr
/*
{
    u_char	_802_5_accesscontrol;
	u_char	_802_5_framecontrol;
	u_char  _802_5_dhost[ETHER_ADDR_LEN];    // destination address
    u_char  _802_5_shost[ETHER_ADDR_LEN];    // source address
    
    struct libnet_802_2snap_hdr _802_5snap_hdr;
};
*/

#define  _802_5_dsap    _802_5snap_hdr.snap_dsap
#define  _802_5_ssap    _802_5snap_hdr.snap_ssap
#define  _802_5_control _802_5snap_hdr.snap_control
#define  _802_5_oui     _802_5snap_hdr.snap_oui
#define  _802_5_type    _802_5snap_hdr.snap_type

/* 
 *  ARP header
 *  Address Resolution Protocol
 *  Base header size: 8 bytes
 */
struct libnet_arp_hdr
{
    u_short ar_hrd;         /* format of hardware address */
#define ARPHRD_NETROM   0   /* from KA9Q: NET/ROM pseudo */
#define ARPHRD_ETHER    1   /* Ethernet 10Mbps */
#define ARPHRD_EETHER   2   /* Experimental Ethernet */
#define ARPHRD_AX25     3   /* AX.25 Level 2 */
#define ARPHRD_PRONET   4   /* PROnet token ring */
#define ARPHRD_CHAOS    5   /* Chaosnet */
#define ARPHRD_IEEE802  6   /* IEEE 802.2 Ethernet/TR/TB */
#define ARPHRD_ARCNET   7   /* ARCnet */
#define ARPHRD_APPLETLK 8   /* APPLEtalk */
#define ARPHRD_LANSTAR  9   /* Lanstar */
#define ARPHRD_DLCI     15  /* Frame Relay DLCI */
#define ARPHRD_ATM      19  /* ATM */
#define ARPHRD_METRICOM 23  /* Metricom STRIP (new IANA id) */
#define ARPHRD_IPSEC    31  /* IPsec tunnel */
    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 */

    /* address information allocated dynamically */
};


/*
 *  CDP header
 *  Cisco Discovery Protocol
 *  Base header size: 8 bytes
 */

/*
 *  For checksum stuff -- IANA says 135-254 is "unassigned" as of 12.2001.
 *  Let's hope this one stays that way for a while!
 */
#define LIBNET_PROTO_CDP    200
struct libnet_cdp_hdr
{
    u_char cdp_version;     /* version (should always be 0x01) */
    u_char cdp_ttl;         /* time reciever should hold info in this packet */
    u_short cdp_sum;        /* checksum */
    u_short cdp_type;       /* type */
#define LIBNET_CDP_DEVID    0x1 /* device id */
#define LIBNET_CDP_ADDRESS  0x2 /* address */
#define LIBNET_CDP_PORTID   0x3 /* port id */
#define LIBNET_CDP_CAPABIL  0x4 /* capabilities */
#define LIBNET_CDP_VERSION  0x5 /* version */
#define LIBNET_CDP_PLATFORM 0x6 /* platform */
#define LIBNET_CDP_IPPREFIX 0x7 /* ip prefix */
    u_short cdp_len;        /* type + length + value */
    /* value information done dynamically */

/* CDP capabilities */
#define LIBNET_CDP_CAP_L3R  0x01/* performs level 3 routing */
#define LIBNET_CDP_CAP_L2B  0x02/* performs level 2 transparent bridging */
#define LIBNET_CDP_CAP_L2SRB 0x04/* performs level 2 sourceroute bridging */
#define LIBNET_CDP_CAP_L2S  0x08/* performs level 2 switching */
#define LIBNET_CDP_CAP_SR   0x10/* sends and recieves packets on a network */
#define LIBNET_CDP_CAP_NOI  0x20/* does not forward IGMP on non-router ports */
#define LIBNET_CDP_CAP_L1F  0x40/* provides level 1 functionality */
};


/*
 *  Used as an overlay for type/len/values
 */
struct libnet_cdp_value_hdr
{
    u_short cdp_type;
    u_short cdp_len;
};


/*
 *  DHCP header
 *  Dynamic Host Configuration Protocol
 *  Static header size: f0 bytes
 */
struct libnet_dhcpv4_hdr
{
    u_char dhcp_opcode;     /* opcode */
#define LIBNET_DHCP_REQUEST 0x1
#define LIBNET_DHCP_REPLY   0x2
    u_char dhcp_htype;      /* hardware address type */
    u_char dhcp_hlen;       /* hardware address length */
    u_char dhcp_hopcount;   /* used by proxy servers */
    u_long dhcp_xid;        /* transaction ID */
    u_short dhcp_secs;      /* number of seconds since trying to bootstrap */
    u_short dhcp_flags;     /* flags for DHCP, unused for BOOTP */
    u_long dhcp_cip;        /* client's IP */
    u_long dhcp_yip;        /* your IP */
    u_long dhcp_sip;        /* server's IP */
    u_long dhcp_gip;        /* gateway IP */
    u_char dhcp_chaddr[16]; /* client hardware address */
    u_char dhcp_sname[64];  /* server host name */
    u_char dhcp_file[128];  /* boot file name */
    u_long dhcp_magic;      /* BOOTP magic header */
#define DHCP_MAGIC                  0x63825363
#define LIBNET_BOOTP_MIN_LEN        0x12c
#define LIBNET_DHCP_PAD             0x00
#define LIBNET_DHCP_SUBNETMASK      0x01
#define LIBNET_DHCP_TIMEOFFSET      0x02
#define LIBNET_DHCP_ROUTER          0x03
#define LIBNET_DHCP_TIMESERVER      0x04
#define LIBNET_DHCP_NAMESERVER      0x05
#define LIBNET_DHCP_DNS             0x06
#define LIBNET_DHCP_LOGSERV         0x07
#define LIBNET_DHCP_COOKIESERV      0x08
#define LIBNET_DHCP_LPRSERV         0x09
#define LIBNET_DHCP_IMPSERV         0x0a
#define LIBNET_DHCP_RESSERV         0x0b
#define LIBNET_DHCP_HOSTNAME        0x0c
#define LIBNET_DHCP_BOOTFILESIZE    0x0d
#define LIBNET_DHCP_DUMPFILE        0x0e
#define LIBNET_DHCP_DOMAINNAME      0x0f
#define LIBNET_DHCP_SWAPSERV        0x10
#define LIBNET_DHCP_ROOTPATH        0x11
#define LIBNET_DHCP_EXTENPATH       0x12
#define LIBNET_DHCP_IPFORWARD       0x13
#define LIBNET_DHCP_SRCROUTE        0x14
#define LIBNET_DHCP_POLICYFILTER    0x15
#define LIBNET_DHCP_MAXASMSIZE      0x16
#define LIBNET_DHCP_IPTTL           0x17
#define LIBNET_DHCP_MTUTIMEOUT      0x18
#define LIBNET_DHCP_MTUTABLE        0x19
#define LIBNET_DHCP_MTUSIZE         0x1a
#define LIBNET_DHCP_LOCALSUBNETS    0x1b
#define LIBNET_DHCP_BROADCASTADDR   0x1c
#define LIBNET_DHCP_DOMASKDISCOV    0x1d
#define LIBNET_DHCP_MASKSUPPLY      0x1e
#define LIBNET_DHCP_DOROUTEDISC     0x1f
#define LIBNET_DHCP_ROUTERSOLICIT   0x20
#define LIBNET_DHCP_STATICROUTE     0x21
#define LIBNET_DHCP_TRAILERENCAP    0x22
#define LIBNET_DHCP_ARPTIMEOUT      0x23
#define LIBNET_DHCP_ETHERENCAP      0x24
#define LIBNET_DHCP_TCPTTL          0x25
#define LIBNET_DHCP_TCPKEEPALIVE    0x26
#define LIBNET_DHCP_TCPALIVEGARBAGE 0x27
#define LIBNET_DHCP_NISDOMAIN       0x28
#define LIBNET_DHCP_NISSERVERS      0x29
#define LIBNET_DHCP_NISTIMESERV     0x2a
#define LIBNET_DHCP_VENDSPECIFIC    0x2b
#define LIBNET_DHCP_NBNS            0x2c
#define LIBNET_DHCP_NBDD            0x2d
#define LIBNET_DHCP_NBTCPIP         0x2e
#define LIBNET_DHCP_NBTCPSCOPE      0x2f
#define LIBNET_DHCP_XFONT           0x30
#define LIBNET_DHCP_XDISPLAYMGR     0x31
#define LIBNET_DHCP_DISCOVERADDR    0x32
#define LIBNET_DHCP_LEASETIME       0x33
#define LIBNET_DHCP_OPTIONOVERLOAD  0x34
#define LIBNET_DHCP_MESSAGETYPE     0x35
#define LIBNET_DHCP_SERVIDENT       0x36
#define LIBNET_DHCP_PARAMREQUEST    0x37
#define LIBNET_DHCP_MESSAGE         0x38
#define LIBNET_DHCP_MAXMSGSIZE      0x39
#define LIBNET_DHCP_RENEWTIME       0x3a
#define LIBNET_DHCP_REBINDTIME      0x3b
#define LIBNET_DHCP_CLASSSID        0x3c
#define LIBNET_DHCP_CLIENTID        0x3d
#define LIBNET_DHCP_NISPLUSDOMAIN   0x40
#define LIBNET_DHCP_NISPLUSSERVERS  0x41
#define LIBNET_DHCP_MOBILEIPAGENT   0x44
#define LIBNET_DHCP_SMTPSERVER      0x45
#define LIBNET_DHCP_POP3SERVER      0x46
#define LIBNET_DHCP_NNTPSERVER      0x47
#define LIBNET_DHCP_WWWSERVER       0x48
#define LIBNET_DHCP_FINGERSERVER    0x49
#define LIBNET_DHCP_IRCSERVER       0x4a
#define LIBNET_DHCP_STSERVER        0x4b
#define LIBNET_DHCP_STDASERVER      0x4c
#define LIBNET_DHCP_END             0xff

#define LIBNET_DHCP_MSGDISCOVER     0x01
#define LIBNET_DHCP_MSGOFFER        0x02
#define LIBNET_DHCP_MSGREQUEST      0x03
#define LIBNET_DHCP_MSGDECLINE      0x04
#define LIBNET_DHCP_MSGACK          0x05
#define LIBNET_DHCP_MSGNACK         0x06
#define LIBNET_DHCP_MSGRELEASE      0x07
#define LIBNET_DHCP_MSGINFORM       0x08
};


/*
 *  Base DNSv4 header
 *  Domain Name System
 *  Base header size: 12 bytes
 */
struct libnet_dnsv4_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 */
};


/*
 *  Ethernet II header
 *  Static header size: 14 bytes
 */
struct libnet_ethernet_hdr
{
    u_char  ether_dhost[ETHER_ADDR_LEN];/* destination ethernet address */
    u_char  ether_shost[ETHER_ADDR_LEN];/* source ethernet address */
    u_short ether_type;                 /* protocol */
};

#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 */

struct libnet_ether_addr
{
    u_char  ether_addr_octet[6];        /* Ethernet address */
};


/*
 *  IPv4 header
 *  Internet Protocol, version 4
 *  Static header size: 20 bytes
 */
struct libnet_ipv4_hdr
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -