本文整理汇总了C++中Address::get_family方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::get_family方法的具体用法?C++ Address::get_family怎么用?C++ Address::get_family使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::get_family方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Bind
// SOCKMGMT
evutil_socket_t Channel::Bind (Address address, sckrwecb_t callbacks) {
struct sockaddr_storage sa = address;
evutil_socket_t fd;
// Arno, 2013-06-05: MacOS X bind fails if sizeof(struct sockaddr_storage) is passed.
int len = address.get_family_sockaddr_length(), sndbuf=1<<20, rcvbuf=1<<20;
#define dbnd_ensure(x) { if (!(x)) { \
print_error("binding fails"); close_socket(fd); return INVALID_SOCKET; } }
dbnd_ensure ( (fd = socket(address.get_family(), SOCK_DGRAM, 0)) >= 0 );
dbnd_ensure( make_socket_nonblocking(fd) ); // FIXME may remove this
int enable = true;
dbnd_ensure ( setsockopt(fd, SOL_SOCKET, SO_SNDBUF,
(setsockoptptr_t)&sndbuf, sizeof(int)) == 0 );
dbnd_ensure ( setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
(setsockoptptr_t)&rcvbuf, sizeof(int)) == 0 );
//setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (setsockoptptr_t)&enable, sizeof(int));
if (address.get_family() == AF_INET6)
{
// Arno, 2012-12-04: Enable IPv4 on this IPv6 socket, addresses
// show up as IPv4-mapped IPv6.
int no = 0;
dbnd_ensure ( setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (setsockoptptr_t)&no, sizeof(no)) == 0 );
}
dbnd_ensure ( ::bind(fd, (sockaddr*)&sa, len) == 0 );
callbacks.sock = fd;
sock_open[sock_count++] = callbacks;
return fd;
}
示例2: evbuffer_add_pexaddr
int swift::evbuffer_add_pexaddr(struct evbuffer *evb, Address& a)
{
int ret = -1;
if (a.get_family() == AF_INET)
{
ret = evbuffer_add_8(evb, SWIFT_PEX_RESv4);
ret = evbuffer_add_32be(evb, a.ipv4());
ret = evbuffer_add_16be(evb, a.port());
}
else
{
struct in6_addr ipv6 = a.ipv6();
ret = evbuffer_add_8(evb, SWIFT_PEX_RESv6);
for (int i=0; i<16; i++)
ret = evbuffer_add_8(evb, ipv6.s6_addr[i] );
ret = evbuffer_add_16be(evb, a.port());
}
return ret;
}