/** * @brief 无需root权限发送icmp包,从boost/asio/ip/icmp.hpp修改而来 * @author yikenan */ # pragma once #include #include #include #include #include #include #include #include namespace boost { namespace asio { namespace ip { /** * @brief 无需root权限发送icmp包,从boost/asio/ip/icmp.hpp修改而来 */ class icmp_nonroot { public: /// The type of a ICMP endpoint. typedef basic_endpoint endpoint; /// Construct to represent the IPv4 ICMP protocol. static icmp_nonroot v4() { return icmp_nonroot( BOOST_ASIO_OS_DEF( IPPROTO_ICMP ), BOOST_ASIO_OS_DEF( AF_INET ) ); } /// Construct to represent the IPv6 ICMP protocol. static icmp_nonroot v6() { return icmp_nonroot( BOOST_ASIO_OS_DEF( IPPROTO_ICMPV6 ), BOOST_ASIO_OS_DEF( AF_INET6 ) ); } /// Obtain an identifier for the type of the protocol. int type() const { //< yikenan #ifndef OS_WINDOWS return BOOST_ASIO_OS_DEF( SOCK_DGRAM ); #else return BOOST_ASIO_OS_DEF(SOCK_RAW); #endif } /// Obtain an identifier for the protocol. int protocol() const { return protocol_; } /// Obtain an identifier for the protocol family. int family() const { return family_; } /// The ICMP socket type. //< yikenan //typedef basic_raw_socket socket; typedef basic_datagram_socket socket; /// The ICMP resolver type. typedef basic_resolver resolver; /// Compare two protocols for equality. friend bool operator==( const icmp_nonroot &p1, const icmp_nonroot &p2 ) { return p1.protocol_ == p2.protocol_ && p1.family_ == p2.family_; } /// Compare two protocols for inequality. friend bool operator!=( const icmp_nonroot &p1, const icmp_nonroot &p2 ) { return p1.protocol_ != p2.protocol_ || p1.family_ != p2.family_; } private: // Construct with a specific family. explicit icmp_nonroot( int protocol_id, int protocol_family ) : protocol_( protocol_id ), family_( protocol_family ) { } int protocol_; int family_; }; } // namespace ip } // namespace asio } // namespace boost #include