25 if (family == AF_INET)
27 sockaddr_in addr = {};
28 addr.sin_family = AF_INET;
31 else if (family == AF_INET6)
33 sockaddr_in6 addr = {};
34 addr.sin6_family = AF_INET6;
49 char controldata[1000];
51 struct msghdr hdr = {};
52 sockaddr_storage addrRemote = {};
57 hdr.msg_name = &addrRemote;
58 hdr.msg_namelen =
sizeof(addrRemote);
61 hdr.msg_control = controldata;
62 hdr.msg_controllen =
ARRAYSIZE(controldata);
64 ret = ::recvmsg(sockfd, &hdr, flags);
75 struct cmsghdr* pCmsg = NULL;
79 for (pCmsg = CMSG_FIRSTHDR(&hdr); pCmsg != NULL; pCmsg = CMSG_NXTHDR(&hdr, pCmsg))
82 if ((pCmsg->cmsg_level == IPPROTO_IPV6) && (pCmsg->cmsg_type == IPV6_PKTINFO) && CMSG_DATA(pCmsg))
84 struct in6_pktinfo* pInfo = (in6_pktinfo*)CMSG_DATA(pCmsg);
85 sockaddr_in6 addr = {};
86 addr.sin6_family = AF_INET6;
87 addr.sin6_addr = pInfo->ipi6_addr;
98 if ((pCmsg->cmsg_level == IPPROTO_IP) && (pCmsg->cmsg_type==IP_PKTINFO) && CMSG_DATA(pCmsg))
100 struct in_pktinfo* pInfo = (in_pktinfo*)CMSG_DATA(pCmsg);
101 sockaddr_in addr = {};
102 addr.sin_family = AF_INET;
103 addr.sin_addr = pInfo->ipi_addr;
109 #ifdef IP_RECVDSTADDR 111 if ((pCmsg->cmsg_level == IPPROTO_IP) && (pCmsg->cmsg_type==IP_RECVDSTADDR) && CMSG_DATA(pCmsg))
113 sockaddr_in addr = {};
114 addr.sin_family = AF_INET;
115 addr.sin_addr = *(in_addr*)CMSG_DATA(pCmsg);
ssize_t recvfromex(int sockfd, void *buf, size_t len, int flags, CSocketAddress *pSrcAddr, CSocketAddress *pDstAddr)
static void InitSocketAddress(int family, CSocketAddress *pAddr)