- 论坛徽章:
- 0
|
socket 编程中,通过gethostbyname() 或者
gethostbyaddr 取得主机的 hostent 解构的信息,
现在从中提取出地址信息:
- struct host * host;
- struct sockaddr_in address;
- ....
- ...
- ...
- memcpy (&address.sin_addr, host->h_addr_list[0], sizeof(address.sin_addr));
- 或者:
- address.sin_addr=*((struct in_addr *)host->h_addr);
复制代码
编译的时候出现这样的错误:
error: dereferencing pointer to incomplete type ( 提领指向不完全类型的指针)
请问这个提示是什么意思,代码应该怎么写才能把地址拿出来。
还有,当我进行强制地址类型转换的时候提示:
warning: assignment from incompatible pointer type
代码是这样的:
- struct in_addr inaddr;
- .....
- .....
- .....
- if (inet_aton(argv[1], &inaddr))
- host = gethostbyaddr((char *) &inaddr, sizeof (inaddr), AF_INET);
复制代码
这样会不会不安全? |
|