라이브러리 ws2_32.lib 추가해주고 실행해야한다.

#include <WinSock2.h>
#include <stdio.h>

void ptintMyent(struct hostent *myent);

int main(int argc, char **argv) {
	WSADATA		WSAData;

	if (WSAStartup (MAKEWORD(2,2), &WSAData) != 0) {
		return 1;
	}

	ptintMyent(gethostbyname("web.dongguk.ac.kr"));
	ptintMyent(gethostbyname("www.naver.com"));
	ptintMyent(gethostbyname("www.hanb.co.kr"));

	WSACleanup();
	return 0;

}

void ptintMyent(struct hostent *myent) {
	long int *add;
	SOCKADDR_IN myen;

	if(myent == NULL) {
		return;
	}

	printf("Host name : %s\n", myent->h_name);

	while(*myent->h_addr_list != NULL) {
		add = (long int*)*myent->h_addr_list;
		myen.sin_addr.S_un.S_addr = *add;
		
		printf("%d -> %s\n", add, inet_ntoa(myen.sin_addr));
		myent->h_addr_list++;
	}
	printf("\n");
}


+ Recent posts