DNS IPV6--inet_ntop, Inet_pton

Source: Internet
Author: User

I was strange, in the Win32 project to import the # include <WS2tcpip.h> after the use of the Inet_ntop () function without pressure, but in the DLL project error: Intellisense:identifier "inet_ Ntop "is undefined, really do not understand, have a friend can tell me ah. It's urgent to use it, only with your own function.


Inet_ntop (): Converts an IPV4 or IPV6 Internet network address to a string in Internet standard format.

const char *inet_ntop (int af, const void *SRC, char *dst, socklen_t cnt) {    if (af = = af_inet)    {        struct sockaddr _in in;        memset (&in, 0, sizeof (in));        in.sin_family = af_inet;        memcpy (&in.sin_addr, SRC, sizeof (struct in_addr));        Getnameinfo (struct sockaddr *) &in, sizeof (struct            sockaddr_in), DST, CNT, NULL, 0, ni_numerichost);        return DST;    }    else if (AF = = Af_inet6)    {        struct sockaddr_in6 in;        memset (&in, 0, sizeof (in));        in.sin6_family = Af_inet6;        memcpy (&in.sin6_addr, SRC, sizeof (struct IN_ADDR6));        Getnameinfo (struct sockaddr *) &in, sizeof (struct            sockaddr_in6), DST, CNT, NULL, 0, ni_numerichost);        return DST;    }    return NULL;}


Inet_pton (): Converts an IPV4 or IPv6 Internet Network address on its standard text presentation form into its numeric Bina Ry form.

int Inet_pton (int af, const char *src, void *dst) {    struct addrinfo hints, *res, *ressave;    memset (&hints, 0, sizeof (struct addrinfo));    hints.ai_family = AF;    if (getaddrinfo (SRC, NULL, &hints, &res)! = 0)    {//commented out because Dolog and Log_err is not defined.../ /        Dolog (Log_err, "couldn ' t resolve host%s\n", SRC);        return-1;    }    Ressave = res;    while (res)    {        memcpy (DST, res->ai_addr, Res->ai_addrlen);        res = res->ai_next;    }    Freeaddrinfo (ressave);    return 0;}

Not to be continued!

DNS IPV6--inet_ntop, Inet_pton

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.