DNS IPV6化——inet_ntop、inet_pton

來源:互聯網
上載者:User

標籤:網路編程   ipv4   ipv6   windows   

      我就奇了怪了,在Win32工程裡匯入#include <WS2tcpip.h>後Inet_ntop()函數的使用毫無壓力,但在DLL工程裡卻報錯:     IntelliSense: identifier "inet_ntop" is undefined,實在是搞不懂,有懂的朋友可以告訴我哈。現在急著用,只有用自己的函數實現。


Inet_ntop():converts an IPv4 or IPv6 Internet network address into 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 in its standard text presentation form into its numeric binary 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 are 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;}

未完待續!

DNS IPV6化——inet_ntop、inet_pton

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.