00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __DECODE_H__
00023 #define __DECODE_H__
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include "config.h"
00030 #endif
00031
00032 #include <sys/types.h>
00033 #include <pcap.h>
00034
00035 #ifndef WIN32
00036 #include <sys/socket.h>
00037 #include <netinet/in.h>
00038 #include <net/if.h>
00039 #else
00040 #include <netinet/in_systm.h>
00041 #include "libnet/IPExport.h"
00042 #ifndef IFNAMSIZ
00043 #define IFNAMESIZ MAX_ADAPTER_NAME
00044 #endif
00045 #endif
00046
00047 #include "stream.h"
00048
00049
00050
00051 #define ETHERNET_MTU 1500
00052 #define ETHERNET_TYPE_IP 0x0800
00053 #define ETHERNET_TYPE_ARP 0x0806
00054 #define ETHERNET_TYPE_REVARP 0x8035
00055 #define ETHERNET_TYPE_EAPOL 0x888e
00056 #define ETHERNET_TYPE_IPV6 0x86dd
00057 #define ETHERNET_TYPE_IPX 0x8137
00058 #define ETHERNET_TYPE_PPPoE_DISC 0x8863
00059 #define ETHERNET_TYPE_PPPoE_SESS 0x8864
00060 #define ETHERNET_TYPE_8021Q 0x8100
00061 #define ETHERNET_TYPE_LOOP 0x9000
00062
00063 #define ETH_DSAP_SNA 0x08
00064 #define ETH_SSAP_SNA 0x00
00065 #define ETH_DSAP_STP 0x42
00066 #define ETH_SSAP_STP 0x42
00067 #define ETH_DSAP_IP 0xaa
00068 #define ETH_SSAP_IP 0xaa
00069
00070 #define ETH_ORG_CODE_ETHR 0x000000
00071 #define ETH_ORG_CODE_CDP 0x00000c
00072
00073 #define ETHERNET_HEADER_LEN 14
00074 #define ETHERNET_MAX_LEN_ENCAP 1518
00075 #define PPPOE_HEADER_LEN 20
00076 #define MINIMAL_TOKENRING_HEADER_LEN 22
00077 #define MINIMAL_IEEE80211_HEADER_LEN 10
00078 #define IEEE802_11_DATA_HDR_LEN 24
00079 #define TR_HLEN MINIMAL_TOKENRING_HEADER_LEN
00080 #define TOKENRING_LLC_LEN 8
00081 #define SLIP_HEADER_LEN 16
00082
00083
00084
00085 #define WLAN_TYPE_MGMT_ASREQ 0x0
00086 #define WLAN_TYPE_MGMT_ASRES 0x10
00087 #define WLAN_TYPE_MGMT_REREQ 0x20
00088 #define WLAN_TYPE_MGMT_RERES 0x30
00089 #define WLAN_TYPE_MGMT_PRREQ 0x40
00090 #define WLAN_TYPE_MGMT_PRRES 0x50
00091 #define WLAN_TYPE_MGMT_BEACON 0x80
00092 #define WLAN_TYPE_MGMT_ATIM 0x90
00093 #define WLAN_TYPE_MGMT_DIS 0xa0
00094 #define WLAN_TYPE_MGMT_AUTH 0xb0
00095 #define WLAN_TYPE_MGMT_DEAUTH 0xc0
00096
00097 #define WLAN_TYPE_CONT_PS 0xa4
00098 #define WLAN_TYPE_CONT_RTS 0xb4
00099 #define WLAN_TYPE_CONT_CTS 0xc4
00100 #define WLAN_TYPE_CONT_ACK 0xd4
00101 #define WLAN_TYPE_CONT_CFE 0xe4
00102 #define WLAN_TYPE_CONT_CFACK 0xf4
00103
00104 #define WLAN_TYPE_DATA_DATA 0x08
00105 #define WLAN_TYPE_DATA_DTCFACK 0x18
00106 #define WLAN_TYPE_DATA_DTCFPL 0x28
00107 #define WLAN_TYPE_DATA_DTACKPL 0x38
00108 #define WLAN_TYPE_DATA_NULL 0x48
00109 #define WLAN_TYPE_DATA_CFACK 0x58
00110 #define WLAN_TYPE_DATA_CFPL 0x68
00111 #define WLAN_TYPE_DATA_ACKPL 0x78
00112
00113
00114
00115 #define WLAN_FLAG_TODS 0x0100
00116 #define WLAN_FLAG_FROMDS 0x0200
00117 #define WLAN_FLAG_FRAG 0x0400
00118 #define WLAN_FLAG_RETRY 0x0800
00119 #define WLAN_FLAG_PWRMGMT 0x1000
00120 #define WLAN_FLAG_MOREDAT 0x2000
00121 #define WLAN_FLAG_WEP 0x4000
00122 #define WLAN_FLAG_ORDER 0x8000
00123
00124
00125 #define EAPOL_TYPE_EAP 0x00
00126 #define EAPOL_TYPE_START 0x01
00127 #define EAPOL_TYPE_LOGOFF 0x02
00128 #define EAPOL_TYPE_KEY 0x03
00129 #define EAPOL_TYPE_ASF 0x04
00130
00131
00132 #define EAP_CODE_REQUEST 0x01
00133 #define EAP_CODE_RESPONSE 0x02
00134 #define EAP_CODE_SUCCESS 0x03
00135 #define EAP_CODE_FAILURE 0x04
00136
00137 #define EAP_TYPE_IDENTITY 0x01
00138 #define EAP_TYPE_NOTIFY 0x02
00139 #define EAP_TYPE_NAK 0x03
00140 #define EAP_TYPE_MD5 0x04
00141 #define EAP_TYPE_OTP 0x05
00142 #define EAP_TYPE_GTC 0x06
00143 #define EAP_TYPE_TLS 0x0d
00144
00145
00146 #define CHDLC_HEADER_LEN 4
00147 #define CHDLC_ADDR_UNICAST 0x0f
00148 #define CHDLC_ADDR_MULTICAST 0x8f
00149 #define CHDLC_ADDR_BROADCAST 0xff
00150 #define CHDLC_CTRL_UNNUMBERED 0x03
00151
00152
00153
00154
00155
00156
00157
00158 struct ppp_header {
00159 unsigned char address;
00160 unsigned char control;
00161 unsigned short protocol;
00162 };
00163
00164 #ifndef PPP_HDRLEN
00165 #define PPP_HDRLEN sizeof(struct ppp_header)
00166 #endif
00167
00168 #define PPP_IP 0x0021
00169 #define PPP_VJ_COMP 0x002d
00170 #define PPP_VJ_UCOMP 0x002f
00171 #define PPP_IPX 0x002b
00172
00173
00174 #ifndef PPP_MTU
00175 #define PPP_MTU 1500
00176 #endif
00177
00178
00179 #define NULL_HDRLEN 4
00180
00181
00182 struct enc_header {
00183 u_int32_t af;
00184 u_int32_t spi;
00185 u_int32_t flags;
00186 };
00187 #define ENC_HEADER_LEN 12
00188
00189
00190 #define IP_HEADER_LEN 20
00191 #define TCP_HEADER_LEN 20
00192 #define UDP_HEADER_LEN 8
00193 #define ICMP_HEADER_LEN 4
00194
00195 #define IP_OPTMAX 40
00196 #define TCP_OPTLENMAX 40
00197
00198 #ifndef IP_MAXPACKET
00199 #define IP_MAXPACKET 65535
00200 #endif
00201
00202 #define TH_FIN 0x01
00203 #define TH_SYN 0x02
00204 #define TH_RST 0x04
00205 #define TH_PUSH 0x08
00206 #define TH_ACK 0x10
00207 #define TH_URG 0x20
00208 #define TH_RES2 0x40
00209 #define TH_RES1 0x80
00210 #define TH_NORESERVED (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG)
00211
00212
00213
00214
00215
00216
00217 #define TCPOPT_EOL 0
00218 #define TCPOLEN_EOL 1
00219
00220 #define TCPOPT_NOP 1
00221 #define TCPOLEN_NOP 1
00222
00223 #define TCPOPT_MAXSEG 2
00224 #define TCPOLEN_MAXSEG 4
00225
00226 #define TCPOPT_WSCALE 3
00227 #define TCPOLEN_WSCALE 3
00228
00229 #define TCPOPT_SACKOK 4
00230 #define TCPOLEN_SACKOK 2
00231
00232 #define TCPOPT_SACK 5
00233
00234 #define TCPOPT_ECHO 6
00235 #define TCPOLEN_ECHO 6
00236
00237 #define TCPOPT_ECHOREPLY 7
00238 #define TCPOLEN_ECHOREPLY 6
00239
00240 #define TCPOPT_TIMESTAMP 8
00241 #define TCPOLEN_TIMESTAMP 10
00242
00243 #define TCPOPT_PARTIAL_PERM 9
00244 #define TCPOLEN_PARTIAL_PERM 2
00245
00246 #define TCPOPT_PARTIAL_SVC 10
00247 #define TCPOLEN_PARTIAL_SVC 3
00248
00249
00250 #define TCPOPT_CC 11
00251 #define TCPOPT_CC_NEW 12
00252 #define TCPOPT_CC_ECHO 13
00253 #define TCPOLEN_CC 6
00254 #define TCPOLEN_CC_NEW 6
00255 #define TCPOLEN_CC_ECHO 6
00256
00257 #define TCPOPT_ALTCSUM 15
00258 #define TCPOPT_SKEETER 16
00259 #define TCPOPT_BUBBA 17
00260
00261 #define TCPOPT_TRAILER_CSUM 18
00262 #define TCPOLEN_TRAILER_CSUM 3
00263
00264 #define TCPOPT_MD5SIG 19
00265 #define TCPOLEN_MD5SIG 18
00266
00267
00268 #define TCPOPT_SCPS 20
00269 #define TCPOPT_SELNEGACK 21
00270 #define TCPOPT_RECORDBOUND 22
00271 #define TCPOPT_CORRUPTION 23
00272
00273 #define TCPOPT_SNAP 24
00274 #define TCPOPT_UNASSIGNED 25
00275 #define TCPOPT_COMPRESSION 26
00276
00277
00278 #define TCP_OPT_TRUNC -1
00279 #define TCP_OPT_BADLEN -2
00280
00281
00282 #define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2)
00283 #define TCPOPT_TSTAMP_HDR \
00284 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
00285
00286
00287
00288
00289
00290
00291
00292
00293 #ifndef TCP_MSS
00294 #define TCP_MSS 512
00295 #endif
00296
00297 #ifndef TCP_MAXWIN
00298 #define TCP_MAXWIN 65535
00299 #endif
00300
00301 #ifndef TCP_MAX_WINSHIFT
00302 #define TCP_MAX_WINSHIFT 14
00303 #endif
00304
00305
00306
00307
00308 #ifndef TCP_NODELAY
00309 #define TCP_NODELAY 0x01
00310 #endif
00311
00312 #ifndef TCP_MAXSEG
00313 #define TCP_MAXSEG 0x02
00314 #endif
00315
00316 #define SOL_TCP 6
00317
00318
00319
00320 #define L2TP_PORT 1701
00321 #define DHCP_CLIENT_PORT 68
00322 #define DHCP_SERVER_PORT 67
00323
00324
00325 #ifndef IRIX
00326 #define SNAPLEN 1514
00327 #else
00328 #define SNAPLEN 1500
00329 #endif
00330
00331 #define MIN_SNAPLEN 68
00332 #define PROMISC 1
00333 #define READ_TIMEOUT 500
00334
00335
00336 #define TR_ALEN 6
00337 #define IPARP_SAP 0xaa
00338
00339 #define AC 0x10
00340 #define LLC_FRAME 0x40
00341
00342 #define TRMTU 2000
00343 #define TR_RII 0x80
00344 #define TR_RCF_DIR_BIT 0x80
00345 #define TR_RCF_LEN_MASK 0x1f00
00346 #define TR_RCF_BROADCAST 0x8000
00347 #define TR_RCF_LIMITED_BROADCAST 0xC000
00348 #define TR_RCF_FRAME2K 0x20
00349 #define TR_RCF_BROADCAST_MASK 0xC000
00350
00351
00352
00353 #define FDDI_ALLC_LEN 13
00354 #define FDDI_ALEN 6
00355 #define FDDI_MIN_HLEN (FDDI_ALLC_LEN + 3)
00356
00357 #define FDDI_DSAP_SNA 0x08
00358 #define FDDI_SSAP_SNA 0x00
00359 #define FDDI_DSAP_STP 0x42
00360 #define FDDI_SSAP_STP 0x42
00361 #define FDDI_DSAP_IP 0xaa
00362 #define FDDI_SSAP_IP 0xaa
00363
00364 #define FDDI_ORG_CODE_ETHR 0x000000
00365 #define FDDI_ORG_CODE_CDP 0x00000c
00366
00367
00368 #define ETHERNET_TYPE_CDP 0x2000
00369
00370
00371 #define ARPOP_REQUEST 1
00372 #define ARPOP_REPLY 2
00373 #define ARPOP_RREQUEST 3
00374 #define ARPOP_RREPLY 4
00375
00376
00377 #define PPPoE_CODE_SESS 0x00
00378 #define PPPoE_CODE_PADI 0x09
00379 #define PPPoE_CODE_PADO 0x07
00380 #define PPPoE_CODE_PADR 0x19
00381 #define PPPoE_CODE_PADS 0x65
00382 #define PPPoE_CODE_PADT 0xa7
00383
00384
00385 #define PPPoE_TAG_END_OF_LIST 0x0000
00386 #define PPPoE_TAG_SERVICE_NAME 0x0101
00387 #define PPPoE_TAG_AC_NAME 0x0102
00388 #define PPPoE_TAG_HOST_UNIQ 0x0103
00389 #define PPPoE_TAG_AC_COOKIE 0x0104
00390 #define PPPoE_TAG_VENDOR_SPECIFIC 0x0105
00391 #define PPPoE_TAG_RELAY_SESSION_ID 0x0110
00392 #define PPPoE_TAG_SERVICE_NAME_ERROR 0x0201
00393 #define PPPoE_TAG_AC_SYSTEM_ERROR 0x0202
00394 #define PPPoE_TAG_GENERIC_ERROR 0x0203
00395
00396
00397 #define ICMP_ECHOREPLY 0
00398 #define ICMP_DEST_UNREACH 3
00399 #define ICMP_SOURCE_QUENCH 4
00400 #define ICMP_REDIRECT 5
00401 #define ICMP_ECHO 8
00402 #define ICMP_ROUTER_ADVERTISE 9
00403 #define ICMP_ROUTER_SOLICIT 10
00404 #define ICMP_TIME_EXCEEDED 11
00405 #define ICMP_PARAMETERPROB 12
00406 #define ICMP_TIMESTAMP 13
00407 #define ICMP_TIMESTAMPREPLY 14
00408 #define ICMP_INFO_REQUEST 15
00409 #define ICMP_INFO_REPLY 16
00410 #define ICMP_ADDRESS 17
00411 #define ICMP_ADDRESSREPLY 18
00412 #define NR_ICMP_TYPES 18
00413
00414
00415 #define ICMP_NET_UNREACH 0
00416 #define ICMP_HOST_UNREACH 1
00417 #define ICMP_PROT_UNREACH 2
00418 #define ICMP_PORT_UNREACH 3
00419 #define ICMP_FRAG_NEEDED 4
00420 #define ICMP_SR_FAILED 5
00421 #define ICMP_NET_UNKNOWN 6
00422 #define ICMP_HOST_UNKNOWN 7
00423 #define ICMP_HOST_ISOLATED 8
00424 #define ICMP_PKT_FILTERED_NET 9
00425 #define ICMP_PKT_FILTERED_HOST 10
00426 #define ICMP_NET_UNR_TOS 11
00427 #define ICMP_HOST_UNR_TOS 12
00428 #define ICMP_PKT_FILTERED 13
00429 #define ICMP_PREC_VIOLATION 14
00430 #define ICMP_PREC_CUTOFF 15
00431 #define NR_ICMP_UNREACH 15
00432
00433
00434 #define ICMP_REDIR_NET 0
00435 #define ICMP_REDIR_HOST 1
00436 #define ICMP_REDIR_TOS_NET 2
00437 #define ICMP_REDIR_TOS_HOST 3
00438
00439 #define ICMP_TIMEOUT_TRANSIT 0
00440 #define ICMP_TIMEOUT_REASSY 1
00441
00442 #define ICMP_PARAM_BADIPHDR 0
00443 #define ICMP_PARAM_OPTMISSING 1
00444 #define ICMP_PARAM_BAD_LENGTH 2
00445
00446
00447 #ifndef IPOPT_EOL
00448 #define IPOPT_EOL 0x00
00449 #endif
00450
00451 #ifndef IPOPT_NOP
00452 #define IPOPT_NOP 0x01
00453 #endif
00454
00455 #ifndef IPOPT_RR
00456 #define IPOPT_RR 0x07
00457 #endif
00458
00459 #ifndef IPOPT_RTRALT
00460 #define IPOPT_RTRALT 0x14
00461 #endif
00462
00463 #ifndef IPOPT_TS
00464 #define IPOPT_TS 0x44
00465 #endif
00466
00467 #ifndef IPOPT_SECURITY
00468 #define IPOPT_SECURITY 0x82
00469 #endif
00470
00471 #ifndef IPOPT_LSRR
00472 #define IPOPT_LSRR 0x83
00473 #endif
00474
00475 #ifndef IPOPT_LSRR_E
00476 #define IPOPT_LSRR_E 0x84
00477 #endif
00478
00479 #ifndef IPOPT_SATID
00480 #define IPOPT_SATID 0x88
00481 #endif
00482
00483 #ifndef IPOPT_SSRR
00484 #define IPOPT_SSRR 0x89
00485 #endif
00486
00487
00488
00489
00490 #define TOPT_EOL 0x00
00491 #define TOPT_NOP 0x01
00492 #define TOPT_MSS 0x02
00493 #define TOPT_WS 0x03
00494 #define TOPT_TS 0x08
00495 #ifndef TCPOPT_WSCALE
00496 #define TCPOPT_WSCALE 3
00497 #endif
00498 #ifndef TCPOPT_SACKOK
00499 #define TCPOPT_SACKOK 4
00500 #endif
00501 #ifndef TCPOPT_SACK
00502 #define TCPOPT_SACK 5
00503 #endif
00504 #ifndef TCPOPT_ECHO
00505 #define TCPOPT_ECHO 6
00506 #endif
00507 #ifndef TCPOPT_ECHOREPLY
00508 #define TCPOPT_ECHOREPLY 7
00509 #endif
00510 #ifndef TCPOPT_TIMESTAMP
00511 #define TCPOPT_TIMESTAMP 8
00512 #endif
00513 #ifndef TCPOPT_CC
00514 #define TCPOPT_CC 11
00515 #endif
00516 #ifndef TCPOPT_CCNEW
00517 #define TCPOPT_CCNEW 12
00518 #endif
00519 #ifndef TCPOPT_CCECHO
00520 #define TCPOPT_CCECHO 13
00521 #endif
00522
00523 #define EXTRACT_16BITS(p) ((u_short) ntohs (*(u_short *)(p)))
00524
00525 #ifdef WORDS_MUSTALIGN
00526
00527 #if defined(__GNUC__)
00528
00529 #define EXTRACT_32BITS(p) ({ u_int32_t __tmp; memmove(&__tmp, (p), sizeof(u_int32_t)); (u_int32_t) ntohl(__tmp);})
00530 #endif
00531
00532 #else
00533
00534
00535 #define EXTRACT_32BITS(p) ((u_int32_t) ntohl (*(u_int32_t *)(p)))
00536
00537 #endif
00538
00539
00540 #define PKT_REBUILT_FRAG 0x00000001
00541 #define PKT_REBUILT_STREAM 0x00000002
00542 #define PKT_STREAM_UNEST_UNI 0x00000004
00543
00544
00545
00546 #define PKT_STREAM_UNEST_BI 0x00000008
00547
00548
00549
00550 #define PKT_STREAM_EST 0x00000010
00551 #define PKT_ECN 0x00000020
00552 #define PKT_FROM_SERVER 0x00000040
00553
00554 #define PKT_FROM_CLIENT 0x00000080
00555
00556 #define PKT_HTTP_DECODE 0x00000100
00557 #define PKT_FRAG_ALERTED 0x00000200
00558
00559 #define PKT_STREAM_INSERT 0x00000400
00560 #define PKT_ALT_DECODE 0x00000800
00561
00562
00563 #define PKT_STREAM_TWH 0x00001000
00564 #define PKT_IGNORE_PORT 0x00002000
00565 #define PKT_INLINE_DROP 0x20000000
00566 #define PKT_OBFUSCATED 0x40000000
00567 #define PKT_LOGGED 0x80000000
00568
00569
00570
00571
00572
00573 #ifdef _MSC_VER
00574
00575 #pragma warning( disable : 4214 )
00576 #endif
00577
00578
00579 typedef struct _Trh_llc
00580 {
00581 u_int8_t dsap;
00582 u_int8_t ssap;
00583 u_int8_t protid[3];
00584 u_int16_t ethertype;
00585 } Trh_llc;
00586
00587
00588
00589
00590
00591
00592
00593 #ifdef _MSC_VER
00594
00595 #pragma warning( disable : 4214 )
00596 #endif
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614 #define TRH_MR_BCAST(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0xe000) >> 13)
00615 #define TRH_MR_LEN(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x1F00) >> 8)
00616 #define TRH_MR_DIR(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0080) >> 8)
00617 #define TRH_MR_LF(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x0070) >> 7)
00618 #define TRH_MR_RES(trhmr) ((ntohs((trhmr)->bcast_len_dir_lf_res) & 0x000F))
00619
00620 typedef struct _Trh_mr
00621 {
00622 u_int16_t bcast_len_dir_lf_res;
00623 u_int16_t rseg[8];
00624 } Trh_mr;
00625 #ifdef _MSC_VER
00626
00627 #pragma warning( default : 4214 )
00628 #endif
00629
00630
00631 typedef struct _Trh_hdr
00632 {
00633 u_int8_t ac;
00634 u_int8_t fc;
00635 u_int8_t daddr[TR_ALEN];
00636 u_int8_t saddr[TR_ALEN];
00637 } Trh_hdr;
00638
00639 #ifdef WIN32
00640
00641 #pragma warning( default : 4214 )
00642 #endif
00643
00644
00645
00646
00647
00648
00649 typedef struct _Fddi_hdr
00650 {
00651 u_int8_t fc;
00652 u_int8_t daddr[FDDI_ALEN];
00653 u_int8_t saddr[FDDI_ALEN];
00654 } Fddi_hdr;
00655
00656
00657 typedef struct _Fddi_llc_saps
00658 {
00659 u_int8_t dsap;
00660 u_int8_t ssap;
00661 } Fddi_llc_saps;
00662
00663
00664 typedef struct _Fddi_llc_sna
00665 {
00666 u_int8_t ctrl_fld[2];
00667 } Fddi_llc_sna;
00668
00669
00670
00671
00672 typedef struct _Fddi_llc_other
00673 {
00674 u_int8_t ctrl_fld[1];
00675 } Fddi_llc_other;
00676
00677
00678 typedef struct _Fddi_llc_iparp
00679 {
00680 u_int8_t ctrl_fld;
00681 u_int8_t protid[3];
00682 u_int16_t ethertype;
00683 } Fddi_llc_iparp;
00684
00685
00686
00687
00688
00689
00690
00691
00692 #define SLL_HDR_LEN 16
00693 #define SLL_ADDRLEN 8
00694 typedef struct _SLLHdr {
00695 u_int16_t sll_pkttype;
00696 u_int16_t sll_hatype;
00697 u_int16_t sll_halen;
00698 u_int8_t sll_addr[SLL_ADDRLEN];
00699 u_int16_t sll_protocol;
00700 } SLLHdr;
00701
00702
00703
00704
00705
00706
00707
00708 typedef struct _OldPflog_hdr
00709 {
00710 u_int32_t af;
00711 char intf[IFNAMSIZ];
00712 short rule;
00713 u_short reason;
00714 u_short action;
00715 u_short dir;
00716 } OldPflogHdr;
00717
00718 #define OLDPFLOG_HDRLEN sizeof(struct _OldPflog_hdr)
00719
00720
00721
00722
00723
00724
00725 typedef struct _Pflog_hdr
00726 {
00727 int8_t length;
00728 sa_family_t af;
00729 u_int8_t action;
00730 u_int8_t reason;
00731 char ifname[IFNAMSIZ];
00732 char ruleset[16];
00733 u_int32_t rulenr;
00734 u_int32_t subrulenr;
00735 u_int8_t dir;
00736 u_int8_t pad[3];
00737 } PflogHdr;
00738
00739 #define PFLOG_HDRLEN sizeof(struct _Pflog_hdr)
00740
00741
00742
00743
00744
00745 #define LINUX_SLL_HOST 0
00746 #define LINUX_SLL_BROADCAST 1
00747 #define LINUX_SLL_MULTICAST 2
00748 #define LINUX_SLL_OTHERHOST 3
00749 #define LINUX_SLL_OUTGOING 4
00750
00751
00752
00753 #define LINUX_SLL_P_802_3 0x0001
00754 #define LINUX_SLL_P_802_2 0x0004
00755
00756
00757 #ifdef _MSC_VER
00758
00759
00760
00761 #pragma warning( disable : 4214 )
00762 #endif
00763
00764 #define VTH_PRIORITY(vh) ((ntohs((vh)->vth_pri_cfi_vlan) & 0xe000) >> 13)
00765 #define VTH_CFI(vh) ((ntohs((vh)->vth_pri_cfi_vlan) & 0x0100) >> 12)
00766 #define VTH_VLAN(vh) ((ntohs((vh)->vth_pri_cfi_vlan) & 0x0FFF))
00767
00768 typedef struct _VlanTagHdr
00769 {
00770 u_int16_t vth_pri_cfi_vlan;
00771 u_int16_t vth_proto;
00772 } VlanTagHdr;
00773 #ifdef _MSC_VER
00774
00775 #pragma warning( default : 4214 )
00776 #endif
00777
00778
00779 typedef struct _EthLlc
00780 {
00781 u_int8_t dsap;
00782 u_int8_t ssap;
00783 } EthLlc;
00784
00785 typedef struct _EthLlcOther
00786 {
00787 u_int8_t ctrl;
00788 u_int8_t org_code[3];
00789 u_int16_t proto_id;
00790 } EthLlcOther;
00791
00792
00793
00794
00795
00796
00797 typedef struct _EtherHdr
00798 {
00799 u_int8_t ether_dst[6];
00800 u_int8_t ether_src[6];
00801 u_int16_t ether_type;
00802
00803 } EtherHdr;
00804
00805
00806
00807
00808
00809 typedef struct _WifiHdr
00810 {
00811 u_int16_t frame_control;
00812 u_int16_t duration_id;
00813 u_int8_t addr1[6];
00814 u_int8_t addr2[6];
00815 u_int8_t addr3[6];
00816 u_int16_t seq_control;
00817 u_int8_t addr4[6];
00818 } WifiHdr;
00819
00820
00821
00822
00823 #ifdef _MSC_VER
00824
00825
00826
00827 #pragma warning( disable : 4214 )
00828 #endif
00829
00830
00831 #define IP_VER(iph) (((iph)->ip_verhl & 0xf0) >> 4)
00832 #define IP_HLEN(iph) ((iph)->ip_verhl & 0x0f)
00833
00834
00835 #define SET_IP_VER(iph, value) ((iph)->ip_verhl = (((iph)->ip_verhl & 0x0f) | (value << 4)))
00836 #define SET_IP_HLEN(iph, value) ((iph)->ip_verhl = (((iph)->ip_verhl & 0xf0) | (value & 0x0f)))
00837
00838 typedef struct _IPHdr
00839 {
00840 u_int8_t ip_verhl;
00841 u_int8_t ip_tos;
00842 u_int16_t ip_len;
00843 u_int16_t ip_id;
00844 u_int16_t ip_off;
00845 u_int8_t ip_ttl;
00846 u_int8_t ip_proto;
00847 u_int16_t ip_csum;
00848 struct in_addr ip_src;
00849 struct in_addr ip_dst;
00850 } IPHdr;
00851 #ifdef _MSC_VER
00852
00853 #pragma warning( default : 4214 )
00854 #endif
00855
00856
00857
00858
00859 #ifdef _MSC_VER
00860
00861
00862
00863 #pragma warning( disable : 4214 )
00864 #endif
00865
00866
00867
00868 #define TCP_OFFSET(tcph) (((tcph)->th_offx2 & 0xf0) >> 4)
00869 #define TCP_X2(tcph) ((tcph)->th_offx2 & 0x0f)
00870
00871
00872 #define SET_TCP_OFFSET(tcph, value) ((tcph)->th_offx2 = (((tcph)->th_offx2 & 0x0f) | (value << 4)))
00873 #define SET_TCP_X2(tcph, value) ((tcph)->th_offx2 = (((tcph)->th_offx2 & 0xf0) | (value & 0x0f)))
00874
00875 typedef struct _TCPHdr
00876 {
00877 u_int16_t th_sport;
00878 u_int16_t th_dport;
00879 u_int32_t th_seq;
00880 u_int32_t th_ack;
00881 u_int8_t th_offx2;
00882 u_int8_t th_flags;
00883 u_int16_t th_win;
00884 u_int16_t th_sum;
00885 u_int16_t th_urp;
00886
00887 } TCPHdr;
00888 #ifdef _MSC_VER
00889
00890
00891
00892 #pragma warning( default : 4214 )
00893 #endif
00894
00895
00896 typedef struct _UDPHdr
00897 {
00898 u_int16_t uh_sport;
00899 u_int16_t uh_dport;
00900 u_int16_t uh_len;
00901 u_int16_t uh_chk;
00902
00903 } UDPHdr;
00904
00905
00906 typedef struct _ICMPHdr
00907 {
00908 u_int8_t type;
00909 u_int8_t code;
00910 u_int16_t csum;
00911 union
00912 {
00913 u_int8_t pptr;
00914
00915 struct in_addr gwaddr;
00916
00917 struct idseq
00918 {
00919 u_int16_t id;
00920 u_int16_t seq;
00921 } idseq;
00922
00923 int sih_void;
00924
00925 struct pmtu
00926 {
00927 u_int16_t ipm_void;
00928 u_int16_t nextmtu;
00929 } pmtu;
00930
00931 struct rtradv
00932 {
00933 u_int8_t num_addrs;
00934 u_int8_t wpa;
00935 u_int16_t lifetime;
00936 } rtradv;
00937 } icmp_hun;
00938
00939 #define s_icmp_pptr icmp_hun.pptr
00940 #define s_icmp_gwaddr icmp_hun.gwaddr
00941 #define s_icmp_id icmp_hun.idseq.id
00942 #define s_icmp_seq icmp_hun.idseq.seq
00943 #define s_icmp_void icmp_hun.sih_void
00944 #define s_icmp_pmvoid icmp_hun.pmtu.ipm_void
00945 #define s_icmp_nextmtu icmp_hun.pmtu.nextmtu
00946 #define s_icmp_num_addrs icmp_hun.rtradv.num_addrs
00947 #define s_icmp_wpa icmp_hun.rtradv.wpa
00948 #define s_icmp_lifetime icmp_hun.rtradv.lifetime
00949
00950 union
00951 {
00952
00953 struct ts
00954 {
00955 u_int32_t otime;
00956 u_int32_t rtime;
00957 u_int32_t ttime;
00958 } ts;
00959
00960
00961 struct ih_ip
00962 {
00963 IPHdr *ip;
00964
00965 } ip;
00966
00967 struct ra_addr
00968 {
00969 u_int32_t addr;
00970 u_int32_t preference;
00971 } radv;
00972
00973 u_int32_t mask;
00974
00975 char data[1];
00976
00977 } icmp_dun;
00978 #define s_icmp_otime icmp_dun.ts.otime
00979 #define s_icmp_rtime icmp_dun.ts.rtime
00980 #define s_icmp_ttime icmp_dun.ts.ttime
00981 #define s_icmp_ip icmp_dun.ih_ip
00982 #define s_icmp_radv icmp_dun.radv
00983 #define s_icmp_mask icmp_dun.mask
00984 #define s_icmp_data icmp_dun.data
00985
00986 } ICMPHdr;
00987
00988
00989 typedef struct _ARPHdr
00990 {
00991 u_int16_t ar_hrd;
00992 u_int16_t ar_pro;
00993 u_int8_t ar_hln;
00994 u_int8_t ar_pln;
00995 u_int16_t ar_op;
00996 } ARPHdr;
00997
00998
00999
01000 typedef struct _EtherARP
01001 {
01002 ARPHdr ea_hdr;
01003 u_int8_t arp_sha[6];
01004 u_int8_t arp_spa[4];
01005 u_int8_t arp_tha[6];
01006 u_int8_t arp_tpa[4];
01007 } EtherARP;
01008
01009
01010 typedef struct _EtherEapol
01011 {
01012 u_int8_t version;
01013 u_int8_t eaptype;
01014 u_int16_t len;
01015 } EtherEapol;
01016
01017 typedef struct _EAPHdr
01018 {
01019 u_int8_t code;
01020 u_int8_t id;
01021 u_int16_t len;
01022 } EAPHdr;
01023
01024 typedef struct _EapolKey
01025 {
01026 u_int8_t type;
01027 u_int8_t length[2];
01028 u_int8_t counter[8];
01029 u_int8_t iv[16];
01030 u_int8_t index;
01031 u_int8_t sig[16];
01032 } EapolKey;
01033
01034 typedef struct _Options
01035 {
01036 u_int8_t code;
01037 u_int8_t len;
01038 u_int8_t *data;
01039 } Options;
01040
01041
01042 typedef struct _PPPoEHdr
01043 {
01044 EtherHdr ethhdr;
01045 unsigned char ver_type;
01046 unsigned char code;
01047 unsigned short session;
01048 unsigned short length;
01049
01050 } PPPoEHdr;
01051
01052
01053 typedef struct _PPPoE_Tag
01054 {
01055 unsigned short type;
01056 unsigned short length;
01057
01058 } PPPoE_Tag;
01059
01060 #define DECODE_BLEN 65535
01061
01062
01063 #define URI_COUNT 5
01064
01065 #define HTTPURI_PIPELINE_REQ 0x01
01066 typedef struct _HttpUri
01067 {
01068 u_int8_t *uri;
01069 u_int16_t length;
01070 u_int32_t decode_flags;
01071 } HttpUri;
01072
01073 typedef struct _Packet
01074 {
01075 struct pcap_pkthdr *pkth;
01076 u_int8_t *pkt;
01077
01078 Fddi_hdr *fddihdr;
01079 Fddi_llc_saps *fddisaps;
01080 Fddi_llc_sna *fddisna;
01081 Fddi_llc_iparp *fddiiparp;
01082 Fddi_llc_other *fddiother;
01083
01084 Trh_hdr *trh;
01085 Trh_llc *trhllc;
01086 Trh_mr *trhmr;
01087
01088 SLLHdr *sllh;
01089
01090 PflogHdr *pfh;
01091
01092 OldPflogHdr *opfh;
01093
01094 EtherHdr *eh;
01095 VlanTagHdr *vh;
01096 EthLlc *ehllc;
01097 EthLlcOther *ehllcother;
01098
01099 WifiHdr *wifih;
01100
01101 EtherARP *ah;
01102
01103 EtherEapol *eplh;
01104 EAPHdr *eaph;
01105 u_int8_t *eaptype;
01106 EapolKey *eapolk;
01107
01108 PPPoEHdr *pppoeh;
01109
01110 IPHdr *iph, *orig_iph;
01111 u_int32_t ip_options_len;
01112 u_int8_t *ip_options_data;
01113
01114 TCPHdr *tcph, *orig_tcph;
01115 u_int32_t tcp_options_len;
01116 u_int8_t *tcp_options_data;
01117
01118 UDPHdr *udph, *orig_udph;
01119 ICMPHdr *icmph, *orig_icmph;
01120
01121 u_int8_t *data;
01122 u_int16_t dsize;
01123 u_int16_t alt_dsize;
01124
01125 u_int16_t actual_ip_len;
01126
01127 u_int8_t frag_flag;
01128 u_int16_t frag_offset;
01129 u_int8_t mf;
01130 u_int8_t df;
01131 u_int8_t rf;
01132
01133 u_int16_t sp;
01134 u_int16_t dp;
01135 u_int16_t orig_sp;
01136 u_int16_t orig_dp;
01137 u_int32_t caplen;
01138
01139 u_int8_t uri_count;
01140
01141 void *ssnptr;
01142 void *fragtracker;
01143 void *flow;
01144 void *streamptr;
01145
01146 Options ip_options[IP_OPTMAX];
01147 u_int32_t ip_option_count;
01148 u_char ip_lastopt_bad;
01149
01150 Options tcp_options[TCP_OPTLENMAX];
01151 u_int32_t tcp_option_count;
01152 u_char tcp_lastopt_bad;
01153
01154
01155 u_int8_t csum_flags;
01156 u_int32_t packet_flags;
01157 u_int32_t bytes_to_inspect;
01158 int preprocessors;
01159 } Packet;
01160
01161 typedef struct s_pseudoheader
01162 {
01163 u_int32_t sip, dip;
01164 u_int8_t zero;
01165 u_int8_t protocol;
01166 u_int16_t len;
01167
01168 } PSEUDO_HDR;
01169
01170
01171 #define DECODE_CLASS 25
01172
01173 typedef struct _DecoderFlags
01174 {
01175 char decode_alerts;
01176 char drop_alerts;
01177 char tcpopt_experiment;
01178 char drop_tcpopt_experiment;
01179 char tcpopt_obsolete;
01180 char drop_tcpopt_obsolete;
01181 char tcpopt_ttcp;
01182 char drop_tcpopt_ttcp;
01183 char tcpopt_decode;
01184 char drop_tcpopt_decode;
01185 char ipopt_decode;
01186 char drop_ipopt_decode;
01187 } DecoderFlags;
01188
01189 #define ALERTMSG_LENGTH 256
01190
01191
01192
01193 void InitDecoderFlags(void);
01194 void DecodeTRPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01195 void DecodeFDDIPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01196 void DecodeLinuxSLLPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01197 void DecodeEthPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01198 void DecodeIEEE80211Pkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01199 void DecodeVlan(u_int8_t *, const u_int32_t, Packet *);
01200 void DecodePppPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01201 void DecodePppSerialPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01202 void DecodePppPktEncapsulated(Packet *, const u_int32_t, u_int8_t *);
01203 void DecodeSlipPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01204 void DecodeNullPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01205 void DecodeRawPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01206 void DecodeI4LRawIPPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01207 void DecodeI4LCiscoIPPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01208 void DecodeChdlcPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01209 void DecodePflog(Packet *, struct pcap_pkthdr *, u_int8_t *);
01210 void DecodeOldPflog(Packet *, struct pcap_pkthdr *, u_int8_t *);
01211 void DecodeIP(u_int8_t *, const u_int32_t, Packet *);
01212 void DecodeARP(u_int8_t *, u_int32_t, Packet *);
01213 void DecodeEapol(u_int8_t *, u_int32_t, Packet *);
01214 void DecodeEapolKey(u_int8_t *, u_int32_t, Packet *);
01215 void DecodeIPV6(u_int8_t *, u_int32_t);
01216 void DecodeIPX(u_int8_t *, u_int32_t);
01217 void DecodeEthLoopback(u_int8_t *, u_int32_t);
01218 void DecodeTCP(u_int8_t *, const u_int32_t, Packet *);
01219 void DecodeUDP(u_int8_t *, const u_int32_t, Packet *);
01220 void DecodeEAP(u_int8_t *, const u_int32_t, Packet *);
01221 void DecodeICMP(u_int8_t *, const u_int32_t, Packet *);
01222 void DecodeIPOptions(u_int8_t *, u_int32_t, Packet *);
01223 void DecodeTCPOptions(u_int8_t *, u_int32_t, Packet *);
01224 void DecodeIPOptions(u_int8_t *, u_int32_t, Packet *);
01225 void DecodePPPoEPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01226 void DecodeEncPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01227 #ifdef GIDS
01228 #ifndef IPFW
01229 void DecodeIptablesPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01230 #else
01231 void DecodeIpfwPkt(Packet *, struct pcap_pkthdr *, u_int8_t *);
01232 #endif
01233 #endif
01234
01235 #if defined(WORDS_MUSTALIGN) && !defined(__GNUC__)
01236 u_int32_t EXTRACT_32BITS (u_char *);
01237 #endif
01238
01239
01240 typedef struct _PortList
01241 {
01242 int ports[32];
01243
01244 int num_entries;
01245
01246 } PortList;
01247
01248 #endif