[e767dbf] | 1 | /*
|
---|
| 2 | * Copyright (c) 2012 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup inet
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file IP header definitions
|
---|
| 34 | *
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef INET_STD_H_
|
---|
| 38 | #define INET_STD_H_
|
---|
| 39 |
|
---|
| 40 | #include <sys/types.h>
|
---|
| 41 |
|
---|
[44c9ef4] | 42 | #define IP6_NEXT_FRAGMENT 44
|
---|
| 43 |
|
---|
[1d24ad3] | 44 | /** IPv4 Datagram header (fixed part) */
|
---|
[e767dbf] | 45 | typedef struct {
|
---|
| 46 | /** Version, Internet Header Length */
|
---|
| 47 | uint8_t ver_ihl;
|
---|
| 48 | /* Type of Service */
|
---|
| 49 | uint8_t tos;
|
---|
| 50 | /** Total Length */
|
---|
| 51 | uint16_t tot_len;
|
---|
[313824a] | 52 | /** Identifier */
|
---|
[e767dbf] | 53 | uint16_t id;
|
---|
| 54 | /** Flags, Fragment Offset */
|
---|
| 55 | uint16_t flags_foff;
|
---|
| 56 | /** Time to Live */
|
---|
| 57 | uint8_t ttl;
|
---|
| 58 | /** Protocol */
|
---|
| 59 | uint8_t proto;
|
---|
| 60 | /** Header Checksum */
|
---|
| 61 | uint16_t chksum;
|
---|
| 62 | /** Source Address */
|
---|
| 63 | uint32_t src_addr;
|
---|
| 64 | /** Destination Address */
|
---|
| 65 | uint32_t dest_addr;
|
---|
| 66 | } ip_header_t;
|
---|
| 67 |
|
---|
| 68 | /** Bits in ip_header_t.ver_ihl */
|
---|
| 69 | enum ver_ihl_bits {
|
---|
| 70 | /** Version, highest bit */
|
---|
| 71 | VI_VERSION_h = 7,
|
---|
| 72 | /** Version, lowest bit */
|
---|
| 73 | VI_VERSION_l = 4,
|
---|
| 74 | /** Internet Header Length, highest bit */
|
---|
| 75 | VI_IHL_h = 3,
|
---|
| 76 | /** Internet Header Length, lowest bit */
|
---|
| 77 | VI_IHL_l = 0
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | /** Bits in ip_header_t.flags_foff */
|
---|
| 81 | enum flags_foff_bits {
|
---|
| 82 | /** Reserved, must be zero */
|
---|
| 83 | FF_FLAG_RSVD = 15,
|
---|
| 84 | /** Don't Fragment */
|
---|
| 85 | FF_FLAG_DF = 14,
|
---|
| 86 | /** More Fragments */
|
---|
| 87 | FF_FLAG_MF = 13,
|
---|
| 88 | /** Fragment Offset, highest bit */
|
---|
| 89 | FF_FRAGOFF_h = 12,
|
---|
| 90 | /** Fragment Offset, lowest bit */
|
---|
| 91 | FF_FRAGOFF_l = 0
|
---|
| 92 | };
|
---|
| 93 |
|
---|
[44c9ef4] | 94 | /** Bits in ip6_header_fragment_t.offsmf */
|
---|
[c0f3460] | 95 | enum flags_offsmt_bits {
|
---|
| 96 | /** More fragments */
|
---|
| 97 | OF_FLAG_M = 0,
|
---|
| 98 | /** Fragment offset, highest bit */
|
---|
| 99 | OF_FRAGOFF_h = 15,
|
---|
| 100 | /** Fragment offset, lowest bit */
|
---|
| 101 | OF_FRAGOFF_l = 3
|
---|
| 102 | };
|
---|
| 103 |
|
---|
[1d24ad3] | 104 | /** IPv6 Datagram header (fixed part) */
|
---|
| 105 | typedef struct {
|
---|
| 106 | /** Version, Traffic class first 4 bits */
|
---|
| 107 | uint8_t ver_tc;
|
---|
| 108 | /** Traffic class (the rest), Flow label */
|
---|
| 109 | uint8_t tc_fl[3];
|
---|
| 110 | /* Payload length */
|
---|
| 111 | uint16_t payload_len;
|
---|
| 112 | /** Next header */
|
---|
| 113 | uint8_t next;
|
---|
| 114 | /** Hop limit */
|
---|
| 115 | uint8_t hop_limit;
|
---|
| 116 | /** Source address */
|
---|
| 117 | uint8_t src_addr[16];
|
---|
| 118 | /** Destination address */
|
---|
| 119 | uint8_t dest_addr[16];
|
---|
| 120 | } ip6_header_t;
|
---|
| 121 |
|
---|
| 122 | /** IPv6 Datagram Fragment extension header */
|
---|
| 123 | typedef struct {
|
---|
| 124 | /** Next header */
|
---|
| 125 | uint8_t next;
|
---|
| 126 | /** Reserved */
|
---|
| 127 | uint8_t reserved;
|
---|
[c0f3460] | 128 | /** Fragmentation offset, reserved and M flag */
|
---|
| 129 | uint16_t offsmf;
|
---|
[313824a] | 130 | /** Identifier */
|
---|
[1d24ad3] | 131 | uint32_t id;
|
---|
| 132 | } ip6_header_fragment_t;
|
---|
| 133 |
|
---|
[347768d] | 134 | /** Fragment offset is expressed in units of 8 bytes */
|
---|
| 135 | #define FRAG_OFFS_UNIT 8
|
---|
| 136 |
|
---|
[e767dbf] | 137 | #endif
|
---|
| 138 |
|
---|
| 139 | /** @}
|
---|
| 140 | */
|
---|