本文整理汇总了C++中boost::asio::ip::address::is_v6方法的典型用法代码示例。如果您正苦于以下问题:C++ address::is_v6方法的具体用法?C++ address::is_v6怎么用?C++ address::is_v6使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::address
的用法示例。
在下文中一共展示了address::is_v6方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: is_allowed
bool is_allowed(const boost::asio::ip::address &address, std::list<std::string> &errors) {
return (entries_v4.empty()&&entries_v6.empty())
|| (address.is_v4() && is_allowed_v4(address.to_v4().to_bytes(), errors))
|| (address.is_v6() && is_allowed_v6(address.to_v6().to_bytes(), errors))
|| (address.is_v6() && address.to_v6().is_v4_compatible() && is_allowed_v4(address.to_v6().to_v4().to_bytes(), errors))
|| (address.is_v6() && address.to_v6().is_v4_mapped() && is_allowed_v4(address.to_v6().to_v4().to_bytes(), errors))
;
}
示例2: LogPacket
void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address const& addr, uint16 port)
{
std::lock_guard<std::mutex> lock(_logPacketLock);
PacketHeader header;
*reinterpret_cast<uint32*>(header.Direction) = direction == CLIENT_TO_SERVER ? 0x47534d43 : 0x47534d53;
header.ConnectionId = 0;
header.ArrivalTicks = getMSTime();
header.OptionalDataSize = sizeof(header.OptionalData);
memset(header.OptionalData.SocketIPBytes, 0, sizeof(header.OptionalData.SocketIPBytes));
if (addr.is_v4())
{
auto bytes = addr.to_v4().to_bytes();
memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size());
}
else if (addr.is_v6())
{
auto bytes = addr.to_v6().to_bytes();
memcpy(header.OptionalData.SocketIPBytes, bytes.data(), bytes.size());
}
header.OptionalData.SocketPort = port;
header.Length = packet.size() + sizeof(header.Opcode);
header.Opcode = packet.GetOpcode();
fwrite(&header, sizeof(header), 1, _file);
if (!packet.empty())
fwrite(packet.contents(), 1, packet.size(), _file);
fflush(_file);
}
示例3:
bool PeerID::Certificate::checkAltNames(boost::asio::ip::address& address) const
{
GENERAL_NAMES* gens = static_cast<GENERAL_NAMES*>(
X509_get_ext_d2i(x509_, NID_subject_alt_name, 0, 0));
BOOST_SCOPE_EXIT(gens){
GENERAL_NAMES_free(gens);
}BOOST_SCOPE_EXIT_END;
for (int i = 0; i < sk_GENERAL_NAME_num(gens); ++i)
{
GENERAL_NAME* gen = sk_GENERAL_NAME_value(gens, i);
if (gen->type == GEN_IPADD)
{
ASN1_OCTET_STRING* ip = gen->d.iPAddress;
if (ip->type == V_ASN1_OCTET_STRING && ip->data)
{
return (
(address.is_v4() && ip->length == 4 &&
std::memcmp(address.to_v4().to_bytes().data(), ip->data, 4) == 0) ||
(address.is_v6() && ip->length == 16 &&
std::memcmp(address.to_v6().to_bytes().data(), ip->data, 16) == 0)
);
}
}
}
}
示例4: IsLoopbackAddress
bool IsLoopbackAddress(const boost::asio::ip::address& addr) {
if (addr.is_v6()) {
return addr.to_v6().is_loopback();
} else {
return (addr.to_v4() == boost::asio::ip::address_v4::loopback());
}
}
示例5: is_link_local
bool is_link_local(const boost::asio::ip::address& addr) {
if (addr.is_v6() && addr.to_v6().is_link_local())
return true;
if (addr.is_v4() &&
(mask_address(addr, 16) == address::from_string("169.254.0.0")))
return true;
return false;
}
示例6: subsumes
bool subsumes( Entry other )
{
if ( addr.is_v6() != other.addr.is_v6() )
{
// jeden adres jest v6, drugi v4
// zwracamy zawsze false
return false;
}
if ( addr.is_v6() )
{
boost::asio::ip::address_v6::bytes_type a1 = addr.to_v6().to_bytes();
boost::asio::ip::address_v6::bytes_type a2 = other.addr.to_v6().to_bytes();
int mask_left = mask;
for(unsigned int i = 0; i < a1.size(); i++)
{
int tmp = (1 << std::max(0,std::min(mask_left,8)))-1;
unsigned char apply_mask = tmp;
mask_left -= 8;
a1[i] &= apply_mask;
a2[i] &= apply_mask;
}
bool val = boost::asio::ip::address_v6(a1) == boost::asio::ip::address_v6(a2);
return val;
}
else
{
boost::asio::ip::address_v4::bytes_type a1 = addr.to_v4().to_bytes();
boost::asio::ip::address_v4::bytes_type a2 = other.addr.to_v4().to_bytes();
int mask_left = mask;
for(unsigned int i = 0; i < a1.size(); i++)
{
int tmp = (1 << std::max(0,std::min(mask_left,8)))-1;
unsigned char apply_mask = tmp;
mask_left -= 8;
a1[i] &= apply_mask;
a2[i] &= apply_mask;
}
bool val = boost::asio::ip::address_v4(a1) == boost::asio::ip::address_v4(a2);
return val;
}
return false;
}
示例7: if
static bool
isLoopback(const boost::asio::ip::address& addr)
{
if (addr.is_loopback()) {
return true;
}
// Workaround for loopback IPv4-mapped IPv6 addresses
// see https://svn.boost.org/trac/boost/ticket/9084
else if (addr.is_v6()) {
auto addr6 = addr.to_v6();
if (addr6.is_v4_mapped()) {
return addr6.to_v4().is_loopback();
}
}
return false;
}
示例8: address_is_private
/**
* If true the address is private.
*/
static bool address_is_private(
const boost::asio::ip::address & addr
)
{
if (addr.is_v6())
{
return addr.to_v6().is_link_local();
}
else
{
std::uint32_t ip = addr.to_v4().to_ulong();
return (
(ip & 0xff000000) == 0x0a000000 ||
(ip & 0xfff00000) == 0xac100000 ||
(ip & 0xffff0000) == 0xc0a80000
);
}
return false;
}
示例9: ClientAllowed
bool ClientAllowed(const boost::asio::ip::address& address)
{
// Make sure that IPv4-compatible and IPv4-mapped IPv6 addresses are treated as IPv4 addresses
if (address.is_v6()
&& (address.to_v6().is_v4_compatible()
|| address.to_v6().is_v4_mapped()))
return ClientAllowed(address.to_v6().to_v4());
if (address == asio::ip::address_v4::loopback()
|| address == asio::ip::address_v6::loopback()
|| (address.is_v4()
// Check whether IPv4 addresses match 127.0.0.0/8 (loopback subnet)
&& (address.to_v4().to_ulong() & 0xff000000) == 0x7f000000))
return true;
const string strAddress = address.to_string();
const vector<string>& vAllow = SysCfg().GetMultiArgs("-rpcallowip");
for (auto strAllow : vAllow)
if (WildcardMatch(strAddress, strAllow))
return true;
return false;
}
示例10: is_allowed
bool is_allowed(const boost::asio::ip::address &address, std::list<std::string> &errors) {
return (address.is_v4() && is_allowed_v4(address.to_v4().to_ulong(), errors))
|| (address.is_v6() && address.to_v6().is_v4_compatible() && is_allowed_v4(address.to_v6().to_v4().to_ulong(), errors))
|| (address.is_v6() && address.to_v6().is_v4_mapped() && is_allowed_v4(address.to_v6().to_v4().to_ulong(), errors));
}
示例11: operator
bool
operator()(const boost::asio::ip::address& address)
{
return address.is_v6();
}
示例12: HostAddressToEntry
// ////////////////////////////////////////////////////////////////////////////
HostEntry HostAddressToEntry(const boost::asio::ip::address &host_address)
{
return((host_address.is_v6()) ?
HostAddressToEntry(host_address.to_v6()) :
HostAddressToEntry(host_address.to_v4()));
}
示例13: AbstractReceivable
Client::Client(const std::string& name, const boost::asio::ip::address& ip) :
AbstractReceivable(2 + (ip.is_v6() ? 16 : 4) + name.size()),
its_name(name),
its_ip(ip)
{
}