C + + Poco library Chinese Programming Reference Guide (4) poco::net::ipaddress

Source: Internet
Author: User
Tags bool range reference tostring

1 poco::net::ipaddress

Address maximum length, IPv4 is in_addr length, IPv6 is in6_addr length

Enum   
{   
    max_address_length =    
#if defined (Poco_have_ipv6)
        sizeof (struct in6_addr)   
#else
        sizeof (struct in_addr)   
#endif   
        ///Maximum length in bytes of the 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);

Creates an IP address with a IPV4 address or IPv6 address of type string, where IPv4 is represented in decimal notation, and IPv6 is in hexadecimal notation:

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

Creates an IP address with a string-type IP address and a specified type (IPV4 or IPv6), where IPv4 is represented in decimal notation, and IPv6 is in hexadecimal notation:

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

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

IPAddress (const void* addr, poco_socklen_t length);

Creates 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, and IPV4 ignores this parameter:

IPAddress (const void* addr, poco_socklen_t length, poco::uint32 scope);

1.3 Overloaded operators

Assignment operator:

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 the Address type:

Family Family () const;

IPv6 a private function that returns the scope identifier and, if it is IPv4, returns 0:

Poco::uint32 scope () const;

TOSTRING,IPV4 displays "D.d.d.d" and 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

Whether the 1.5.1 state is uninitialized

is an uninitialized full 0 state (wildcard):

BOOL Iswildcard () const;

1.5.2 is broadcast/multicast/unicast

Whether it is a broadcast address (all 0), the difference from wildcard is that the wildcard is uninitialized. IPV6 returns false only if the IPV4 has a broadcast address.

BOOL Isbroadcast () const;

Whether it is a loopback address:

For IPV4 is 127.0.0.1

For IPV6 are:: 1

Function Prototypes:

BOOL Isloopback () const;

is multicast:

For IPv4 is 224.0.0.0 to 239.255.255.255 range;

For IPV6 is the range of ffxx:x:x:x:x:x:x:x:

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);

CSDN blog from Liuda: blog.csdn.net/poechant

View a full set of articles: Http://www.bianceng.cn/Programming/cplus/201301/35022.htm

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.