网络编程
1、不相关线程传送文件描述符使用unix套接字的CMSG的辅助数据传输,其中CMSG_DATA宏返回cmsg结构中辅助数据的指针,而这个CMSG_DATA宏仅仅是根据其参数提供的cmsg指针来返回其中的辅助数据成员,没有什么特殊之处。而内核实际是根据套接字选项,传送进程描述表中指向文件表的指针。
根据linux中 /usr/src/linux-headers-5.11.0-41-generic/include/linux/socket.h 文件中的定义
#define CMSG_DATA(cmsg) \ ((void *)(cmsg) + sizeof(struct cmsghdr))
struct msghdr { 51 void *msg_name; /* ptr to socket address structure */ 52 int msg_namelen; /* size of socket address structure */ 53 struct iov_iter msg_iter; /* data */ 54 55 /* 56 * Ancillary data. msg_control_user is the user buffer used for the 57 * recv* side when msg_control_is_user is set, msg_control is the kernel 58 * buffer used for all other cases. 59 */ 60 union { 61 void *msg_control; 62 void __user *msg_control_user; 63 }; 64 bool msg_control_is_user : 1; 65 __kernel_size_t msg_controllen; /* ancillary data buffer length */ 66 unsigned int msg_flags; /* flags on received message */ 67 struct kiocb *msg_iocb; /* ptr to iocb for async requests */ 68 };