154568cb3Sopenharmony_ci/*
254568cb3Sopenharmony_ci * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
354568cb3Sopenharmony_ci *
454568cb3Sopenharmony_ci * UniProton is licensed under Mulan PSL v2.
554568cb3Sopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2.
654568cb3Sopenharmony_ci * You may obtain a copy of Mulan PSL v2 at:
754568cb3Sopenharmony_ci *          http://license.coscl.org.cn/MulanPSL2
854568cb3Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
954568cb3Sopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
1054568cb3Sopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
1154568cb3Sopenharmony_ci * See the Mulan PSL v2 for more details.
1254568cb3Sopenharmony_ci * Create: 2022-09-21
1354568cb3Sopenharmony_ci * Description: 网络
1454568cb3Sopenharmony_ci */
1554568cb3Sopenharmony_ci
1654568cb3Sopenharmony_ci#ifndef LWIP_PORTING_INET_H
1754568cb3Sopenharmony_ci#define LWIP_PORTING_INET_H
1854568cb3Sopenharmony_ci
1954568cb3Sopenharmony_ci#include <arpa/inet.h>
2054568cb3Sopenharmony_ci#include <netinet/in.h>
2154568cb3Sopenharmony_ci#include_next <lwip/inet.h>
2254568cb3Sopenharmony_ci
2354568cb3Sopenharmony_ci#if LWIP_IPV4
2454568cb3Sopenharmony_ci#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) \
2554568cb3Sopenharmony_ci            ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
2654568cb3Sopenharmony_ci#define inet_addr_to_ip4addr(target_ipaddr, source_inaddr) \
2754568cb3Sopenharmony_ci            (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
2854568cb3Sopenharmony_ci
2954568cb3Sopenharmony_ci/* directly map this to the lwip internal functions */
3054568cb3Sopenharmony_ci#define inet_ntoa_r(addr, buf, buflen)  ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
3154568cb3Sopenharmony_ci#endif /* LWIP_IPV4 */
3254568cb3Sopenharmony_ci#if LWIP_IPV6
3354568cb3Sopenharmony_ci#define inet6_addr_from_ip6addr(target_in6addr, source_ip6addr) do {    \
3454568cb3Sopenharmony_ci            (target_in6addr)->s6_addr32[0] = (source_ip6addr)->addr[0]; \
3554568cb3Sopenharmony_ci            (target_in6addr)->s6_addr32[1] = (source_ip6addr)->addr[1]; \
3654568cb3Sopenharmony_ci            (target_in6addr)->s6_addr32[2] = (source_ip6addr)->addr[2]; \
3754568cb3Sopenharmony_ci            (target_in6addr)->s6_addr32[3] = (source_ip6addr)->addr[3]; \
3854568cb3Sopenharmony_ci} while (0)
3954568cb3Sopenharmony_ci
4054568cb3Sopenharmony_ci#define inet6_addr_to_ip6addr(target_ip6addr, source_in6addr) do {  \
4154568cb3Sopenharmony_ci            (target_ip6addr)->addr[0] = (source_in6addr)->s6_addr32[0]; \
4254568cb3Sopenharmony_ci            (target_ip6addr)->addr[1] = (source_in6addr)->s6_addr32[1]; \
4354568cb3Sopenharmony_ci            (target_ip6addr)->addr[2] = (source_in6addr)->s6_addr32[2]; \
4454568cb3Sopenharmony_ci            (target_ip6addr)->addr[3] = (source_in6addr)->s6_addr32[3]; \
4554568cb3Sopenharmony_ci            ip6_addr_clear_zone(target_ip6addr);    \
4654568cb3Sopenharmony_ci} while (0)
4754568cb3Sopenharmony_ci
4854568cb3Sopenharmony_ci#endif /* LWIP_IPV6 */
4954568cb3Sopenharmony_ci
5054568cb3Sopenharmony_ci#endif /* LWIP_PORTING_INET_H */
51