Protohdr.h
上传用户:ionicmat
上传日期:2007-01-05
资源大小:22k
文件大小:3k
源码类别:

网络截获/分析

开发平台:

Delphi

  1. /****************************************************************************
  2.  * Written by Sang-Eun Han (seh@brabo1.korea.ac.kr).
  3.  * 
  4.  * Date :
  5.  *
  6.  * Filename : protohdr.h
  7.  *
  8.  *
  9.  * PERMISSION IS GRANTED TO USE, COPY AND DISTRIBUTE THIS SOFTWARE FOR ANY 
  10.  * PURPOSE EXCEPT FOR A BUSINESS OR COMMERCIAL PURPOSE, AND WITHOUT FEE, PROVIDED, 
  11.  * THAT THE ABOVE COPYRIGHT NOTICE AND THIS STATEMENT APPEAR IN ALL COPIES.
  12.  * I MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS
  13.  * SOFTWARE FOR ANY PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS."
  14.  *
  15.  */
  16. #ifndef _PROTOCOL_HEADER_H_
  17. #define _PROTOCOL_HEADER_H_
  18. // Ethernet Frame Header
  19. typedef struct _ETHERNET_HDR {
  20. UCHAR Destination[6];
  21. UCHAR Source[6];
  22. UCHAR Protocol[2];
  23. UCHAR Data[1];
  24. } ETHERNET_HDR, *PETHERNET_HDR;
  25. //rfc1340
  26. #define PROTO_IP (0x0800)
  27. #define PROTO_ARP (0x0806)
  28. #define PROTO_XNS (0x0600)
  29. #define PROTO_SNMP (0x814C)
  30. #define PROTO_OLD_IPX (0x8137)
  31. #define PROTO_NOVELL (0x8138)
  32. #define PROTO_IPNG (0x86DD)
  33. #define OFFSET_IP (14)
  34. // IPv4 Header
  35. typedef struct _IP_RHDR {
  36. UCHAR VerLen;
  37. UCHAR Service;
  38. UCHAR Length[2];
  39. UCHAR Ident[2];
  40. UCHAR Flagoff[2];
  41. UCHAR Timelive;
  42. UCHAR Protocol;
  43. UCHAR Checksum[2];
  44. UCHAR Source[4];
  45. UCHAR Destination[4];
  46. UCHAR Data[1];
  47. } IP_RHDR, *PIP_RHDR;
  48. // IPv6 Header
  49. typedef struct _IPNG_RHDR {
  50. UCHAR VerPrio;
  51. UCHAR FlowLabel[3];
  52. UCHAR Length[2];
  53. UCHAR NextHdr;
  54. UCHAR HopLimit;
  55. UCHAR Source[16];
  56. UCHAR Destination[16];
  57. UCHAR Data[1];
  58. } IPNG_RHDR, *PIPNG_RHDR;
  59. // TCP Header, RFC793
  60. typedef struct _TCP_RHDR {
  61. UCHAR Source[2];
  62. UCHAR Destination[2];
  63. UCHAR Seq[4];
  64. UCHAR Ack[4];
  65. UCHAR Rsvd0:4;
  66. UCHAR Offset:4;
  67. UCHAR Flags:6;
  68. UCHAR Rsvd1:2;
  69. UCHAR Window[2];
  70. UCHAR Checksum[2];
  71. UCHAR UrgPoint[2];
  72. UCHAR Data[1];
  73. } TCP_RHDR, *PTCP_RHDR;
  74. #define TCP_FLAG_FIN 0x01
  75. #define TCP_FLAG_SYN 0x02
  76. #define TCP_FLAG_RST 0x04
  77. #define TCP_FLAG_PSH 0x08
  78. #define TCP_FLAG_ACK 0x10
  79. #define TCP_FLAG_URG 0x20
  80. #define PROTO_TCP (6)
  81. // UDP Header
  82. typedef struct _UDP_RHDR {
  83. UCHAR Source[2];
  84. UCHAR Destination[2];
  85. UCHAR Length[2];
  86. UCHAR Checksum[2];
  87. UCHAR Data[1];
  88. } UDP_RHDR, *PUDP_RHDR;
  89. // Pseudo Header for evaluating TCP/UDP Checksum
  90. typedef struct _PSU_RHDR {
  91. UCHAR Source[4];
  92. UCHAR Destination[4];
  93. UCHAR Zero;
  94. UCHAR Protocol;
  95. UCHAR Length[2];
  96. UCHAR Data[1];
  97. } PSU_RHDR, *PPSU_RHDR;
  98. //Borland CBuilder is 32 bit Win App
  99. //#ifdef WIN32
  100. #define TOUSHORT(x) (USHORT)(*(x)<<8|*(x+1))
  101. #define TOULONG(x) (ULONG)(*(x)<<24|*(x+1)<<16|*(x+2)<<8|*(x+3))
  102. //#else
  103. //#define TOUSHORT(x) (*(USHORT *)x) //Big-Endian
  104. //#define TOULONG(x) (*(ULONG *)x)
  105. //#endif
  106. #endif /* _PROTOCOL_HEADER_H_ */