1 /* 2 * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved. 3 * 4 * UniProton is licensed under Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * http://license.coscl.org.cn/MulanPSL2 8 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 9 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 10 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 11 * See the Mulan PSL v2 for more details. 12 * Create: 2022-09-21 13 * Description: 网络 14 */ 15 16 #ifndef LWIP_PORTING_INET_H 17 #define LWIP_PORTING_INET_H 18 19 #include <arpa/inet.h> 20 #include <netinet/in.h> 21 #include_next <lwip/inet.h> 22 23 #if LWIP_IPV4 24 #define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) \ 25 ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) 26 #define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) \ 27 (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) 28 29 /* directly map this to the lwip internal functions */ 30 #define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen) 31 #endif /* LWIP_IPV4 */ 32 #if LWIP_IPV6 33 #define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) do { \ 34 (target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \ 35 (target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \ 36 (target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \ 37 (target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3]; \ 38 } while (0) 39 40 #define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) do { \ 41 (target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \ 42 (target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \ 43 (target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \ 44 (target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \ 45 ip6_addr_clear_zone(target_ip6addr); \ 46 } while (0) 47 48 #endif /* LWIP_IPV6 */ 49 50 #endif /* LWIP_PORTING_INET_H */ 51