hostent结构介绍
来源:互联网 发布:mac按哪个键切换输入法 编辑:程序博客网 时间:2024/05/09 20:21
转自:http://blog.csdn.net/leewenjin/article/details/7394613
struct hostent结构体
这个数据结构是这样的:
struct hostent {
const char *h_name; // 地址的正式名称。
char **h_aliases; // 空字节-地址的预备名称的指针。
short h_addrtype; // 地址类型; 通常是AF_INET。
short h_length; // 地址的比特长度
char **h_addr_list; // 零字节-主机网络地址指针。网络字节顺序。
#define h_addr h_addr_list[0] // h_addr 为 h_addr_list中的第一地址。
};
typedef uint32_t in_addr_t;
struct in_addr
{
in_addr_t s_addr;
};
gethostbyname() 成 功时返回一个指向结构体 hostent 的指针,或者 是个空 (NULL) 指针。
这里是个例子:
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
int main(void) {
struct hostent *h;
h = gethostbyname("www.126.com");
if(h==NULL){
herror("gethostbyname");
exit(1);
}
printf("%s\n",h->h_name);
printf("%d\n",h->h_addr);
struct in_addr *in={h->h_addr};
printf("%s\n",inet_ntoa(*in));
// printf("IP Address : %s\n",inet_ntoa(*((struct in_addr *)h->h_addr)));
return EXIT_SUCCESS;
}
在使用 gethostbyname() 的时候,你不能用perror() 打印错误信息 (因为 errno 没有使用),你应该调用 herror()。
gethostbyname()返回的 struct hostent 数据。
- hostent结构介绍
- hostent结构介绍
- hostent结构体
- 【转】hostent结构体
- hostent 和in_addr结构
- struct hostent结构体
- hostent 结构体
- struct hostent结构体
- hostent结构体
- struct hostent结构体
- hostent结构体
- hostent结构体
- hostent结构体
- struct hostent结构体
- linux hostent结构体
- hostent结构体
- struct hostent结构体
- 使用hostent结构:
- 将石头随即放入矩阵中 找出最小SubMatrix包含所有石头
- java环境变量配置
- java环境变量设置(完美版)
- Matlab 2011集成Visual studio 2010编译器
- spring启动后立即执行指定的函数
- hostent结构介绍
- 2个日期之间有多少天
- adb shell am & busybox
- CSS 获取浏览器尺寸
- ClientScriptManager 类
- 修改数据库服务器名
- UrlRewrite
- MySQL在Linux下的表名如何不区分大小写
- lucene query time join (关联搜索)