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