一、函数原型
#include <sys/socket.h>
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
//返回值:成功返回读取/写出的字节数;失败返回-1
二、struct msghdr结构体
struct msghdr {
void *msg_name; /* optional address */
socklen_t msg_namelen; /* size of address */
struct iovec *msg_iov; /* scatter/gather array */
size_t msg_iovlen; /* # elements in msg_iov */
void *msg_control; /* ancillary data, see below */
size_t msg_controllen; /* ancillary data buffer len */
int msg_flags; /* flags on received message */
};
msg_name、msg_namelen:
msg_iov、msg_iovlen:
- 用于接受/发送数据的缓冲区数组,msg_iolen是这个缓冲区数组的大小,而不是单个缓冲区的大小
msg_control、msg_controllen:
msg_flags: