Poco Library Chinese Programming Reference Guide (4) poco::net::ipaddress

Source: Internet
Author: User

Poco Library Chinese Programming Reference Guide (4) poco::net::ipaddress
    • Liu Poechant
    • Blog: blog.csdn.net/poechant
    • E-Mail: zhongchao.ustc#gmail.com (#, @)
    • Date: April 14th, 2012
1 poco::net::ipaddress

Address maximum length, IPv4 is the length of in_addr, IPV6 is the length of in6_addr

enum{    MAX_ADDRESS_LENGTH = #if defined(POCO_HAVE_IPv6)        sizeof(struct in6_addr)#else        sizeof(struct in_addr)#endif        /// Maximum length in bytes of a socket address.};
1.1 IPv4 or IPv6?

POCO is represented by an enumeration class:

enum Family    /// Possible address families for IP addresses.{    IPv4,    IPv6};
1.2 Constructors

Returns a full 0 IP address:

IPAddress();

Copy constructor:

IPAddress(const IPAddress& addr);

Create a full 0 IP address based on the IP type (IPv4 or IPV6):

explicit IPAddress(Family family);

Create an IP address with the IPV4 address or IPV6 address of the string type, where IPv4 is in decimal notation, and IPv6 is in hexadecimal:

explicit IPAddress(const std::string& addr);

Creates an IP address with the IP address of the string type and the specified type (IPV4 or IPV6), where the IPv4 is in decimal notation and IPv6 is in hexadecimal:

IPAddress(const std::string& addr, Family family);

Create a IPAddress with the native IP address in_addr or IN6_ADDR data structure and the given string length:

IPAddress(const void* addr, poco_socklen_t length);

Create a IPAddress with the native IP address in_addr or IN6_ADDR data structure and the given string length, where the scope parameter is used for Ipv6,ipv4 to ignore this parameter:

IPAddress(const void* addr, poco_socklen_t length, Poco::UInt32 scope);
1.3 Overloaded operators

Assignment operators:

IPAddress& operator = (const IPAddress& addr);

Comparison operators

bool operator == (const IPAddress& addr) const;bool operator != (const IPAddress& addr) const;bool operator <  (const IPAddress& addr) const;bool operator <= (const IPAddress& addr) const;bool operator >  (const IPAddress& addr) const;bool operator >= (const IPAddress& addr) const;
1.4 Common operations

Swap

void swap(IPAddress& address);

Get address Type:

Family family() const;

IPV6 Special function, returns the scope identifier, and returns 0 if it is IPv4:

Poco::UInt32 scope() const;

Tostring,ipv4 "D.d.d.d" is displayed, IPV6

std::string toString() const;poco_socklen_t length() const;const void* addr() const;int af() const;void mask(const IPAddress& mask);void mask(const IPAddress& mask, const IPAddress& set);static IPAddress parse(const std::string& addr);static bool tryParse(const std::string& addr, IPAddress& result);static IPAddress wildcard(Family family = IPv4);static IPAddress broadcast();
1.5 is function 1.5.1 is uninitialized state

is an uninitialized full 0 state (wildcard):

bool isWildcard() const;
Whether the 1.5.2 is broadcast/multicast/unicast

is the broadcast address (all 0), the difference from wildcard is that wildcard is uninitialized. Only IPV4 has a broadcast address, and IPV6 returns false.

bool isBroadcast() const;

Whether it is a loopback address:

    • For IPV4 is127.0.0.1
    • For IPV6 is::1

Function Prototypes:

bool isLoopback() const;

Whether it is multicast:

    • For IPv4 is 224.0.0.0 to 239.255.255.255 range;
    • For IPV6 is FFxx:x:x:x:x:x:x:x the range:

Function Prototypes:

bool isMulticast() const;

Whether it is unicast:

bool isUnicast() const;
1.5.2 Other functions
bool isLinkLocal() const;bool isSiteLocal() const;bool isIPv4Compatible() const;bool isIPv4Mapped() const;bool isWellKnownMC() const;bool isNodeLocalMC() const;bool isLinkLocalMC() const;bool isSiteLocalMC() const;bool isOrgLocalMC() const;bool isGlobalMC() const;
1.5 protected function
protected:    void init(IPAddressImpl* pImpl);

-

From:blog.csdn.net/poechant

Poco Library Chinese Programming Reference Guide (4) poco::net::ipaddress

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.