這是編譯選項造成的。
例如,如下的編譯選項就可能出現問題:
> gcc -pedantic -Os -c client.c -o client.o -std=c99
在netdb.h文件中,可以找到hostent的定義:
/* Description of data base entry for a single host. */
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. */
#if defined __USE_MISC || defined __USE_GNU
# define h_addr h_addr_list[0] /* Address, for backward compatibility.*/
#endif
};
解決辦法,加上編譯選項即可:
> gcc -pedantic -Os -c client.c -o client.o -std=c99 -D_GNU_SOURCE