1 /* 2 * Copyright (C) 2025-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NSTACKX_INET_H 17 #define NSTACKX_INET_H 18 19 #include <arpa/inet.h> 20 #include <stdbool.h> 21 #include <stdint.h> 22 #include <string.h> 23 #include <netinet/in.h> 24 #include <netinet/ip6.h> 25 #include <unistd.h> 26 27 #define AF_ERROR 255 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 union InetAddr { 34 struct in_addr in; 35 struct in6_addr in6; 36 }; 37 uint8_t InetGetAfType(const char *ipStr, union InetAddr *addr); 38 39 bool InetEqual(uint8_t af, const union InetAddr *a, const union InetAddr *b); 40 41 bool InetEqualZero(uint8_t af, const union InetAddr *a); 42 43 bool InetEqualNone(uint8_t af, const union InetAddr *a); 44 45 bool InetEqualLoop(uint8_t af, const char *ip); 46 #ifdef __cplusplus 47 } 48 #endif 49 50 #endif