12
我遇到下面的代碼快照:struct hostent是否有字段「h_addr」?
struct hostent *hp;
hp = my_gethostbyname(localhost);
if (hp == NULL) {
ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "my_gethostbyname()");
return -1;
}
strcpy(localhost, hp->h_name);
memcpy(&addr, hp->h_addr, hp->h_length);
我的最後一條語句比較混亂,結構hostent的聲明是這樣的:
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 */
};
它沒有一場名爲「 h_addr「,但代碼確實可以編譯,誰能告訴我爲什麼?謝謝。
謝謝.....小尷尬.... – wangshuaijie 2012-07-10 02:37:32