| 
 #include <winsock.h>     #include <Windows.h>     #include <stdio.h>      #pragma comment (lib, "ws2_32.lib")      int main(void) {         WSADATA wsaData = {0,};         struct in_addr addr = {0,};         struct hostent *res;         int i = 0;          WSAStartup(MAKEWORD(2, 2), &wsaData);          res = gethostbyname("IPv6test.ntes53.netease.com.");         while (res->h_addr_list[i] != 0) {             addr.s_addr = *(u_long *) res->h_addr_list[i++];             printf("IP Address: %sn", inet_ntoa(addr));         }          WSACleanup(); } 
 getaddrinfo #include <stdio.h>     #include <string.h>     #include <stdlib.h>     #include <netdb.h>     #include <sys/types.h>     #include <sys/socket.h>     #include <arpa/inet.h>      int lookup_host () {       struct addrinfo hints, *res;       int errcode;       char addrstr[100];       void *ptr;        memset (&hints, 0, sizeof (hints));       hints.ai_family = AF_INET;        errcode = getaddrinfo ("IPv6test.ntes53.netease.com", NULL, &hints, &res);       if (errcode != 0)         {           perror ("getaddrinfo");           return -1;         }       while (res)         {           inet_ntop (res->ai_family, res->ai_addr->sa_data, addrstr, 100);           switch (res->ai_family)             {             case AF_INET:               ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;               break;             case AF_INET6:               ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;               break;             }           inet_ntop (res->ai_family, ptr, addrstr, 100);           printf ("IPv%d address: %s (%s)n", res->ai_family == PF_INET6 ? 6 : 4,                   addrstr, res->ai_canonname);           res = res->ai_next;         }       return 0;     }     int main (void) {         lookup_host();     } 
 windows(编辑:南平站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |