本文整理汇总了C++中address::to_v6方法的典型用法代码示例。如果您正苦于以下问题:C++ address::to_v6方法的具体用法?C++ address::to_v6怎么用?C++ address::to_v6使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类address
的用法示例。
在下文中一共展示了address::to_v6方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: add_rule
void ip_filter::add_rule(address first, address last, int flags)
{
if (first.is_v4())
{
assert(last.is_v4());
m_filter4.add_rule(first.to_v4(), last.to_v4(), flags);
}
else if (first.is_v6())
{
assert(last.is_v6());
m_filter6.add_rule(first.to_v6(), last.to_v6(), flags);
}
else
assert(false);
}
示例2: access
int ip_filter::access(address const& addr) const
{
if (addr.is_v4())
return m_filter4.access(addr.to_v4());
assert(addr.is_v6());
return m_filter6.access(addr.to_v6());
}
示例3: cidr_distance
// returns the number of bits in that differ from the right
// between the addresses.
int cidr_distance(address const& a1, address const& a2)
{
if (a1.is_v4() && a2.is_v4())
{
// both are v4
address_v4::bytes_type b1 = a1.to_v4().to_bytes();
address_v4::bytes_type b2 = a2.to_v4().to_bytes();
return address_v4::bytes_type::static_size * 8
- common_bits(b1.c_array(), b2.c_array(), b1.size());
}
address_v6::bytes_type b1;
address_v6::bytes_type b2;
if (a1.is_v4()) b1 = address_v6::v4_mapped(a1.to_v4()).to_bytes();
else b1 = a1.to_v6().to_bytes();
if (a2.is_v4()) b2 = address_v6::v4_mapped(a2.to_v4()).to_bytes();
else b2 = a2.to_v6().to_bytes();
return address_v6::bytes_type::static_size * 8
- common_bits(b1.c_array(), b2.c_array(), b1.size());
}
示例4: cidr_distance
// returns the number of bits in that differ from the right
// between the addresses. The larger number, the further apart
// the IPs are
int cidr_distance(address const& a1, address const& a2)
{
#if LIBED2K_USE_IPV6
if (a1.is_v4() && a2.is_v4())
{
#endif
// both are v4
address_v4::bytes_type b1 = a1.to_v4().to_bytes();
address_v4::bytes_type b2 = a2.to_v4().to_bytes();
return address_v4::bytes_type().size() * 8 - common_bits(b1.data(), b2.data(), b1.size());
#if LIBED2K_USE_IPV6
}
address_v6::bytes_type b1;
address_v6::bytes_type b2;
if (a1.is_v4()) b1 = address_v6::v4_mapped(a1.to_v4()).to_bytes();
else b1 = a1.to_v6().to_bytes();
if (a2.is_v4()) b2 = address_v6::v4_mapped(a2.to_v4()).to_bytes();
else b2 = a2.to_v6().to_bytes();
return address_v6::bytes_type().size() * 8 - common_bits(b1.data(), b2.data(), b1.size());
#endif
}
示例5: write_address
void write_address(address const& a, OutIt& out)
{
if (a.is_v4())
{
write_uint32(a.to_v4().to_ulong(), out);
}
else if (a.is_v6())
{
address_v6::bytes_type bytes
= a.to_v6().to_bytes();
std::copy(bytes.begin(), bytes.end(), out);
}
}
示例6: mask_address
address mask_address(const address& addrIn, uint8_t prefixLen) {
if (addrIn.is_v4()) {
prefixLen = std::min<uint8_t>(prefixLen, 32);
uint32_t mask = get_subnet_mask_v4(prefixLen);
return address_v4(addrIn.to_v4().to_ulong() & mask);
}
struct in6_addr mask;
struct in6_addr addr6;
prefixLen = std::min<uint8_t>(prefixLen, 128);
compute_ipv6_subnet(addrIn.to_v6(), prefixLen, &mask, &addr6);
address_v6::bytes_type data;
std::memcpy(data.data(), &addr6, sizeof(addr6));
return address_v6(data);
}
示例7: address_to_bytes
std::string address_to_bytes(address const& a)
{
#if LIBED2K_USE_IPV6
if (a.is_v6())
{
address_v6::bytes_type b = a.to_v6().to_bytes();
return std::string((char*)&b[0], b.size());
}
else
#endif
{
address_v4::bytes_type b = a.to_v4().to_bytes();
return std::string((char*)&b[0], b.size());
}
}
示例8: write_address
void write_address(address const& a, OutIt&& out)
{
#if TORRENT_USE_IPV6
if (a.is_v4())
{
#endif
write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
}
else if (a.is_v6())
{
for (auto b : a.to_v6().to_bytes())
write_uint8(b, out);
}
#endif
}
示例9: write_address
void write_address(address const& a, OutIt& out)
{
#if TORRENT_USE_IPV6
if (a.is_v4())
{
#endif
write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
}
else if (a.is_v6())
{
address_v6::bytes_type bytes
= a.to_v6().to_bytes();
std::copy(bytes.begin(), bytes.end(), out);
}
#endif
}
示例10: write_address
void write_address(address const& a, OutIt& out)
{
#if TORRENT_USE_IPV6
if (a.is_v4())
{
#endif
write_uint32(a.to_v4().to_ulong(), out);
#if TORRENT_USE_IPV6
}
else if (a.is_v6())
{
typedef address_v6::bytes_type bytes_t;
bytes_t bytes = a.to_v6().to_bytes();
for (bytes_t::iterator i = bytes.begin()
, end(bytes.end()); i != end; ++i)
write_uint8(*i, out);
}
#endif
}