Last active
August 29, 2015 14:01
-
-
Save daramkun/035c22bdff560e39b19b to your computer and use it in GitHub Desktop.
gethostbyname example in Winsock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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("www.naver.com"); | |
| while (res->h_addr_list[i] != 0) | |
| { | |
| addr.s_addr = *(u_long *)res->h_addr_list[i++]; | |
| printf("IP Address: %s\n", inet_ntoa(addr)); | |
| } | |
| WSACleanup(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment