1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 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 * limitations under the License. 14 */ 15 16 #ifndef SOCKET_APP_H 17 #define SOCKET_APP_H 18 19 #include "sockets.h" 20 #include "socket_common.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #define IPV6_ADDR_IS_NULL(addr) \ 27 (((addr)->sin6_addr.s6_addr[0] == 0) && ((addr)->sin6_addr.s6_addr[1] == 0) && \ 28 ((addr)->sin6_addr.s6_addr[2] == 0) && ((addr)->sin6_addr.s6_addr[3] == 0) && \ 29 ((addr)->sin6_addr.s6_addr[4] == 0) && ((addr)->sin6_addr.s6_addr[5] == 0) && \ 30 ((addr)->sin6_addr.s6_addr[6] == 0) && ((addr)->sin6_addr.s6_addr[7] == 0) && \ 31 ((addr)->sin6_addr.s6_addr[8] == 0) && ((addr)->sin6_addr.s6_addr[9] == 0) && \ 32 ((addr)->sin6_addr.s6_addr[10] == 0) && ((addr)->sin6_addr.s6_addr[11] == 0) && \ 33 ((addr)->sin6_addr.s6_addr[12] == 0) && ((addr)->sin6_addr.s6_addr[13] == 0) && \ 34 ((addr)->sin6_addr.s6_addr[14] == 0) && ((addr)->sin6_addr.s6_addr[15] == 0)) 35 36 FILLP_INT SockSocket(FILLP_INT domain, FILLP_INT type, FILLP_INT protocol); 37 FillpErrorType SockConnect(FILLP_INT sockIndex, FILLP_CONST struct sockaddr *name, socklen_t nameLen); 38 FILLP_ULLONG SockGetRtt(FILLP_INT sockFd); 39 FillpErrorType SockBind(FILLP_INT sockIndex, FILLP_CONST struct sockaddr *name, FILLP_UINT32 nameLen); 40 FILLP_INT SockRecv(FILLP_INT fd, void *mem, FILLP_SIZE_T len, FILLP_INT flags); 41 FILLP_INT SockSend(FILLP_INT sockIndex, FILLP_CONST void *data, FILLP_SIZE_T size, FILLP_INT flags); 42 FILLP_INT SockSendFrame(FILLP_INT sockIndex, FILLP_CONST void *data, FILLP_SIZE_T size, FILLP_INT flags, 43 FILLP_CONST struct FrameInfo *frame); 44 45 FillpErrorType SockReadv(FILLP_INT sockIndex, const struct iovec *iov, FILLP_INT iovCount); 46 FillpErrorType SockWritev(FILLP_INT sockIndex, const struct iovec *iov, FILLP_INT iovCount); 47 FILLP_INT SockRecvmsg(FILLP_INT sockIndex, struct msghdr *msg, FILLP_INT flags); 48 FILLP_INT SockSendmsg(FILLP_INT sockIndex, struct msghdr *msg, FILLP_INT flags); 49 FillpErrorType SockListen(FILLP_INT sockIndex, FILLP_INT backLog); 50 FillpErrorType SockAccept(FILLP_INT fd, struct sockaddr *addr, socklen_t *addrLen); 51 52 FillpErrorType SockClose(FILLP_INT sockIndex); 53 FillpErrorType SockShutdown(FILLP_INT sockIndex, FILLP_INT how); 54 55 56 #ifdef FILLP_LINUX 57 FILLP_INT SockFcntl(FILLP_INT fd, FILLP_INT cmd, FILLP_INT val); 58 #endif 59 60 FILLP_INT SockIoctlsocket(FILLP_INT fd, FILLP_SLONG cmd, FILLP_CONST FILLP_INT *val); 61 62 FILLP_INT SockGetsockname(FILLP_INT sockIndex, struct sockaddr *name, socklen_t *nameLen); 63 64 FILLP_INT SockGetpeername(FILLP_INT sockIndex, struct sockaddr *name, socklen_t *nameLen); 65 66 FILLP_INT SockGetSockEvt(FILLP_INT fd); 67 68 #ifdef FILLP_WIN32 69 #ifndef MSGHDR_IOVEC_DEFINED 70 struct iovec { 71 void *iov_base; 72 size_t iov_len; 73 }; 74 75 struct msghdr { 76 void *msg_name; 77 socklen_t msg_namelen; 78 struct iovec *msg_iov; 79 size_t msg_iovlen; 80 void *msg_control; 81 size_t msg_controllen; 82 int msg_flags; 83 }; 84 85 #define MSGHDR_IOVEC_DEFINED 1 86 #endif 87 88 #ifndef MSG_DONTWAIT 89 #define MSG_DONTWAIT 0x40 90 #endif 91 #endif /* FILLP_WIN32 */ 92 93 FILLP_INT SockEventInfoGet(int s, FtEventCbkInfo *info); 94 95 #define SOCK_DESTROY_CONN(lock, conn, sock, err) \ 96 do { \ 97 (void)SYS_ARCH_RWSEM_RDPOST(lock); \ 98 FillpNetconnDestroy(conn); \ 99 FILLP_SOCK_SET_ERR(sock, err); \ 100 SET_ERRNO(err); \ 101 } while (0) 102 103 #define SOCK_SENDMSG_DATA_MOD_LEN(iovIter, iovRemainLen, itemIter, itemRemainLen, sendLen, dataLen, cpylen) \ 104 do { \ 105 (iovIter) += (cpylen); \ 106 (iovRemainLen) -= (cpylen); \ 107 (itemIter) += (cpylen); \ 108 (itemRemainLen) -= (cpylen); \ 109 (sendLen) += (FILLP_INT)(cpylen); \ 110 (dataLen) += (FILLP_UINT16)(cpylen); \ 111 } while (0) 112 113 #define SOCK_SENDMSG_DATA_MOD_IOV(iovRemainLen, iovIter, msg, index) \ 114 do { \ 115 if ((iovRemainLen) == 0) { \ 116 (iovIter) = (msg)->msg_iov[index].iov_base; \ 117 (iovRemainLen) = (FILLP_UINT32)(msg)->msg_iov[index].iov_len; \ 118 (index)++; \ 119 } \ 120 } while (0) 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif /* SOCKET_APP_H */ 127