大家好!
本人是初学者,学习版本是Ubuntu 12.04 LTS,最近练习网络编程时发现书中一个很奇怪的问题,无法解释为什么要这样。
代码不长的,其中问题的地方我已经注明了,代码在附件中,望大家下载下来看看。
我是按照书上到例子来的,还望各位朋友解释下,谢谢了!
对该程序中的用法感到很奇怪,请大家帮忙解释下!
-
- 帖子: 27
- 注册时间: 2013-01-23 21:46
- 系统: windows xp
- weidongxu
- 帖子: 13
- 注册时间: 2013-02-02 10:48
Re: 对该程序中的用法感到很奇怪,请大家帮忙解释下!
看文档的话 h_addr 是宏,就是 h_addr_list[0]。为后向兼容定义的(估计早的时候没有addr_list,只有一个addr)。
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Syntax
C++
typedef struct hostent {
char FAR *h_name;
char FAR FAR **h_aliases;
short h_addrtype;
short h_length;
char FAR FAR **h_addr_list;
} HOSTENT, *PHOSTENT, FAR *LPHOSTENT;
Members
h_name
The official name of the host (PC). If using the DNS or similar resolution system, it is the Fully Qualified Domain Name (FQDN) that caused the server to return a reply. If using a local hosts file, it is the first entry after the IPv4 address.
h_aliases
A NULL-terminated array of alternate names.
h_addrtype
The type of address being returned.
h_length
The length, in bytes, of each address.
h_addr_list
A NULL-terminated list of addresses for the host. Addresses are returned in network byte order. The macro h_addr is defined to be h_addr_list[0] for compatibility with older software.
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Syntax
C++
typedef struct hostent {
char FAR *h_name;
char FAR FAR **h_aliases;
short h_addrtype;
short h_length;
char FAR FAR **h_addr_list;
} HOSTENT, *PHOSTENT, FAR *LPHOSTENT;
Members
h_name
The official name of the host (PC). If using the DNS or similar resolution system, it is the Fully Qualified Domain Name (FQDN) that caused the server to return a reply. If using a local hosts file, it is the first entry after the IPv4 address.
h_aliases
A NULL-terminated array of alternate names.
h_addrtype
The type of address being returned.
h_length
The length, in bytes, of each address.
h_addr_list
A NULL-terminated list of addresses for the host. Addresses are returned in network byte order. The macro h_addr is defined to be h_addr_list[0] for compatibility with older software.
-
- 帖子: 27
- 注册时间: 2013-01-23 21:46
- 系统: windows xp
Re: 对该程序中的用法感到很奇怪,请大家帮忙解释下!
谢谢,明白了……
weidongxu 写了:看文档的话 h_addr 是宏,就是 h_addr_list[0]。为后向兼容定义的(估计早的时候没有addr_list,只有一个addr)。
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Syntax
C++
typedef struct hostent {
char FAR *h_name;
char FAR FAR **h_aliases;
short h_addrtype;
short h_length;
char FAR FAR **h_addr_list;
} HOSTENT, *PHOSTENT, FAR *LPHOSTENT;
Members
h_name
The official name of the host (PC). If using the DNS or similar resolution system, it is the Fully Qualified Domain Name (FQDN) that caused the server to return a reply. If using a local hosts file, it is the first entry after the IPv4 address.
h_aliases
A NULL-terminated array of alternate names.
h_addrtype
The type of address being returned.
h_length
The length, in bytes, of each address.
h_addr_list
A NULL-terminated list of addresses for the host. Addresses are returned in network byte order. The macro h_addr is defined to be h_addr_list[0] for compatibility with older software.