/*----------------------------------------------------------------------------------------------- ÆÄÀϸí : host_ent.c ±â ´É : hostent ±¸Á¶Ã¼ ³»¿ë Ãâ·Â ÇÁ·Î±×·¥ ÄÄÆÄÀÏ : cc -o host_ent host_ent.c -lnsl ½ÇÇ࿹ : host_ent telecom.kangwon.ac.kr --------------------------------------------------------------------------------------------- */ #include #include #include #include void main(int argc, char *argv[]) { struct hostent *myhost; struct in_addr myinaddr; /* IP ÁÖ¼Ò¸¦ ÀúÀåÇÒ ±¸Á¶Ã¼ */ int i; if( argc < 2 ) { printf( "»ç¿ë¹ý : %s host_name(µµ¸ÞÀÎ ³×ÀÓ) \n", argv[0] ); exit(1); } /* hostent ±¸Çϱâ */ myhost = gethostbyname( argv[1] ); if (myhost == 0) { printf("error occurs... at 'gethostbyname'. \n\n\n"); exit(1); } /* È£½ºÆ® À̸§ Ãâ·Â */ printf("official host name : \t\t%s\n", myhost->h_name); /* È£½ºÆ® º°¸í Ãâ·Â */ i = 0; while(myhost->h_aliases[i] != NULL) { printf( "aliases name : \t\t%s\n", myhost->h_aliases[i] ); i++; } /* È£½ºÆ® ÁÖ¼Ò Ã¼°è Ãâ·Â */ printf("host address type : \t\t%d\n", myhost->h_addrtype); /* È£½ºÆ® ÁÖ¼Ò ±æÀÌ Ãâ·Â */ printf("length of host address : \t%d\n", myhost->h_length); /* È£½ºÆ® ÁÖ¼Ò¸¦ dotted decimal ÇüÅ·ΠÃâ·Â */ i = 0; while( myhost->h_addr_list[i] != NULL ) { myinaddr.s_addr = *( (u_long *)(myhost->h_addr_list[i]) ) ; printf("address for host : \t\t%s\n", inet_ntoa(myinaddr)) ; i++; } }