decode.h
来自「基于linux下的故障录波前置程序」· C头文件 代码 · 共 1,172 行 · 第 1/3 页
H
1,172 行
#define ICMP_HOST_UNKNOWN 7#define ICMP_HOST_ISOLATED 8#define ICMP_PKT_FILTERED_NET 9#define ICMP_PKT_FILTERED_HOST 10#define ICMP_NET_UNR_TOS 11#define ICMP_HOST_UNR_TOS 12#define ICMP_PKT_FILTERED 13 /* Packet filtered */#define ICMP_PREC_VIOLATION 14 /* Precedence violation */#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */#define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate * value */#define ICMP_REDIR_NET 0#define ICMP_REDIR_HOST 1#define ICMP_REDIR_TOS_NET 2#define ICMP_REDIR_TOS_HOST 3#define ICMP_TIMEOUT_TRANSIT 0#define ICMP_TIMEOUT_REASSY 1#define ICMP_PARAM_BADIPHDR 0#define ICMP_PARAM_OPTMISSING 1#define ICMP_PARAM_BAD_LENGTH 2/* ip option type codes */#ifndef IPOPT_EOL #define IPOPT_EOL 0x00#endif#ifndef IPOPT_NOP #define IPOPT_NOP 0x01#endif#ifndef IPOPT_RR #define IPOPT_RR 0x07#endif#ifndef IPOPT_RTRALT #define IPOPT_RTRALT 0x14#endif#ifndef IPOPT_TS #define IPOPT_TS 0x44#endif#ifndef IPOPT_SECURITY #define IPOPT_SECURITY 0x82#endif#ifndef IPOPT_LSRR #define IPOPT_LSRR 0x83#endif#ifndef IPOPT_LSRR_E #define IPOPT_LSRR_E 0x84#endif#ifndef IPOPT_SATID #define IPOPT_SATID 0x88#endif#ifndef IPOPT_SSRR #define IPOPT_SSRR 0x89#endif/* tcp option codes */#define TOPT_EOL 0x00#define TOPT_NOP 0x01#define TOPT_MSS 0x02#define TOPT_WS 0x03#define TOPT_TS 0x08#ifndef TCPOPT_WSCALE #define TCPOPT_WSCALE 3 /* window scale factor (rfc1072) */#endif#ifndef TCPOPT_SACKOK #define TCPOPT_SACKOK 4 /* selective ack ok (rfc1072) */#endif#ifndef TCPOPT_SACK #define TCPOPT_SACK 5 /* selective ack (rfc1072) */#endif#ifndef TCPOPT_ECHO #define TCPOPT_ECHO 6 /* echo (rfc1072) */#endif#ifndef TCPOPT_ECHOREPLY #define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */#endif#ifndef TCPOPT_TIMESTAMP #define TCPOPT_TIMESTAMP 8 /* timestamps (rfc1323) */#endif#ifndef TCPOPT_CC #define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */#endif#ifndef TCPOPT_CCNEW #define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */#endif#ifndef TCPOPT_CCECHO #define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */#endif#define EXTRACT_16BITS(p) ((u_short) ntohs (*(u_short *)(p)))#ifdef WORDS_MUSTALIGN#if defined(__GNUC__)/* force word-aligned ntohl parameter */ #define EXTRACT_32BITS(p) ({ u_int32_t __tmp; memmove(&__tmp, (p), sizeof(u_int32_t)); (u_int32_t) ntohl(__tmp);})#endif /* __GNUC__ */#else/* allows unaligned ntohl parameter - dies w/SIGBUS on SPARCs */ #define EXTRACT_32BITS(p) ((u_int32_t) ntohl (*(u_int32_t *)(p)))#endif /* WORDS_MUSTALIGN *//* packet status flags */#define PKT_REBUILT_FRAG 0x00000001 /* is a rebuilt fragment */#define PKT_REBUILT_STREAM 0x00000002 /* is a rebuilt stream */#define PKT_STREAM_UNEST_UNI 0x00000004 /* is from an unestablished stream and * we've only seen traffic in one * direction */#define PKT_STREAM_UNEST_BI 0x00000008 /* is from an unestablished stream and * we've seen traffic in both * directions */#define PKT_STREAM_EST 0x00000010 /* is from an established stream */#define PKT_ECN 0x00000020 /* this is ECN traffic */#define PKT_FROM_SERVER 0x00000040 /* this packet came from the server side of a connection (TCP) */#define PKT_FROM_CLIENT 0x00000080 /* this packet came from the client side of a connection (TCP) */#define PKT_HTTP_DECODE 0x00000100 /* this packet has normalized http */#define PKT_FRAG_ALERTED 0x00000200 /* this packet has been alerted by defrag */#define PKT_STREAM_INSERT 0x00000400 /* this packet has been inserted into stream4 */#define PKT_ALT_DECODE 0x00000800 /* this packet has been normalized by telnet (only set when we must look at an alernative buffer) */#define PKT_OBFUSCATED 0x40000000 /* this packet has been obfuscated */#define PKT_LOGGED 0x80000000 /* this packet has been logged *//* D A T A S T R U C T U R E S *********************************************//* Start Token Ring Data Structures */#ifdef WIN32 /* Visual C++ pragma to disable warning messages about nonstandard bit field type */ #pragma warning( disable : 4214 ) #endif/* LLC structure */typedef struct _Trh_llc{ u_int8_t dsap; u_int8_t ssap; u_int8_t protid[3]; u_int16_t ethertype;} Trh_llc;/* RIF structure * Linux/tcpdump patch defines tokenring header in dump way, since not * every tokenring header with have RIF data... we define it separately, and * a bit more split up */#ifdef WIN32 /* Visual C++ pragma to disable warning messages about nonstandard bit field type */ #pragma warning( disable : 4214 ) #endif/* These are macros to use the bitlevel accesses in the Trh_Mr header they haven't been tested and they aren't used much so here is a listing of what used to be there #if defined(WORDS_BIGENDIAN) u_int16_t bcast:3, len:5, dir:1, lf:3, res:4; #else u_int16_t len:5, length of RIF field, including RC itself bcast:3, broadcast indicator res:4, reserved lf:3, largest frame size dir:1; direction*/#define TRH_MR_BCAST(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0xe000) >> 13)#define TRH_MR_LEN(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x1F00) >> 8)#define TRH_MR_DIR(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0080) >> 8)#define TRH_MR_LF(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0070) >> 7)#define TRH_MR_RES(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x000F))typedef struct _Trh_mr{ u_int16_t bcast_len_dir_lf_res; /* broadcast/res/framesize/direction */ u_int16_t rseg[8];} Trh_mr;#ifdef WIN32 /* Visual C++ pragma to enable warning messages about nonstandard bit field type */ #pragma warning( default : 4214 )#endiftypedef struct _Trh_hdr{ u_int8_t ac; /* access control field */ u_int8_t fc; /* frame control field */ u_int8_t daddr[TR_ALEN]; /* src address */ u_int8_t saddr[TR_ALEN]; /* dst address */} Trh_hdr;#ifdef WIN32 /* Visual C++ pragma to enable warning messages about nonstandard bit field type */ #pragma warning( default : 4214 )#endif/* End Token Ring Data Structures *//* Start FDDI Data Structures *//* FDDI header is always this: -worm5er */typedef struct _Fddi_hdr{ u_int8_t fc; /* frame control field */ u_int8_t daddr[FDDI_ALEN]; /* src address */ u_int8_t saddr[FDDI_ALEN]; /* dst address */} Fddi_hdr;/* splitting the llc up because of variable lengths of the LLC -worm5er */typedef struct _Fddi_llc_saps{ u_int8_t dsap; u_int8_t ssap;} Fddi_llc_saps;/* I've found sna frames have two addition bytes after the llc saps -worm5er */typedef struct _Fddi_llc_sna{ u_int8_t ctrl_fld[2];} Fddi_llc_sna;/* I've also found other frames that seem to have only one byte... We're onlyreally intersted in the IP data so, until we want other, I'm going to saythe data is one byte beyond this frame... -worm5er */typedef struct _Fddi_llc_other{ u_int8_t ctrl_fld[1];} Fddi_llc_other;/* Just like TR the ip/arp data is setup as such: -worm5er */typedef struct _Fddi_llc_iparp{ u_int8_t ctrl_fld; u_int8_t protid[3]; u_int16_t ethertype;} Fddi_llc_iparp;/* End FDDI Data Structures *//* 'Linux cooked captures' data * (taken from tcpdump source). */#define SLL_HDR_LEN 16 /* total header length */#define SLL_ADDRLEN 8 /* length of address field */typedef struct _SLLHdr { u_int16_t sll_pkttype; /* packet type */ u_int16_t sll_hatype; /* link-layer address type */ u_int16_t sll_halen; /* link-layer address length */ u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ u_int16_t sll_protocol; /* protocol */} SLLHdr;/* OpenBSD pf firewall pflog0 header * (information from pf source in kernel) * the rule, reason, and action codes tell why the firewall dropped it -fleck */typedef struct _Pflog_hdr{ u_int32_t af; char intf[IFNAMSIZ]; short rule; u_short reason; u_short action; u_short dir;} PflogHdr;#define PFLOG_HDRLEN sizeof(struct _Pflog_hdr)/* * ssl_pkttype values. */#define LINUX_SLL_HOST 0#define LINUX_SLL_BROADCAST 1#define LINUX_SLL_MULTICAST 2#define LINUX_SLL_OTHERHOST 3#define LINUX_SLL_OUTGOING 4/* ssl protocol values */#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */#ifdef WIN32 /* Visual C++ pragma to disable warning messages * about nonstandard bit field type */ #pragma warning( disable : 4214 ) #endif#define VTH_PRIORITY(vh) ((ntohs((vh)->vth_pri_cfi_vlan) & 0xe000) >> 13)#define VTH_CFI(vh) ((ntohs((vh)->vth_pri_cfi_vlan & 0x0100) >> 12))#define VTH_VLAN(vh) ((ntohs((vh)->vth_pri_cfi_vlan) & 0x0FFF))typedef struct _VlanTagHdr{ u_int16_t vth_pri_cfi_vlan; u_int16_t vth_proto; /* protocol field... */} VlanTagHdr;#ifdef WIN32 /* Visual C++ pragma to enable warning messages about nonstandard bit field type */ #pragma warning( default : 4214 )#endiftypedef struct _EthLlc{ u_int8_t dsap; u_int8_t ssap;} EthLlc;typedef struct _EthLlcOther{ u_int8_t ctrl; u_int8_t org_code[3]; u_int16_t proto_id;} EthLlcOther;/* * Ethernet header */typedef struct _EtherHdr{ u_int8_t ether_dst[6]; u_int8_t ether_src[6]; u_int16_t ether_type;} EtherHdr;/* * Wireless Header (IEEE 802.11) */typedef struct _WifiHdr{ u_int16_t frame_control; u_int16_t duration_id; u_int8_t addr1[6]; u_int8_t addr2[6]; u_int8_t addr3[6]; u_int16_t seq_control; u_int8_t addr4[6];} WifiHdr;/* Can't add any fields not in the real header here because of how the decoder uses structure overlaying */#ifdef WIN32 /* Visual C++ pragma to disable warning messages * about nonstandard bit field type */ #pragma warning( disable : 4214 ) #endif/* tcpdump shows us the way to cross platform compatibility */#define IP_VER(iph) (((iph)->ip_verhl & 0xf0) >> 4)#define IP_HLEN(iph) ((iph)->ip_verhl & 0x0f)/* we need to change them as well as get them */#define SET_IP_VER(iph, value) ((iph)->ip_verhl = (((iph)->ip_verhl & 0x0f) | (value << 4)))
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?