1. struct Hostent structural body
The official name of the H_name address.
H_aliases A pointer to the prestaged name (alias).
H_addrtype address type; Usually a af_inet.
The bit length of the h_length address.
H_addr_list Host network address pointer. Network byte order.
H_ADDR the first address in the h_addr_list.
2. in_addr Structural Body
#include <arpa/inet.h>typedef struct IN_ADDR { union { struct {UCHAR s_b1,s_b2,s_b3,s_b4;} S_un_b; struct {USHORT s_w1,s_w2;} S_un_w; ULONG s_addr; } S_un; #define S_ADDR S_un. S_ADDR/ * Can is used for most TCP & IP code */ #define S_HOST S_un. S_UN_B.S_B2 //Host on IMP #define S_net S_un. S_UN_B.S_B1 //Network #define S_IMP S_un. S_UN_W.S_W2 //Imp #define S_IMPNO S_un. S_UN_B.S_B4 //Imp # #define S_LH S_un. S_UN_B.S_B3 //Logical host } in_addr, *pin_addr, far *lpin_addr;
3. gethostbyname () function
#include <netdb.h> #include <sys/socket.h>struct hostent *gethostbyname (const char *name);
This function calls into the host name or domain name, such as WWW.GOOGLE.COM,WPC, and so on. The function returns a pointer to the struct hostent struct type, and returns a null if the call fails.
The h_addr_list in the returned struct hostent struct is an array of pointers, and each element in the array can be considered a pointer to the IN_ADDR type. is defined as char** because the hostent structure supports
Multiple address types.
by gethostbyname ("www.baidu.com") the hostent can be printed as follows:
4. Inet_ntoa () function
#include <arpa/inet.h>char *inet_ntoa (struct in_addr);
The function is to convert the address of the network byte order to a band "." The IP address string for the format.
Socket Programming Basics 1--hostent, IN_ADDR, gethostbyname, Inet_ntoa