Skip to content

Instantly share code, notes, and snippets.

@daramkun
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save daramkun/035c22bdff560e39b19b to your computer and use it in GitHub Desktop.

Select an option

Save daramkun/035c22bdff560e39b19b to your computer and use it in GitHub Desktop.
gethostbyname example in Winsock
#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