Presentation is loading. Please wait.

Presentation is loading. Please wait.

인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr TCP/IP Socket Programming… 제 8장 도메인 이름과 인터네 주소 인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr.

Similar presentations


Presentation on theme: "인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr TCP/IP Socket Programming… 제 8장 도메인 이름과 인터네 주소 인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr."— Presentation transcript:

1 인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr
TCP/IP Socket Programming… 제 8장 도메인 이름과 인터네 주소 인공지능실험실 박사 1학기 장성만

2 목차 DNS(Domain Name System) IP 주소와 도메인 이름 사이의 변환 윈도우 기반으로 구현하기

3 DNS(Domain Name System)
도메인 이름이란?

4 DNS(Domain Name System)
계층 구조를 가진 분산 데이터 베이스 서버

5 IP 주소와 도메인 이름 사이의 변환 Gethostbyname() : 도메인 명을 네트워크에서 통용되는 32비트 2진수로 바꾸어 준다. Gethostbyaddr() : 네트워크에서 통용되는 32비트 2진수를 도메인 명으로 바꾸어 준다. Inet_ntoa() : 32비트 2진수로 된 주소를 “.”이 있는 십진수로 변환할 때 사용 Inet_addr() : “.”이 있는 십진수를 32비트 2진수로 변환할 때 사용 gethostbyname() gethostbyaddr() inet_ntoa() inet_addr()

6 성공 시 hostent 구조체의 포인터, 실패시 NULL포인터 리턴
IP 주소와 도메인 이름 사이의 변환 도메인 이름을 사용해서 IP 주소 얻어내기 Getbyhostname() 인자로 호스트명을 주면 그 호스트에 대한 정보를 구할 수 있다 그 중의 하나가 32비트로 된 IP 주소임. #include <netdb.h> Struct hostent* gethostbyname(const char * name); 성공 시 hostent 구조체의 포인터, 실패시 NULL포인터 리턴 struct hostent { char *h_name; /* Official name of host. */ char **h_aliases; /* Alias list. */ int h_addrtype; /* Host address type. */ int h_length; /* Length of address. */ char **h_addr_list; /* List of addresses from name server. */ };

7 IP 주소와 도메인 이름 사이의 변환 도메인 이름을 사용해서 IP 주소 얻어내기 if (!host)
host = gethostbyname(argv[1]); if (!host) error_handling("gethostbyname() error"); printf("Officially name : %s \n\n", host->h_name); puts("Aliases "); for(i=0;host->h_aliases[1];i++){ puts(host->h_aliases[i]); } printf("Address Type : %s \n", host->h_addrtype==AF_INET? "AF_INET":"AF_INET6"); puts("IP Address "); for(i=0; host->h_addr_list[i];i++){ puts(inet_ntoa( *(struct in_addr*)host->h_addr_list[i]));

8 성공 시 hostent 구조체의 포인터, 실패시 NULL포인터 리턴
IP 주소와 도메인 이름 사이의 변환 IP 주소를 이용해서 도메인 이름 알아내기 #include <netdb.h> Struct hostent* gethostbyaddr(const char * addr, int len, int type); 성공 시 hostent 구조체의 포인터, 실패시 NULL포인터 리턴

9 IP 주소와 도메인 이름 사이의 변환 IP 주소를 이용해서 도메인 이름 알아내기
host=gethostbyaddr((char*)&addr.sin_addr, 4, AF_INET); if(!host) error_handling("gethostbyaddr() error"); printf("Officially name : %s \n\n", host->h_name); puts("Aliases "); for(i=0;host->h_aliases[i];i++){ puts(host->h_aliases[i]); } printf("Address Type : %s \n", host->h_addrtype==AF_INET ? "AF_INET":"AF_INET6"); puts("IP Address "); for(i=0; host->h_addr_list[i];i++){ puts(inet_ntoa(*(struct in_addr*)host->h_addr_list[i])); return 0;

10 IP 주소와 도메인 이름 사이의 변환 윈도우 기반으로 구현하기 #include <winsock2.h>
Struct hostent FAR *gethostbyname( const char FAR *name ); 성공 시 0, 실패시 SOCKET_ERROR 리턴 Struct hostent { char FAR * h_name; char FAR * FAR h_aliases; short h_addrtype; short h_length; char FAR * FAR h_addr_list; #include <winsock2.h> Struct hostent FAR *gethostbyaddr( const char FAR *addr, int len, int type ); 성공 시 0, 실패시 SOCKET_ERROR 리턴

11 참고문헌 “UNIX Network Programming”, W.Richard Stevens
“TCP/IP 소켓 프로그래밍”, 윤성우 저

12 Q & A


Download ppt "인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr TCP/IP Socket Programming… 제 8장 도메인 이름과 인터네 주소 인공지능실험실 박사 1학기 장성만 smjang@ai.hannam.ac.kr."

Similar presentations


Ads by Google