#include
int main (int argc, char * argv []) {struct hostent * qnew_hp; struct in_addr qnew_in; struct sockaddr_in qnew_localaddr; if (argc <2) return; if (! (qnew_hp = gethostbyname (argv [1]))) { FPrintf (stderr, "can't resolve host./n); exit (1);} Memcpy (& QNEW_LOCALADDR.SIN_ADDR.S_ADDR, QNEW_HP-> h_addr, 4); QNEW_IN.S_ADDR = QNEW_LOCALADDR.SIN_ADDR.S_ADDR; Printf "DOMAIN NAME:% S / N", qneew_hp-> h_name); Printf ("IP AddRes:% S / N", INET_NTOA (QNEW_IN));}
/ * Compilation method: cc -o test Test.c How to use: ./test www.163.com
Struct hostent {char * h_name; host name char ** h_aliases; point to the other alias INT H_ADDRTYPE; address status, usually AF_INET INT H_LENGTH; address length char ** h_addr_list; acquire all of the host from the domain name server} * /