Rev 4722 | Rev 4731 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4722 | Rev 4728 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * IP header and options definitions. |
34 | * IP header and options definitions. |
35 | * Names according to the linux src/include/linux/ip.h header file. |
35 | * Based on the RFC~791. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #ifndef __NET_IP_HEADER_H__ |
38 | #ifndef __NET_IP_HEADER_H__ |
39 | #define __NET_IP_HEADER_H__ |
39 | #define __NET_IP_HEADER_H__ |
40 | 40 | ||
41 | #include <byteorder.h> |
41 | #include <byteorder.h> |
42 | #include <sys/types.h> |
42 | #include <sys/types.h> |
43 | 43 | ||
- | 44 | /** Returns the actual IP header length. |
|
- | 45 | * @param header The IP packet header. Input parameter. |
|
- | 46 | */ |
|
- | 47 | #define IP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
|
- | 48 | ||
- | 49 | /** Returns the actual IP header length. |
|
- | 50 | * @param header The IP packet header. Input parameter. |
|
- | 51 | */ |
|
- | 52 | #define IP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
|
- | 53 | ||
- | 54 | /** Returns the actual IP packet total length. |
|
- | 55 | * @param header The IP packet header. Input parameter. |
|
- | 56 | */ |
|
- | 57 | #define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) |
|
- | 58 | ||
- | 59 | /** Returns the actual IP packet data length. |
|
- | 60 | * @param header The IP packet header. Input parameter. |
|
- | 61 | */ |
|
- | 62 | #define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) |
|
- | 63 | ||
- | 64 | /** Returns the IP packet header checksum. |
|
- | 65 | * @param header The IP packet header. Input parameter. |
|
- | 66 | */ |
|
- | 67 | #define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) |
|
- | 68 | ||
- | 69 | /** Returns the fragment offest. |
|
- | 70 | * @param length The prefixed data total length. Input parameter. |
|
- | 71 | */ |
|
- | 72 | #define IP_COMPUTE_FRAGMENT_OFFSET( length ) (( length ) / 8 ) |
|
- | 73 | ||
44 | /** Type definition of the internet header. |
74 | /** Type definition of the internet header. |
45 | * @see ip_header |
75 | * @see ip_header |
46 | */ |
76 | */ |
47 | typedef struct ip_header ip_header_t; |
77 | typedef struct ip_header ip_header_t; |
48 | 78 | ||
Line 60... | Line 90... | ||
60 | */ |
90 | */ |
61 | uint8_t version:4; |
91 | uint8_t version:4; |
62 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
92 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
63 | * Note that the minimum value for a~correct header is~5. |
93 | * Note that the minimum value for a~correct header is~5. |
64 | */ |
94 | */ |
65 | uint8_t ihl:4; |
95 | uint8_t header_length:4; |
66 | #else |
96 | #else |
67 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
97 | /** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data. |
68 | * Note that the minimum value for a~correct header is~5. |
98 | * Note that the minimum value for a~correct header is~5. |
69 | */ |
99 | */ |
70 | uint8_t ihl:4; |
100 | uint8_t header_length:4; |
71 | /** The Version field indicates the format of the internet header. |
101 | /** The Version field indicates the format of the internet header. |
72 | */ |
102 | */ |
73 | uint8_t version:4; |
103 | uint8_t version:4; |
74 | #endif |
104 | #endif |
75 | /** The Type of Service provides an indication of the abstract parameters of the quality of service desired. |
105 | /** The Type of Service provides an indication of the abstract parameters of the quality of service desired. |
Line 198... | Line 228... | ||
198 | */ |
228 | */ |
199 | #define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT ) |
229 | #define IPFLAG_MORE_FRAGMENTS ( 0x1 << IPFLAG_FRAGMENTED_SHIFT ) |
200 | 230 | ||
201 | /*@}*/ |
231 | /*@}*/ |
202 | 232 | ||
203 | /* |
- | |
204 | #define IPOPT_OPTVAL 0 |
- | |
205 | #define IPOPT_OLEN 1 |
- | |
206 | #define IPOPT_OFFSET 2 |
- | |
207 | #define IPOPT_MINOFF 4 |
- | |
208 | #define MAX_IPOPTLEN 40 |
- | |
209 | */ |
- | |
210 | - | ||
211 | /** Type definition of the internet version 4 pseudo header. |
233 | /** Type definition of the internet version 4 pseudo header. |
212 | * @see ipv4_pseudo_header |
234 | * @see ipv4_pseudo_header |
213 | */ |
235 | */ |
214 | typedef struct ipv4_pseudo_header ipv4_pseudo_header_t; |
236 | typedef struct ipv4_pseudo_header ipv4_pseudo_header_t; |
215 | 237 | ||
Line 225... | Line 247... | ||
225 | */ |
247 | */ |
226 | uint32_t source_address; |
248 | uint32_t source_address; |
227 | /** The destination address. |
249 | /** The destination address. |
228 | */ |
250 | */ |
229 | uint32_t destination_address; |
251 | uint32_t destination_address; |
230 | /** Zero byte. |
252 | /** Reserved byte. |
- | 253 | * Must be zero. |
|
231 | */ |
254 | */ |
232 | uint8_t zero; |
255 | uint8_t reserved; |
233 | /** This field indicates the next level protocol used in the data portion of the internet datagram. |
256 | /** This field indicates the next level protocol used in the data portion of the internet datagram. |
234 | */ |
257 | */ |
235 | uint8_t protocol; |
258 | uint8_t protocol; |
236 | /** Data length is the length of the datagram, measured in octets. |
259 | /** Data length is the length of the datagram, measured in octets. |
237 | */ |
260 | */ |