123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- /*++
- Copyright (c) 2013 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- ip4.h
- Abstract:
- This header contains public definitions for the IPv4 network layer.
- Author:
- Evan Green 5-Apr-2013
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- //
- // --------------------------------------------------------------------- Macros
- //
- //
- // This macro determines whether or not the given IPv4 address is a multicast
- // address. The address is treated as being in network byte order.
- //
- #define IP4_IS_MULTICAST_ADDRESS(_Ip4Address) \
- (((_Ip4Address) & 0x000000F0) == 0x000000E0)
- //
- // ---------------------------------------------------------------- Definitions
- //
- #define IP4_ALLOCATION_TAG 0x21347049 // '!4pI'
- #define IP4_VERSION 0x40
- #define IP4_VERSION_MASK 0xF0
- #define IP4_HEADER_LENGTH_MASK 0x0F
- #define IP4_MAX_PACKET_SIZE 0xFFFF
- #define IP4_TYPE_ECN_MASK 0x03
- #define IP4_TYPE_DSCP_MASK 0xFC
- #define IP4_PRECEDENCE_NETWORK_CONTROL 0xC0
- #define IP4_FLAG_MORE_FRAGMENTS 0x1
- #define IP4_FLAG_DO_NOT_FRAGMENT 0x2
- #define IP4_FLAG_RESERVED 0x4
- #define IP4_FLAGS \
- (IP4_FLAG_RESERVED | \
- IP4_FLAG_DO_NOT_FRAGMENT | \
- IP4_FLAG_MORE_FRAGMENTS)
- #define IP4_FRAGMENT_FLAGS_MASK 0x7
- #define IP4_FRAGMENT_FLAGS_SHIFT 13
- #define IP4_FRAGMENT_OFFSET_MASK 0x1FFF
- #define IP4_FRAGMENT_OFFSET_SHIFT 0
- #define IP4_INITIAL_TIME_TO_LIVE 63
- #define IP4_INITIAL_MULTICAST_TIME_TO_LIVE 1
- #define IP4_LINK_LOCAL_TIME_TO_LIVE 1
- #define IP4_MAX_TIME_TO_LIVE 255
- #define IP4_BROADCAST_ADDRESS 0xFFFFFFFF
- #define IP4_ADDRESS_SIZE 4
- //
- // Define the flags for the IPv4 option type.
- //
- #define IP4_OPTION_TYPE_COPIED 0x80
- #define IP4_OPTION_TYPE_CLASS_MASK 0x60
- #define IP4_OPTION_TYPE_CLASS_SHIFT 5
- #define IP4_OPTION_TYPE_CLASS_CONTROL 0x0
- #define IP4_OPTION_TYPE_CLASS_DEBUG 0x2
- #define IP4_OPTION_TYPE_NUMBER_MASK 0x1F
- #define IP4_OPTION_TYPE_NUMBER_SHIFT 0
- //
- // Define specific IPv4 option types.
- //
- #define IP4_OPTION_END 0x00
- #define IP4_OPTION_NOP 0x01
- #define IP4_OPTION_ROUTER_ALERT 0x94
- //
- // Define the details of the router alert option.
- //
- #define IP4_ROUTER_ALERT_LENGTH 4
- #define IP4_ROUTER_ALERT_VALUE 0
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- /*++
- Structure Description:
- This structure defines an IPv4 address.
- Members:
- Domain - Stores the network domain of this address.
- Port - Stores the 16 bit port number.
- Address - Stores the 32 bit IP address.
- NetworkAddress - Stores the unioned opaque version, used to ensure the
- structure is the proper size.
- --*/
- typedef struct _IP4_ADDRESS {
- union {
- struct {
- NET_DOMAIN_TYPE Domain;
- ULONG Port;
- ULONG Address;
- };
- NETWORK_ADDRESS NetworkAddress;
- };
- } IP4_ADDRESS, *PIP4_ADDRESS;
- /*++
- Structure Description:
- This structure defines an IPv4 header.
- Members:
- VersionAndHeaderLength - Stores the version number and header length.
- Type - Stores the Differentiated Services Code Point (originally called
- Type of Service), and the Explicit Congestion Notification.
- TotalLength - Stores the total length of the packet, including the header
- and data, in bytes.
- Identification - Stores an identification field, usually used for uniquely
- identifying fragments of an original IP datagram.
- FragmentOffset - Stores some flags, as well as the fragment offset
- relative to the beginning of the original unfragmented IP datagram.
- TimeToLive - Stores the number of remaining hops this packet can make
- before being discarded.
- Protocol - Stores the protocol number for the next protocol.
- HeaderChecksum - Stores the 16 bit one's complement of the one's complement
- sum of all 16 bit words in the header.
- SourceAddress - Stores the source IP address of the packet.
- DestinationAddress - Stores the destination IP address of the packet.
- --*/
- #pragma pack(push, 1)
- typedef struct _IP4_HEADER {
- UCHAR VersionAndHeaderLength;
- UCHAR Type;
- USHORT TotalLength;
- USHORT Identification;
- USHORT FragmentOffset;
- UCHAR TimeToLive;
- UCHAR Protocol;
- USHORT HeaderChecksum;
- ULONG SourceAddress;
- ULONG DestinationAddress;
- } PACKED IP4_HEADER, *PIP4_HEADER;
- /*++
- Structure Descriptoin:
- This structure defines an IPv4 header option.
- Members:
- Type - Supplies the type of the IPv4 header option.
- Length - Supplies the length of the IPv4 header option including the type
- and length, in bytes.
- --*/
- typedef struct _IP4_OPTION {
- UCHAR Type;
- UCHAR Length;
- } PACKED IP4_OPTION, *PIP4_OPTION;
- #pragma pack(pop)
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // -------------------------------------------------------- Function Prototypes
- //
|