当前位置: 首页>>代码示例>>C++>>正文


C++ address::is_v4方法代码示例

本文整理汇总了C++中address::is_v4方法的典型用法代码示例。如果您正苦于以下问题:C++ address::is_v4方法的具体用法?C++ address::is_v4怎么用?C++ address::is_v4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在address的用法示例。


在下文中一共展示了address::is_v4方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: local_endpoint

	tcp::endpoint utp_socket_manager::local_endpoint(address const& remote, error_code& ec) const
	{
		tcp::endpoint socket_ep = m_sock.local_endpoint(ec);

		// first enumerate the routes in the routing table
		if (time_now() - m_last_route_update > seconds(60))
		{
			m_last_route_update = time_now();
			error_code ec;
			m_routes = enum_routes(m_sock.get_io_service(), ec);
			if (ec) return socket_ep;
		}

		if (m_routes.empty()) return socket_ep;
		// then find the best match
		ip_route* best = &m_routes[0];
		for (std::vector<ip_route>::iterator i = m_routes.begin()
			, end(m_routes.end()); i != end; ++i)
		{
			if (is_any(i->destination) && i->destination.is_v4() == remote.is_v4())
			{
				best = &*i;
				continue;
			}

			if (match_addr_mask(remote, i->destination, i->netmask))
			{
				best = &*i;
				continue;
			}
		}

		// best now tells us which interface we would send over
		// for this target. Now figure out what the local address
		// is for that interface

		if (time_now() - m_last_if_update > seconds(60))
		{
			m_last_if_update = time_now();
			error_code ec;
			m_interfaces = enum_net_interfaces(m_sock.get_io_service(), ec);
			if (ec) return socket_ep;
		}

		for (std::vector<ip_interface>::iterator i = m_interfaces.begin()
			, end(m_interfaces.end()); i != end; ++i)
		{
			if (i->interface_address.is_v4() != remote.is_v4())
				continue;

			if (strcmp(best->name, i->name) == 0)
				return tcp::endpoint(i->interface_address, socket_ep.port());
		}
		return socket_ep;
	}
开发者ID:ABuus,项目名称:libtorrent,代码行数:55,代码来源:utp_socket_manager.cpp

示例2: mtu_for_dest

	void utp_socket_manager::mtu_for_dest(address const& addr, int& link_mtu, int& utp_mtu)
	{

		int mtu = 0;
		if (is_teredo(addr)) mtu = TORRENT_TEREDO_MTU;
		else mtu = TORRENT_ETHERNET_MTU;

#if defined __APPLE__
		// apple has a very strange loopback. It appears you can't
		// send messages of the reported MTU size, and you don't get
		// EWOULDBLOCK either.
		if (is_loopback(addr))
		{
			if (is_teredo(addr)) mtu = TORRENT_TEREDO_MTU;
			else mtu = TORRENT_ETHERNET_MTU;
		}
#endif

		// clamp the MTU within reasonable bounds
		if (mtu < TORRENT_INET_MIN_MTU) mtu = TORRENT_INET_MIN_MTU;
		else if (mtu > TORRENT_INET_MAX_MTU) mtu = TORRENT_INET_MAX_MTU;

		link_mtu = mtu;

		mtu -= TORRENT_UDP_HEADER;

		if (m_sock.get_proxy_settings().type == settings_pack::socks5
			|| m_sock.get_proxy_settings().type == settings_pack::socks5_pw)
		{
			// this is for the IP layer
			address proxy_addr = m_sock.proxy_addr().address();
			if (proxy_addr.is_v4()) mtu -= TORRENT_IPV4_HEADER;
			else mtu -= TORRENT_IPV6_HEADER;

			// this is for the SOCKS layer
			mtu -= TORRENT_SOCKS5_HEADER;

			// the address field in the SOCKS header
			if (addr.is_v4()) mtu -= 4;
			else mtu -= 16;
		}
		else
		{
			if (addr.is_v4()) mtu -= TORRENT_IPV4_HEADER;
			else mtu -= TORRENT_IPV6_HEADER;
		}

		utp_mtu = (std::min)(mtu, restrict_mtu());
	}
开发者ID:Jackarain,项目名称:libtorrent,代码行数:49,代码来源:utp_socket_manager.cpp

示例3: 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);
	}
开发者ID:Sukumi,项目名称:python-libtorrent,代码行数:15,代码来源:ip_filter.cpp

示例4: 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());
	}
开发者ID:Sukumi,项目名称:python-libtorrent,代码行数:7,代码来源:ip_filter.cpp

示例5: open_multicast_socket

    void broadcast_socket::open_multicast_socket(
        io_service& ios, address const& addr, bool loopback, error_code& ec)
    {
        using namespace asio::ip::multicast;

        boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
        s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec);
        if (ec) return;
        s->set_option(datagram_socket::reuse_address(true), ec);
        if (ec) return;
        s->bind(udp::endpoint(addr, m_multicast_endpoint.port()), ec);
        if (ec) return;
        s->set_option(join_group(m_multicast_endpoint.address()), ec);
        if (ec) return;
        s->set_option(hops(255), ec);
        if (ec) return;
        s->set_option(enable_loopback(loopback), ec);
        if (ec) return;
        m_sockets.push_back(socket_entry(s));
        socket_entry& se = m_sockets.back();
#if defined LIBED2K_ASIO_DEBUGGING
        add_outstanding_async("broadcast_socket::on_receive");
#endif
        s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer)),
                              se.remote, boost::bind(&broadcast_socket::on_receive, this, &se, _1, _2));
        ++m_outstanding_operations;
    }
开发者ID:ST3ALth,项目名称:libed2k,代码行数:27,代码来源:broadcast_socket.cpp

示例6: address_cast

inline T address_cast(const address& addr,
                      typename enable_if<is_same<T, address_v4>::value>::type* = 0)
{
    if (!addr.is_v4())
        throw bad_address_cast();
    return get_v4_helper(addr);
}
开发者ID:ChineseDr,项目名称:mongo,代码行数:7,代码来源:address.hpp

示例7: open_unicast_socket

    void broadcast_socket::open_unicast_socket(
        io_service& ios, address const& addr, address_v4 const& mask)
    {
        using namespace asio::ip::multicast;
        error_code ec;
        boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
        s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec);
        if (ec) return;
        s->bind(udp::endpoint(addr, 0), ec);
        if (ec) return;

        m_unicast_sockets.push_back(socket_entry(s, mask));
        socket_entry& se = m_unicast_sockets.back();

        // allow sending broadcast messages
        asio::socket_base::broadcast option(true);
        s->set_option(option, ec);
        if (!ec) se.broadcast = true;

#if defined LIBED2K_ASIO_DEBUGGING
        add_outstanding_async("broadcast_socket::on_receive");
#endif
        s->async_receive_from(
            asio::buffer(se.buffer, sizeof(se.buffer)), se.remote, 
            boost::bind(&broadcast_socket::on_receive, this, &se, _1, _2));
        ++m_outstanding_operations;
    }
开发者ID:ST3ALth,项目名称:libed2k,代码行数:27,代码来源:broadcast_socket.cpp

示例8: 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());
	}
开发者ID:huyang819,项目名称:cdn-partner,代码行数:22,代码来源:broadcast_socket.cpp

示例9: in_subnet

	bool in_subnet(address const& addr, ip_interface const& iface)
	{
		if (addr.is_v4() != iface.interface_address.is_v4()) return false;
		// since netmasks seems unreliable for IPv6 interfaces
		// (MacOS X returns AF_INET addresses as bitmasks) assume
		// that any IPv6 address belongs to the subnet of any
		// interface with an IPv6 address
		if (addr.is_v6()) return true;

		return (addr.to_v4().to_ulong() & iface.netmask.to_v4().to_ulong())
			== (iface.interface_address.to_v4().to_ulong() & iface.netmask.to_v4().to_ulong());
	}
开发者ID:Krinkelss,项目名称:libtorrent,代码行数:12,代码来源:enum_net.cpp

示例10: 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
    }
开发者ID:ST3ALth,项目名称:libed2k,代码行数:25,代码来源:broadcast_socket.cpp

示例11: 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);
			}
		}
开发者ID:huyang819,项目名称:cdn-partner,代码行数:13,代码来源:socket.hpp

示例12: open_unicast_socket

	void broadcast_socket::open_unicast_socket(io_service& ios, address const& addr)
	{
		using namespace asio::ip::multicast;
		error_code ec;
		boost::shared_ptr<datagram_socket> s(new datagram_socket(ios));
		s->open(addr.is_v4() ? udp::v4() : udp::v6(), ec);
		if (ec) return;
		s->bind(udp::endpoint(addr, 0), ec);
		if (ec) return;
		m_unicast_sockets.push_back(socket_entry(s));
		socket_entry& se = m_unicast_sockets.back();
		s->async_receive_from(asio::buffer(se.buffer, sizeof(se.buffer))
			, se.remote, bind(&broadcast_socket::on_receive, this, &se, _1, _2));
	}
开发者ID:huyang819,项目名称:cdn-partner,代码行数:14,代码来源:broadcast_socket.cpp

示例13: 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);
}
开发者ID:opendaylight,项目名称:opflex,代码行数:14,代码来源:Network.cpp

示例14: 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
		}
开发者ID:Chocobo1,项目名称:libtorrent,代码行数:16,代码来源:socket_io.hpp

示例15: 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
		}
开发者ID:Krinkelss,项目名称:libtorrent,代码行数:17,代码来源:socket.hpp


注:本文中的address::is_v4方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。