First, function prototype #include <netdb.h> struct hostent *gethostbyname (const char *name); role: can be used to resolve the domain name structure hostent prototype is as follows: struct hostent {char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } Example: #include <stdio.h>#include <stdlib.h>#include <sys/socket.h> #include <netinet/in.h>#include <netdb.h>int main(int argc, char **argv){if (argc != 2) {fprintf(stderr, "Usage: %s hostname\\ n",argv[1]);exit(1); }struct hostent *answer;int i;char ipstr[16];answer = gethostbyname(argv[1]);if (answer == NULL) {herror(" ;gethostbyname"); //The error handling function comes with gethostbyname exit(1);}for (i = 0; (answer->h_addr_list)[i] != NULL; i++) {inet_ntop(AF_INET, (answer ->h_addr_list)[i], ipstr, 16);printf("%s\ ", ipstr);printf("officail name : %s\ ", answer->h_name);}exit( 0);} Compile execution effect Root@ubuntu:/media/2-G/teacher code/20100427/inet_v4/stream# ./myhost www.hpu.edu.cn202.102.253.254officail name : www.hpu.edu.cn 2. Function prototype int getaddrinfo( Const char *node, const char *service, const struct addrinfo *hints,struct addrinfo **res); This function stores data in a linked list. Char *node is generally the domain name const char *service //service, can be NULLconst struct addrinfo *hints //pointing to the socket address structure returned by res struct addrinfo **res //pointing to the returned result example: #include < Stdio.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <string.h>int main (int argc, char **argv){if (argc != 2) {fprintf(stderr, "Usage: %s hostname\ ",argv[1]);exit(1); }struct addrinfo *answer, Hint, *curr;char ipstr[16]; bzero(&hint, sizeof(hint));hint.ai_family = AF_INET;hint.ai_socktype = SOCK_STREAM;int ret = getaddrinfo(argv[1], NULL, &hint , &answer);if (ret != 0) {fprintf(stderr,"getaddrinfo: &s\ ",gai_strerror(ret));exit(1);}for (curr = answer; curr != NULL; curr = curr->ai_next) {inet_ntop(AF_INET, &((( struct sockaddr_in *)(curr->ai_addr))->sin_addr), ipstr, 16);printf("%s\\ n", ipstr);}freeaddrinfo(answer);exit(0);}
zh-CN"],null,[0.9596082],zh-CN"]]]
Basic Concepts Virtualization allows multiple virtual machines with different operating systems to
There is no doubt that Red Hat is indeed the choice of many companies considering Linux, but in rece
GRUB is the default bootloader for most Linux systems. You can choose to enter different operating s
First, download the magent download address: http://pan.baidu.com/s/1eRygtEUmkdir -p /usr/local/mag
Implementing Nagios Service on Centos
Storage medium of memory in STM32 three boot modes
How to use static library and shared library on Linux platform
Overview of the location of the Linux kernel in the entire operating system
linux compile Analysis of Common Errors
Linux log server build (rsyslog+loganalyzer)
Retrieve the Linux superuser root password
The Linux CPU number judgment command
How to install directadmin on VPS
Nginx configuration reverse proxy
The first universal Windows 10 app "Photos" was updated
The real reason why QQ2009 can't be used under Windows 7
Win7 lost MSVCP100.dll caused the program can not start the solution
In-depth introduction to the function of the Windows7 system folder
Win xp SP2 system secret weapon big exposure
There is no sound solution for playing cf games in Win7 system.
Win7 system comes with a system restore, than GHOST cattle!
EFI installed Win 8 system method: CD usb hard disk u disk
Naruto OL Lei before the mid-term lineup selection skills analysis Raiders Daquan