1 /* 2 * Copyright (C) 2022 HiHope Open Source Organization . 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 * 14 * limitations under the License. 15 */ 16 17 #ifndef NET_COMMON_H 18 #define NET_COMMON_H 19 20 // __arm__ and __aarch64__ for HarmonyOS with liteos-a kernel, __i386__ and __x86_64__ for Unix like OS 21 #if defined(__arm__) || defined(__aarch64__) || defined(__i386__) || defined(__x86_64__) 22 #define HAVE_BSD_SOCKET 1 23 #else 24 #define HAVE_BSD_SOCKET 0 25 #endif 26 27 #if defined(__riscv) // for wifiiot(HarmonyOS on Hi3861 with liteos-m kernel) 28 #define HAVE_LWIP_SOCKET 1 29 #else 30 #define HAVE_LWIP_SOCKET 0 31 #endif 32 33 #if HAVE_BSD_SOCKET 34 #include <sys/types.h> // for AF_INET SOCK_STREAM 35 #include <sys/socket.h> // for socket 36 #include <netinet/in.h> // for sockaddr_in 37 #include <arpa/inet.h> // for inet_pton 38 #elif HAVE_LWIP_SOCKET 39 #include "lwip/sockets.h" 40 #ifndef close close(fd)41close (fd) { 42 lwip_close(fd) 43 } 44 #endif 45 #else 46 #error "Unknow platform!" 47 #endif 48 49 #endif // NET_COMMON_H