1 /* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, this list of 8 * conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 * of conditions and the following disclaimer in the documentation and/or other materials 12 * provided with the distribution. 13 * 14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef _ADAPT_NETINET_IP_H 32 #define _ADAPT_NETINET_IP_H 33 34 #include <endian.h> 35 #include <stdint.h> 36 #include <netinet/in.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 struct timestamp { 43 uint8_t len; 44 uint8_t ptr; 45 #if BYTE_ORDER == LITTLE_ENDIAN 46 unsigned int flags:4; 47 unsigned int overflow:4; 48 #else 49 unsigned int overflow:4; 50 unsigned int flags:4; 51 #endif 52 uint32_t data[9]; 53 }; 54 55 struct iphdr { 56 #if BYTE_ORDER == LITTLE_ENDIAN 57 unsigned int ihl:4; 58 unsigned int version:4; 59 #else 60 unsigned int version:4; 61 unsigned int ihl:4; 62 #endif 63 uint8_t tos; 64 uint16_t tot_len; 65 uint16_t id; 66 uint16_t frag_off; 67 uint8_t ttl; 68 uint8_t protocol; 69 uint16_t check; 70 uint32_t saddr; 71 uint32_t daddr; 72 }; 73 74 struct ip { 75 #if BYTE_ORDER == LITTLE_ENDIAN 76 unsigned int ip_hl:4; 77 unsigned int ip_v:4; 78 #else 79 unsigned int ip_v:4; 80 unsigned int ip_hl:4; 81 #endif 82 uint8_t ip_tos; 83 uint16_t ip_len; 84 uint16_t ip_id; 85 uint16_t ip_off; 86 uint8_t ip_ttl; 87 uint8_t ip_p; 88 uint16_t ip_sum; 89 struct in_addr ip_src, ip_dst; 90 }; 91 92 #define IP_RF 0x8000 93 #define IP_DF 0x4000 94 #define IP_MF 0x2000 95 #define IP_OFFMASK 0x1fff 96 97 struct ip_timestamp { 98 uint8_t ipt_code; 99 uint8_t ipt_len; 100 uint8_t ipt_ptr; 101 #if BYTE_ORDER == LITTLE_ENDIAN 102 unsigned int ipt_flg:4; 103 unsigned int ipt_oflw:4; 104 #else 105 unsigned int ipt_oflw:4; 106 unsigned int ipt_flg:4; 107 #endif 108 uint32_t data[9]; 109 }; 110 111 #ifdef __cplusplus 112 } 113 #endif 114 115 #endif /* !_ADAPT_NETINET_IP_H */ 116