10a7ce71fSopenharmony_ci/*
20a7ce71fSopenharmony_ci * Copyright (C) 2022 HiHope Open Source Organization .
30a7ce71fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40a7ce71fSopenharmony_ci * you may not use this file except in compliance with the License.
50a7ce71fSopenharmony_ci * You may obtain a copy of the License at
60a7ce71fSopenharmony_ci *
70a7ce71fSopenharmony_ci *     http:// www.apache.org/licenses/LICENSE-2.0
80a7ce71fSopenharmony_ci *
90a7ce71fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100a7ce71fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110a7ce71fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120a7ce71fSopenharmony_ci * See the License for the specific language governing permissions and
130a7ce71fSopenharmony_ci *
140a7ce71fSopenharmony_ci * limitations under the License.
150a7ce71fSopenharmony_ci */
160a7ce71fSopenharmony_ci
170a7ce71fSopenharmony_ci#ifndef NET_COMMON_H
180a7ce71fSopenharmony_ci#define NET_COMMON_H
190a7ce71fSopenharmony_ci
200a7ce71fSopenharmony_ci// __arm__ and __aarch64__ for HarmonyOS with liteos-a kernel, __i386__ and __x86_64__ for Unix like OS
210a7ce71fSopenharmony_ci#if defined(__arm__) || defined(__aarch64__) || defined(__i386__) || defined(__x86_64__)
220a7ce71fSopenharmony_ci#define HAVE_BSD_SOCKET 1
230a7ce71fSopenharmony_ci#else
240a7ce71fSopenharmony_ci#define HAVE_BSD_SOCKET 0
250a7ce71fSopenharmony_ci#endif
260a7ce71fSopenharmony_ci
270a7ce71fSopenharmony_ci#if defined(__riscv) // for wifiiot(HarmonyOS on Hi3861 with liteos-m kernel)
280a7ce71fSopenharmony_ci#define HAVE_LWIP_SOCKET 1
290a7ce71fSopenharmony_ci#else
300a7ce71fSopenharmony_ci#define HAVE_LWIP_SOCKET 0
310a7ce71fSopenharmony_ci#endif
320a7ce71fSopenharmony_ci
330a7ce71fSopenharmony_ci#if HAVE_BSD_SOCKET
340a7ce71fSopenharmony_ci#include <sys/types.h>  // for AF_INET SOCK_STREAM
350a7ce71fSopenharmony_ci#include <sys/socket.h> // for socket
360a7ce71fSopenharmony_ci#include <netinet/in.h> // for sockaddr_in
370a7ce71fSopenharmony_ci#include <arpa/inet.h> // for inet_pton
380a7ce71fSopenharmony_ci#elif HAVE_LWIP_SOCKET
390a7ce71fSopenharmony_ci#include "lwip/sockets.h"
400a7ce71fSopenharmony_ci#ifndef close
410a7ce71fSopenharmony_ciclose (fd) {
420a7ce71fSopenharmony_ci    lwip_close(fd)
430a7ce71fSopenharmony_ci}
440a7ce71fSopenharmony_ci#endif
450a7ce71fSopenharmony_ci#else
460a7ce71fSopenharmony_ci#error "Unknow platform!"
470a7ce71fSopenharmony_ci#endif
480a7ce71fSopenharmony_ci
490a7ce71fSopenharmony_ci#endif  // NET_COMMON_H