Rev 4731 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4731 | Rev 4756 | ||
---|---|---|---|
Line 39... | Line 39... | ||
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. |
44 | /** Returns the actual IP header length in bytes. |
45 | * @param header The IP packet header. Input parameter. |
45 | * @param[in] header The IP packet header. |
46 | */ |
46 | */ |
47 | #define IP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
47 | #define IP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
48 | 48 | ||
49 | /** Returns the actual IP header length. |
49 | /** Returns the IP header length. |
50 | * @param header The IP packet header. Input parameter. |
50 | * @param[in] length The IP header length in bytes. |
51 | */ |
51 | */ |
52 | #define IP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
52 | #define IP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
53 | 53 | ||
54 | /** Returns the actual IP packet total length. |
54 | /** Returns the actual IP packet total length. |
55 | * @param header The IP packet header. Input parameter. |
55 | * @param[in] header The IP packet header. |
56 | */ |
56 | */ |
57 | #define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) |
57 | #define IP_TOTAL_LENGTH( header ) ntohs(( header )->total_length ) |
58 | 58 | ||
59 | /** Returns the actual IP packet data length. |
59 | /** Returns the actual IP packet data length. |
60 | * @param header The IP packet header. Input parameter. |
60 | * @param[in] header The IP packet header. |
61 | */ |
61 | */ |
62 | #define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) |
62 | #define IP_HEADER_DATA_LENGTH( header ) ( IP_TOTAL_LENGTH( header ) - IP_HEADER_LENGTH( header )) |
63 | 63 | ||
64 | /** Returns the IP packet header checksum. |
64 | /** Returns the IP packet header checksum. |
65 | * @param header The IP packet header. Input parameter. |
65 | * @param[in] header The IP packet header. |
66 | */ |
66 | */ |
67 | #define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) |
67 | #define IP_HEADER_CHECKSUM( header ) ( htons( ip_checksum(( uint8_t * )( header ), IP_HEADER_LENGTH( header )))) |
68 | 68 | ||
69 | /** Returns the fragment offest. |
69 | /** Returns the fragment offest. |
70 | * @param header The IP packet header. Input parameter. |
70 | * @param[in] header The IP packet header. |
71 | */ |
71 | */ |
72 | #define IP_FRAGMENT_OFFSET( header ) (((( header )->fragment_offset_high << 8 ) + ( header )->fragment_offset_low ) * 8u ) |
72 | #define IP_FRAGMENT_OFFSET( header ) (((( header )->fragment_offset_high << 8 ) + ( header )->fragment_offset_low ) * 8u ) |
73 | 73 | ||
74 | /** Returns the fragment offest high bits. |
74 | /** Returns the fragment offest high bits. |
75 | * @param length The prefixed data total length. Input parameter. |
75 | * @param[in] length The prefixed data total length. |
76 | */ |
76 | */ |
77 | #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH( length ) (((( length ) / 8u ) & 0x1F00 ) >> 8 ) |
77 | #define IP_COMPUTE_FRAGMENT_OFFSET_HIGH( length ) (((( length ) / 8u ) & 0x1F00 ) >> 8 ) |
78 | 78 | ||
79 | /** Returns the fragment offest low bits. |
79 | /** Returns the fragment offest low bits. |
80 | * @param length The prefixed data total length. Input parameter. |
80 | * @param[in] length The prefixed data total length. |
81 | */ |
81 | */ |
82 | #define IP_COMPUTE_FRAGMENT_OFFSET_LOW( length ) ((( length ) / 8u ) & 0xFF ) |
82 | #define IP_COMPUTE_FRAGMENT_OFFSET_LOW( length ) ((( length ) / 8u ) & 0xFF ) |
83 | 83 | ||
84 | /** Type definition of the internet header. |
84 | /** Type definition of the internet header. |
85 | * @see ip_header |
85 | * @see ip_header |