Skip to content

Instantly share code, notes, and snippets.

@wicksome
Last active August 29, 2015 14:08
Show Gist options
  • Save wicksome/567af58e62d433abd4bf to your computer and use it in GitHub Desktop.
Save wicksome/567af58e62d433abd4bf to your computer and use it in GitHub Desktop.
네트워크 2014.11.05 수업 준비
#include <WinSock2.h>
#include <stdio.h>
int main(int argc, char **argv) {
WSADATA WSAData;
struct hostent *myent;
// B. 인터넷 주소를 가져오지 못할 경우 에러 처리.
if(argc != 2) {
printf("Usage : %s [ineternet address]\n", argv[0]);
WSACleanup();
return 1;
}
if (WSAStartup (MAKEWORD(2,2), &WSAData) != 0) {
printf("WSAStartup failed\n");
return 1;
}
myent = gethostbyname(argv[1]);
if(myent == NULL) {
printf("Not Found Domain Name.\n");
return;
}
printf("Host Name : %s\n", myent->h_name);
// C. 여러 개의 인터넷 주소가 있을 때, 이를 모두 출력한다.
while(*myent->h_addr_list != NULL) {
printf("%s\n", inet_ntoa(*(struct in_addr *)*myent->h_addr_list));
myent->h_addr_list++;
}
WSACleanup();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment