本文整理汇总了C++中address::v4方法的典型用法代码示例。如果您正苦于以下问题:C++ address::v4方法的具体用法?C++ address::v4怎么用?C++ address::v4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类address
的用法示例。
在下文中一共展示了address::v4方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: set_address
static bool set_address(sockaddr_storage &t, const address &addr) {
if (addr.family() == AF_INET)
memcpy(&t, addr.v4(), addr.addrlen());
else if (addr.family() == AF_INET6)
memcpy(&t, addr.v6(), addr.addrlen());
else
return false;
return true;
}
示例2: is_equal
bool address::is_equal(const address &a) const {
if (stor.ss_family != a.stor.ss_family)
return false;
if (stor.ss_family == AF_INET6)
return memcmp(&v6()->sin6_addr, &a.v6()->sin6_addr, sizeof(in6_addr)) == 0;
else if (stor.ss_family == AF_INET)
return v4()->sin_addr.s_addr == a.v4()->sin_addr.s_addr;
return false;
}
示例3: copy_address
bool address::copy_address(const address &source) {
if (family() != source.family())
return false;
if (stor.ss_family == AF_INET6)
v6()->sin6_addr = source.v6()->sin6_addr;
else
v4()->sin_addr = source.v4()->sin_addr;
return true;
}
示例4: _McastListenOldAPI
int _McastListenOldAPI(int sock, const address &grpaddr) {
if (grpaddr.family() == AF_INET6) {
ipv6_mreq mreq;
mreq.ipv6mr_interface = mcastInterface;
mreq.ipv6mr_multiaddr = grpaddr.v6()->sin6_addr;
return setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq));
} else {
ip_mreq mreq;
memset(&mreq, 0, sizeof(mreq));
// Specifying the interface doesn't work, there's ip_mreqn in linux..
// but what about other OSs? -hugo
mreq.imr_multiaddr = grpaddr.v4()->sin_addr;
return setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
}
}