本文整理汇总了C++中address::set_family方法的典型用法代码示例。如果您正苦于以下问题:C++ address::set_family方法的具体用法?C++ address::set_family怎么用?C++ address::set_family使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类address
的用法示例。
在下文中一共展示了address::set_family方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RecvMsg
int RecvMsg(int sock, address &from, address &to, uint8_t *buffer, int buflen, int &ttl, uint64_t &ts) {
int len;
struct msghdr msg;
struct iovec iov;
uint8_t ctlbuf[64];
from.set_family(beaconUnicastAddr.family());
msg.msg_name = (char *)from.saddr();
msg.msg_namelen = from.addrlen();
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = (char *)ctlbuf;
msg.msg_controllen = sizeof(ctlbuf);
msg.msg_flags = 0;
iov.iov_base = (char *)buffer;
iov.iov_len = buflen;
len = recvmsg(sock, &msg, 0);
if (len < 0)
return len;
ts = 0;
ttl = 127;
to = beaconUnicastAddr;
if (msg.msg_controllen > 0) {
for (cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr; hdr = CMSG_NXTHDR(&msg, hdr)) {
if (hdr->cmsg_level == IPPROTO_IPV6 && hdr->cmsg_type == IPV6_HOPLIMIT) {
ttl = *(int *)CMSG_DATA(hdr);
#ifdef IPV6_PKTINFO
} else if (hdr->cmsg_level == IPPROTO_IPV6 && hdr->cmsg_type == IPV6_PKTINFO) {
if (hdr->cmsg_len == CMSG_LEN(sizeof(in6_pktinfo))) {
in6_pktinfo *pktinfo = (in6_pktinfo *)CMSG_DATA(hdr);
to.set_family(AF_INET6);
to.v6()->sin6_addr = pktinfo->ipi6_addr;
}
#endif
#ifdef IP_RECVTTL
} else if (hdr->cmsg_level == IPPROTO_IP && hdr->cmsg_type == IP_RECVTTL) {
ttl = *(uint8_t *)CMSG_DATA(hdr);
#endif
} else if (hdr->cmsg_level == IPPROTO_IP && hdr->cmsg_type == IP_TTL) {
ttl = *(int *)CMSG_DATA(hdr);
#ifdef SO_TIMESTAMP
} else if (hdr->cmsg_level == SOL_SOCKET && hdr->cmsg_type == SO_TIMESTAMP) {
timeval *tv = (timeval *)CMSG_DATA(hdr);
ts = tv->tv_sec;
ts *= 1000;
ts += tv->tv_usec / 1000;
#endif
}
}
}
if (!ts) {
ts = get_time_of_day();
}
return len;
}