34#include <sys/socket.h>
41#ifdef LOSCFG_NET_LWIP_SACK
44#if !LWIP_COMPAT_SOCKETS
46#define CHECK_NULL_PTR(ptr) do { if (ptr == NULL) { set_errno(EFAULT); return -1; } } while (0)
70int accept(
int s,
struct sockaddr *addr, socklen_t *addrlen)
72 return lwip_accept(s, addr, addrlen);
94int bind(
int s,
const struct sockaddr *name, socklen_t namelen)
97 if (namelen <
sizeof(*name)) {
126 return lwip_shutdown(s, how);
131 CHECK_NULL_PTR(name);
132 CHECK_NULL_PTR(namelen);
133 return lwip_getpeername(s, name, namelen);
138 CHECK_NULL_PTR(name);
139 CHECK_NULL_PTR(namelen);
140 return lwip_getsockname(s, name, namelen);
143int getsockopt(
int s,
int level,
int optname,
void *optval, socklen_t *optlen)
145 return lwip_getsockopt(s, level, optname, optval, optlen);
148int setsockopt(
int s,
int level,
int optname,
const void *optval, socklen_t optlen)
168 return lwip_close(s);
185int connect(
int s,
const struct sockaddr *name, socklen_t namelen)
187 CHECK_NULL_PTR(name);
188 if (namelen <
sizeof(*name)) {
192 return lwip_connect(s, name, namelen);
211 return lwip_listen(s, backlog);
237 return lwip_recv(s, mem, len, flags);
241 struct sockaddr *from, socklen_t *fromlen)
244 return lwip_recvfrom(s, mem, len, flags, from, fromlen);
249 CHECK_NULL_PTR(message);
250 if (message->msg_iovlen) {
251 CHECK_NULL_PTR(message->msg_iov);
253 return lwip_recvmsg(s, message, flags);
259 CHECK_NULL_PTR(dataptr);
260 return lwip_send(s, dataptr, size, flags);
265 return lwip_sendmsg(s, message, flags);
269 const struct sockaddr *to, socklen_t tolen)
271 CHECK_NULL_PTR(dataptr);
272 if (to && tolen <
sizeof(*to)) {
276 return lwip_sendto(s, dataptr, size, flags, to, tolen);
314int socket(
int domain,
int type,
int protocol)
323const char *
inet_ntop(
int af,
const void *src,
char *dst, socklen_t size)
325 return lwip_inet_ntop(af, src, dst, size);
330 return lwip_inet_pton(af, src, dst);
333#ifndef LWIP_INET_ADDR_FUNC
336 return ipaddr_addr(cp);
340#ifndef LWIP_INET_ATON_FUNC
343 return ip4addr_aton(cp, (ip4_addr_t*)inp);
347#ifndef LWIP_INET_NTOA_FUNC
350 return ip4addr_ntoa((
const ip4_addr_t*)&(in));
int inet_aton(const char *cp, struct in_addr *inp)
int connect(int s, const struct sockaddr *name, socklen_t namelen)
int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
设置socket 配置项
ssize_t recvmsg(int s, struct msghdr *message, int flags)
只是数据的格式的不同
in_addr_t inet_addr(const char *cp)
int getpeername(int s, struct sockaddr *name, socklen_t *namelen)
获取对等名称 = getsockname
ssize_t recv(int s, void *mem, size_t len, int flags)
int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
获取socket名称和长度
int shutdown(int s, int how)
ssize_t sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
区别是送达地址,意思是这些数据要发给哪个地址的
int bind(int s, const struct sockaddr *name, socklen_t namelen)
ssize_t sendmsg(int s, const struct msghdr *message, int flags)
只是发送数据的格式的不同
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
获取 socket 配置项
char * inet_ntoa(struct in_addr in)
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
int inet_pton(int af, const char *src, void *dst)
inet_pton 函数转换字符串到网络地址,第一个参数af是地址族,转换后存在dst中
ssize_t recvfrom(int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
区别是返回源地址,意思是这些数据是从哪个地址过来的
int listen(int s, int backlog)
ssize_t send(int s, const void *dataptr, size_t size, int flags)
相当于文件操作的 write 功能,区别是第四个参数 同 recv
int socket(int domain, int type, int protocol)
ssize_t lwip_sendto(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
int lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
int lwip_socket(int domain, int type, int protocol)