1
0

ip4.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. ip4.h
  5. Abstract:
  6. This header contains public definitions for the IPv4 network layer.
  7. Author:
  8. Evan Green 5-Apr-2013
  9. --*/
  10. //
  11. // ------------------------------------------------------------------- Includes
  12. //
  13. //
  14. // ---------------------------------------------------------------- Definitions
  15. //
  16. #define IP4_ALLOCATION_TAG 0x21347049 // '!4pI'
  17. #define IP4_VERSION 0x40
  18. #define IP4_VERSION_MASK 0xF0
  19. #define IP4_HEADER_LENGTH_MASK 0x0F
  20. #define IP4_MAX_PACKET_SIZE 0xFFFF
  21. #define IP4_FLAG_MORE_FRAGMENTS 0x1
  22. #define IP4_FLAG_DO_NOT_FRAGMENT 0x2
  23. #define IP4_FLAG_RESERVED 0x4
  24. #define IP4_FLAGS \
  25. (IP4_FLAG_RESERVED | \
  26. IP4_FLAG_DO_NOT_FRAGMENT | \
  27. IP4_FLAG_MORE_FRAGMENTS)
  28. #define IP4_FRAGMENT_FLAGS_MASK 0x7
  29. #define IP4_FRAGMENT_FLAGS_SHIFT 13
  30. #define IP4_FRAGMENT_OFFSET_MASK 0x1FFF
  31. #define IP4_FRAGMENT_OFFSET_SHIFT 0
  32. #define IP4_INITIAL_TIME_TO_LIVE 63
  33. #define IP4_BROADCAST_ADDRESS 0xFFFFFFFF
  34. #define IP4_ADDRESS_SIZE 4
  35. //
  36. // ------------------------------------------------------ Data Type Definitions
  37. //
  38. /*++
  39. Structure Description:
  40. This structure defines an IPv4 address.
  41. Members:
  42. Domain - Stores the network domain of this address.
  43. Port - Stores the 16 bit port number.
  44. Address - Stores the 32 bit IP address.
  45. NetworkAddress - Stores the unioned opaque version, used to ensure the
  46. structure is the proper size.
  47. --*/
  48. typedef struct _IP4_ADDRESS {
  49. union {
  50. struct {
  51. NET_DOMAIN_TYPE Domain;
  52. ULONG Port;
  53. ULONG Address;
  54. };
  55. NETWORK_ADDRESS NetworkAddress;
  56. };
  57. } IP4_ADDRESS, *PIP4_ADDRESS;
  58. /*++
  59. Structure Description:
  60. This structure defines an IPv4 header.
  61. Members:
  62. Version - Stores the version number and header length.
  63. Type - Stores the Differentiated Services Code Point (originally called
  64. Type of Service), and the Explicit Congestion Notification.
  65. TotalLength - Stores the total length of the packet, including the header
  66. and data, in bytes.
  67. Identification - Stores an identification field, usually used for uniquely
  68. identifying fragments of an original IP datagram.
  69. FragmentOffset - Stores some flags, as well as the fragment offset
  70. relative to the beginning of the original unfragmented IP datagram.
  71. TimeToLive - Stores the number of remaining hops this packet can make
  72. before being discarded.
  73. Protocol - Stores the protocol number for the next protocol.
  74. HeaderChecksum - Stores the 16 bit one's complement of the one's complement
  75. sum of all 16 bit words in the header.
  76. SourceAddress - Stores the source IP address of the packet.
  77. DestinationAddress - Stores the destination IP address of the packet.
  78. --*/
  79. typedef struct _IP4_HEADER {
  80. UCHAR VersionAndHeaderLength;
  81. UCHAR Type;
  82. USHORT TotalLength;
  83. USHORT Identification;
  84. USHORT FragmentOffset;
  85. UCHAR TimeToLive;
  86. UCHAR Protocol;
  87. USHORT HeaderChecksum;
  88. ULONG SourceAddress;
  89. ULONG DestinationAddress;
  90. } PACKED IP4_HEADER, *PIP4_HEADER;
  91. //
  92. // -------------------------------------------------------------------- Globals
  93. //
  94. //
  95. // -------------------------------------------------------- Function Prototypes
  96. //