LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1282|回复: 3

hostent结构

[复制链接]
发表于 2006-12-29 09:36:29 | 显示全部楼层 |阅读模式
hostent的结构应该是这样的
struct hostent {
  char  *h_name;
  char  **h_aliases;
  int   h_addrtype;
  int   h_length;
  char  **h_addr_list;
};
但为什么有的程序上写成
struct hostent *hp;
memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
也可以运行啊?hostent中有h_addr和h_length这两个元素吗?
发表于 2006-12-29 17:33:34 | 显示全部楼层
netdb.h:
[PHP]
/* 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.  */
#define h_addr  h_addr_list[0]  /* Address, for backward compatibility.  */
};
[/PHP]
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-30 15:05:28 | 显示全部楼层
呵呵,是我没看仔细,谢谢了。
回复 支持 反对

使用道具 举报

发表于 2006-12-30 17:23:27 | 显示全部楼层
可否解释一下这个指向指针的指针?
char **h_aliases
是否它指向一个指针,而那个指针是指向字符型的数据?最好能举个例子出来。
例子跟上面那个 /* Alias list.  */相关最好,谢谢

鄙人没有用过指向指针的指针,既然看到了,懒得翻书(莫砍我,问了以后再看),遂问于次。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表