udp 可以使用recvfrom 获取客户ip/port . 无法获取本机接口信息。只能使用recvmsg中的辅助数据来实现;
recvmsg 中需要使用到一个结构
struct iovec { /* Scatter/gather array items */
void *iov_base; /* Starting address */
size_t iov_len; /* Number of bytes to transfer */
};
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_control 指向一个辅助数据内存块.
这个辅助数据内存块有个专门的结构 :