1/* 2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef IPV4_H 6#define IPV4_H 7 8 9#include <netinet/in.h> 10 11#include <ByteOrder.h> 12 13 14#define IPV4_VERSION 4 15 16// fragment flags 17#define IP_RESERVED_FLAG 0x8000 18#define IP_DONT_FRAGMENT 0x4000 19#define IP_MORE_FRAGMENTS 0x2000 20#define IP_FRAGMENT_OFFSET_MASK 0x1fff 21 22 23struct ipv4_header { 24#if B_HOST_IS_LENDIAN == 1 25 uint8 header_length : 4; // header length in 32-bit words 26 uint8 version : 4; 27#else 28 uint8 version : 4; 29 uint8 header_length : 4; 30#endif 31 uint8 service_type; 32 uint16 total_length; 33 uint16 id; 34 uint16 fragment_offset; 35 uint8 time_to_live; 36 uint8 protocol; 37 uint16 checksum; 38 in_addr_t source; 39 in_addr_t destination; 40 41 uint16 HeaderLength() const { return header_length << 2; } 42 uint16 TotalLength() const { return ntohs(total_length); } 43 uint16 FragmentOffset() const { return ntohs(fragment_offset); } 44} _PACKED; 45 46 47#endif // IPV4_H 48