本文整理汇总了C++中boost::asio::ip::address类的典型用法代码示例。如果您正苦于以下问题:C++ address类的具体用法?C++ address怎么用?C++ address使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了address类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1:
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)
);
}
}
}
}
开发者ID:nelsonleezonhat,项目名称:PolyProxy,代码行数:25,代码来源:PeerID.cpp
示例2: LogPrint
void RouterContext::UpdateNTCPV6Address (const boost::asio::ip::address& host)
{
bool updated = false, found = false;
int port = 0;
auto& addresses = m_RouterInfo.GetAddresses ();
for (auto& addr : addresses)
{
if (addr.host.is_v6 () && addr.transportStyle == i2p::data::RouterInfo::eTransportNTCP)
{
if (addr.host != host)
{
addr.host = host;
updated = true;
}
found = true;
}
else
port = addr.port;
}
if (!found)
{
// create new address
m_RouterInfo.AddNTCPAddress (host.to_string ().c_str (), port);
auto mtu = i2p::util::net::GetMTU (host);
if (mtu)
{
LogPrint ("Our v6 MTU=", mtu);
if (mtu > 1472) mtu = 1472;
}
m_RouterInfo.AddSSUAddress (host.to_string ().c_str (), port, GetIdentHash (), mtu ? mtu : 1472); // TODO
updated = true;
}
if (updated)
UpdateRouterInfo ();
}
开发者ID:edwtjo,项目名称:i2pd,代码行数:35,代码来源:RouterContext.cpp
示例3: 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);
}
开发者ID:AwkwardDev,项目名称:RE,代码行数:32,代码来源:PacketLog.cpp
示例4: basic_endpoint
/// Construct an endpoint using a port number and an IP address. This
/// constructor may be used for accepting connections on a specific interface
/// or for making a connection to a remote endpoint.
basic_endpoint(const boost::asio::ip::address& addr, unsigned short port_num)
: data_()
{
using namespace std; // For memcpy.
if (addr.is_v4())
{
data_.v4.sin_family = AF_INET;
data_.v4.sin_port =
boost::asio::detail::socket_ops::host_to_network_short(port_num);
data_.v4.sin_addr.s_addr =
boost::asio::detail::socket_ops::host_to_network_long(
addr.to_v4().to_ulong());
}
else
{
data_.v6.sin6_family = AF_INET6;
data_.v6.sin6_port =
boost::asio::detail::socket_ops::host_to_network_short(port_num);
data_.v6.sin6_flowinfo = 0;
boost::asio::ip::address_v6 v6_addr = addr.to_v6();
boost::asio::ip::address_v6::bytes_type bytes = v6_addr.to_bytes();
memcpy(data_.v6.sin6_addr.s6_addr, bytes.elems, 16);
data_.v6.sin6_scope_id = v6_addr.scope_id();
}
}
开发者ID:JupiterSmalltalk,项目名称:openqwaq,代码行数:28,代码来源:basic_endpoint.hpp
示例5: sockRx
void
initialize(ip::address address)
{
ip::address mcastAddr;
if (address.is_v4()) {
// the administratively scoped group 224.0.0.254 is reserved for experimentation (RFC 4727)
mcastAddr = ip::address_v4(0xE00000FE);
}
else {
// the group FF0X::114 is reserved for experimentation at all scope levels (RFC 4727)
auto v6Addr = ip::address_v6::from_string("FF01::114");
v6Addr.scope_id(address.to_v6().scope_id());
mcastAddr = v6Addr;
}
mcastEp = udp::endpoint(mcastAddr, 7373);
remoteMcastEp = udp::endpoint(mcastAddr, 8383);
MulticastUdpTransport::openRxSocket(remoteSockRx, mcastEp, address);
MulticastUdpTransport::openTxSocket(remoteSockTx, udp::endpoint(address, 0), nullptr, true);
udp::socket sockRx(g_io);
udp::socket sockTx(g_io);
MulticastUdpTransport::openRxSocket(sockRx, remoteMcastEp, address);
MulticastUdpTransport::openTxSocket(sockTx, udp::endpoint(address, txPort), nullptr, true);
face = make_unique<Face>(make_unique<DummyLinkService>(),
make_unique<MulticastUdpTransport>(mcastEp, std::move(sockRx), std::move(sockTx),
ndn::nfd::LINK_TYPE_MULTI_ACCESS));
transport = static_cast<MulticastUdpTransport*>(face->getTransport());
receivedPackets = &static_cast<DummyLinkService*>(face->getLinkService())->receivedPackets;
BOOST_REQUIRE_EQUAL(transport->getState(), TransportState::UP);
}
开发者ID:named-data,项目名称:NFD,代码行数:33,代码来源:multicast-udp-transport-fixture.hpp
示例6: contains
bool contains(const boost::asio::ip::address & addr)
{
if(addr.is_v4() == false)
return false;
hippolib::subnet s(m_network, m_netmask);
return s.containsIp(addr.to_v4());
}
开发者ID:handsome616,项目名称:pppoe-killer,代码行数:8,代码来源:host.hpp
示例7: 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;
}
开发者ID:opendaylight,项目名称:opflex,代码行数:8,代码来源:Network.cpp
示例8: 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());
}
}
开发者ID:AMDmi3,项目名称:spring,代码行数:8,代码来源:Socket.cpp
示例9: address_is_any
bool gateway::address_is_any(const boost::asio::ip::address & addr)
{
if (addr.is_v4())
{
return addr.to_v4() == boost::asio::ip::address_v4::any();
}
return addr.to_v6() == boost::asio::ip::address_v6::any();
}
开发者ID:jaggedMiner,项目名称:vanillacoin,代码行数:10,代码来源:gateway.cpp
示例10: address_is_any
/**
* If true the address is any.
*/
static bool address_is_any(const boost::asio::ip::address & addr)
{
if (addr.is_v4())
{
return addr.to_v4() == boost::asio::ip::address_v4::any();
}
else
{
return addr.to_v6() == boost::asio::ip::address_v6::any();
}
}
开发者ID:greenmo000,项目名称:vcash,代码行数:14,代码来源:network.hpp
示例11: address_is_multicast
bool gateway::address_is_multicast(
const boost::asio::ip::address & addr
)
{
if (addr.is_v4())
{
return addr.to_v4().is_multicast();
}
return addr.to_v6().is_multicast();
}
开发者ID:jaggedMiner,项目名称:vanillacoin,代码行数:11,代码来源:gateway.cpp
示例12: 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))
;
}
开发者ID:zyberpunker,项目名称:nscp,代码行数:8,代码来源:socket_helpers.hpp
示例13: address_is_multicast
/**
* If true the address is multicast.
*/
static bool address_is_multicast(
const boost::asio::ip::address & addr
)
{
if (addr.is_v4())
{
return addr.to_v4().is_multicast();
}
else
{
return addr.to_v6().is_multicast();
}
}
开发者ID:greenmo000,项目名称:vcash,代码行数:16,代码来源:network.hpp
示例14: addMatchSubnet
static void addMatchSubnet(struct match* match,
const boost::asio::ip::address& ip,
uint8_t prefixLen, bool src,
uint16_t& ethType) {
if (ip.is_v4()) {
switch (ethType) {
case 0:
ethType = eth::type::IP;
/* fall through */
case eth::type::IP:
case eth::type::ARP:
break;
default:
return;
}
if (prefixLen > 32) prefixLen = 32;
uint32_t mask = (prefixLen != 0)
? (~((uint32_t)0) << (32 - prefixLen))
: 0;
uint32_t addr = ip.to_v4().to_ulong() & mask;
match_set_dl_type(match, htons(ethType));
if (src)
match_set_nw_src_masked(match, htonl(addr), htonl(mask));
else
match_set_nw_dst_masked(match, htonl(addr), htonl(mask));
} else {
switch (ethType) {
case 0:
ethType = eth::type::IPV6;
/* fall through */
case eth::type::IPV6:
break;
default:
return;
}
if (prefixLen > 128) prefixLen = 128;
struct in6_addr mask;
struct in6_addr addr;
network::compute_ipv6_subnet(ip.to_v6(), prefixLen, &mask, &addr);
match_set_dl_type(match, htons(ethType));
if (src)
match_set_ipv6_src_masked(match, &addr, &mask);
else
match_set_ipv6_dst_masked(match, &addr, &mask);
}
}
开发者ID:opendaylight,项目名称:opflex,代码行数:49,代码来源:FlowBuilder.cpp
示例15: remote_address
bool TcpProxyServer::GetRemoteAddressAndPort(boost::asio::ip::tcp::socket& clientSocket, boost::asio::ip::address& remoteAddress, unsigned short& remotePort)
{
boost::asio::ip::tcp::socket::endpoint_type userAgentEnpoint = clientSocket.remote_endpoint();
unsigned short userAgentPort = userAgentEnpoint.port();
boost::asio::ip::address userAgentIP = userAgentEnpoint.address();
if(userAgentIP != boost::asio::ip::address_v4::from_string("127.0.0.1")) {
return false;
}
std::pair<u_long, USHORT> remoteAddressPair = WinsockHooker::GetRemoteAddressPair(userAgentPort);
if(remoteAddressPair.first == 0ul) {
return false;
}
boost::asio::ip::address_v4 remote_address(remoteAddressPair.first);
unsigned short remote_port = remoteAddressPair.second;
if(remote_address == boost::asio::ip::address_v4::from_string("127.0.0.1") && remote_port == listen_port)
{
return false;
}
remoteAddress = remote_address;
remotePort = remote_port;
TSINFO4CXX("Connect: IP:" << remoteAddress.to_string() << ", Port: " << remotePort);
return true;
}
开发者ID:yuanbaoyuele,项目名称:yuanbaoyule,代码行数:27,代码来源:TcpProxyServer.cpp
示例16: isLoopback
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;
}
开发者ID:,项目名称:,代码行数:17,代码来源:
示例17: IsBlockedAddress
bool Server::IsBlockedAddress(const boost::asio::ip::address& address)
{
BOOST_FOREACH(const auto& pattern, config_.blocking_address_patterns()) {
if (network::Utils::MatchWithWildcard(pattern, address.to_string())) {
return true;
}
}
return false;
}
开发者ID:h2so5,项目名称:MikuMikuOnline,代码行数:9,代码来源:Server.cpp
示例18: 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;
}
开发者ID:Tener,项目名称:asdsk-2011,代码行数:44,代码来源:showroute.cpp
示例19: checkCommonNames
bool PeerID::Certificate::checkCommonNames(const boost::asio::ip::address& address) const
{
std::string ipString = address.to_string();
return checkCommonNames(
[&ipString](char const * host, std::size_t len) -> bool
{
return boost::iequals(
ipString,
std::make_pair(host, host + len));
});
}
开发者ID:nelsonleezonhat,项目名称:PolyProxy,代码行数:11,代码来源:PeerID.cpp
示例20: 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;
}
开发者ID:greenmo000,项目名称:vcash,代码行数:24,代码来源:network.hpp
注:本文中的boost::asio::ip::address类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论