41#ifdef LOSCFG_NET_LWIP_SACK
45#define SOCKET_U2K(s) \
47 s = GetAssociatedSystemFd(s); \
48 if (s == VFS_ERROR) { \
50 return -get_errno(); \
54#define SOCKET_K2U(s) \
56 int fd = AllocAndAssocProcessFd(s, MIN_START_FD); \
70 ret =
socket(domain, type, protocol);
79int SysBind(
int s,
const struct sockaddr *name, socklen_t namelen)
84 CHECK_ASPACE(name, namelen);
86 DUP_FROM_USER(name, namelen);
92 ret =
bind(s, name, namelen);
102int SysConnect(
int s,
const struct sockaddr *name, socklen_t namelen)
107 CHECK_ASPACE(name, namelen);
109 DUP_FROM_USER(name, namelen);
115 ret =
connect(s, name, namelen);
130 ret =
listen(sockfd, backlog);
139 socklen_t *addressLen)
145 CHECK_ASPACE(addressLen,
sizeof(socklen_t));
146 CPY_FROM_USER(addressLen);
148 CHECK_ASPACE(address, LEN(addressLen));
149 DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
157 CPY_TO_USER(addressLen, close(ret); FREE_DUP(address));
158 DUP_TO_USER(address, LEN(addressLen), close(ret); FREE_DUP(address));
171 CHECK_ASPACE(namelen,
sizeof(socklen_t));
172 CPY_FROM_USER(namelen);
174 CHECK_ASPACE(name, LEN(namelen));
175 DUP_FROM_USER_NOCOPY(name, LEN(namelen));
177 if (name == NULL || namelen == NULL) {
188 CPY_TO_USER(namelen, FREE_DUP(name));
189 DUP_TO_USER(name, LEN(namelen), FREE_DUP(name));
200 CHECK_ASPACE(namelen,
sizeof(socklen_t));
201 CPY_FROM_USER(namelen);
203 CHECK_ASPACE(name, LEN(namelen));
204 DUP_FROM_USER_NOCOPY(name, LEN(namelen));
206 if (name == NULL || namelen == NULL) {
217 CPY_TO_USER(namelen, FREE_DUP(name));
218 DUP_TO_USER(name, LEN(namelen), FREE_DUP(name));
228 CHECK_ASPACE(dataptr, size);
230 DUP_FROM_USER(dataptr, size);
232 if (dataptr == NULL) {
236 ret =
send(s, dataptr, size, flags);
247 const struct sockaddr *to, socklen_t tolen)
252 CHECK_ASPACE(dataptr, size);
253 CHECK_ASPACE(to, tolen);
255 DUP_FROM_USER(dataptr, size);
256 DUP_FROM_USER(to, tolen, FREE_DUP(dataptr));
258 if (dataptr == NULL) {
262 ret =
sendto(s, dataptr, size, flags, to, tolen);
278 CHECK_ASPACE(buffer, length);
280 DUP_FROM_USER_NOCOPY(buffer, length);
282 if (buffer == NULL) {
293 DUP_TO_USER(buffer, ret, FREE_DUP(buffer));
299 int flags,
struct sockaddr *address,
300 socklen_t *addressLen)
305 CHECK_ASPACE(buffer, length);
307 CHECK_ASPACE(addressLen,
sizeof(socklen_t));
308 CPY_FROM_USER(addressLen);
310 CHECK_ASPACE(address, LEN(addressLen));
311 DUP_FROM_USER_NOCOPY(address, LEN(addressLen));
313 DUP_FROM_USER_NOCOPY(buffer, length, FREE_DUP(address));
315 if (buffer == NULL || (address != NULL && addressLen == NULL)) {
319 ret =
recvfrom(
socket, buffer, length, flags, address, addressLen);
327 CPY_TO_USER(addressLen, FREE_DUP(address); FREE_DUP(buffer));
328 DUP_TO_USER(address, LEN(addressLen), FREE_DUP(address); FREE_DUP(buffer));
329 DUP_TO_USER(buffer, ret, FREE_DUP(address); FREE_DUP(buffer));
349 const void *optValue, socklen_t optLen)
354 CHECK_ASPACE(optValue, optLen);
356 DUP_FROM_USER(optValue, optLen);
367 void *optValue, socklen_t *optLen)
373 CHECK_ASPACE(optLen,
sizeof(socklen_t));
374 CPY_FROM_USER(optLen);
376 CHECK_ASPACE(optValue, LEN(optLen));
377 DUP_FROM_USER_NOCOPY(optValue, LEN(optLen));
379 if (optLen == NULL) {
383 ret =
getsockopt(sockfd, level, optName, optValue, optLen);
390 CPY_TO_USER(optLen, FREE_DUP(optValue));
391 DUP_TO_USER(optValue, LEN(optLen), FREE_DUP(optValue));
402 CHECK_ASPACE(message,
sizeof(
struct msghdr));
403 CPY_FROM_CONST_USER(
struct msghdr, message);
405 if (message && message->msg_iovlen > IOV_MAX) {
410 CHECK_FIELD_ASPACE(message, msg_name, message->msg_namelen);
411 CHECK_FIELD_ASPACE(message, msg_iov, message->msg_iovlen *
sizeof(
struct iovec));
412 CHECK_FIELD_ASPACE(message, msg_control, message->msg_controllen);
414 DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen *
sizeof(
struct iovec));
415 CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
416 FREE_DUP_FIELD(message, msg_iov));
417 DUP_FIELD_FROM_USER(message, msg_name, message->msg_namelen,
418 FREE_DUP_FIELD(message, msg_iov));
419 DUP_FIELD_FROM_USER(message, msg_control, message->msg_controllen,
420 FREE_DUP_FIELD(message, msg_iov);
421 FREE_DUP_FIELD(message, msg_name));
422 DUP_ARRAY_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
423 FREE_DUP_FIELD(message, msg_control);
424 FREE_DUP_FIELD(message, msg_iov);
425 FREE_DUP_FIELD(message, msg_name));
427 if (message == NULL) {
431 ret =
sendmsg(s, message, flags);
433 FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
434 FREE_DUP_FIELD(message, msg_control);
435 FREE_DUP_FIELD(message, msg_iov);
436 FREE_DUP_FIELD(message, msg_name);
450 CHECK_ASPACE(message,
sizeof(
struct msghdr));
451 CPY_FROM_NONCONST_USER(message);
453 if (message && message->msg_iovlen > IOV_MAX) {
458 CHECK_FIELD_ASPACE(message, msg_name, message->msg_namelen);
459 CHECK_FIELD_ASPACE(message, msg_iov, message->msg_iovlen *
sizeof(
struct iovec));
460 CHECK_FIELD_ASPACE(message, msg_control, message->msg_controllen);
462 DUP_FIELD_FROM_USER(message, msg_iov, message->msg_iovlen *
sizeof(
struct iovec));
463 CHECK_ARRAY_FIELD_ASPACE(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
464 FREE_DUP_FIELD(message, msg_iov));
465 DUP_FIELD_FROM_USER_NOCOPY(message, msg_name, message->msg_namelen,
466 FREE_DUP_FIELD(message, msg_iov));
467 DUP_FIELD_FROM_USER_NOCOPY(message, msg_control, message->msg_controllen,
468 FREE_DUP_FIELD(message, msg_iov);
469 FREE_DUP_FIELD(message, msg_name));
470 DUP_ARRAY_FIELD_FROM_USER_NOCOPY(message, msg_iov, message->msg_iovlen, iov_base, iov_len,
471 FREE_DUP_FIELD(message, msg_control);
472 FREE_DUP_FIELD(message, msg_iov);
473 FREE_DUP_FIELD(message, msg_name));
475 if (message == NULL) {
479 ret =
recvmsg(s, message, flags);
485 CPY_TO_USER(message, ret = -1;
goto OUT);
486 DUP_FIELD_TO_USER(message, msg_control, message->msg_controllen, ret = -1;
goto OUT);
487 DUP_FIELD_TO_USER(message, msg_iov, message->msg_iovlen *
sizeof(
struct iovec), ret = -1;
goto OUT);
488 DUP_FIELD_TO_USER(message, msg_name, message->msg_namelen, ret = -1;
goto OUT);
489 DUP_ARRAY_FIELD_TO_USER(message, msg_iov, message->msg_iovlen, iov_base, iov_len, ret = -1;
goto OUT);
491 FREE_DUP_ARRAY_FIELD(message, msg_iov, message->msg_iovlen, iov_base);
492 FREE_DUP_FIELD(message, msg_control);
493 FREE_DUP_FIELD(message, msg_iov);
494 FREE_DUP_FIELD(message, msg_name);
495 return (ret == -1) ? -get_errno() : ret;
int SysGetSockName(int s, struct sockaddr *name, socklen_t *namelen)
int SysAccept(int socket, struct sockaddr *address, socklen_t *addressLen)
int SysBind(int s, const struct sockaddr *name, socklen_t namelen)
int SysGetPeerName(int s, struct sockaddr *name, socklen_t *namelen)
int SysGetSockOpt(int sockfd, int level, int optName, void *optValue, socklen_t *optLen)
ssize_t SysSend(int s, const void *dataptr, size_t size, int flags)
ssize_t SysRecvFrom(int socket, void *buffer, size_t length, int flags, struct sockaddr *address, socklen_t *addressLen)
int SysSetSockOpt(int socket, int level, int optName, const void *optValue, socklen_t optLen)
ssize_t SysSendTo(int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
ssize_t SysSendMsg(int s, const struct msghdr *message, int flags)
ssize_t SysRecvMsg(int s, struct msghdr *message, int flags)
ssize_t SysRecv(int socket, void *buffer, size_t length, int flags)
int SysShutdown(int socket, int how)
int SysConnect(int s, const struct sockaddr *name, socklen_t namelen)
int SysListen(int sockfd, int backlog)
int SysSocket(int domain, int type, int protocol)
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)
只是数据的格式的不同
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 配置项
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)