struct hostent结构体
来源:互联网 发布:尔雅网络选修课 编辑:程序博客网 时间:2024/05/22 06:36
struct hostent结构体
这个数据结构是这样的:
struct hostent {
const char *h_name; // official name of host
char **h_aliases; // alias list
short h_addrtype; // host address type
short 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 compatiblity
};
typedef uint32_t in_addr_t;
struct in_addr
{
in_addr_t s_addr;
};
这里是这个数据结构的详细资料:
struct hostent:
h_name – 地址的正式名称。
h_aliases – 空字节-地址的预备名称的指针。
h_addrtype –地址类型; 通常是AF_INET。
h_length – 地址的比特长度。
h_addr_list – 零字节-主机网络地址指针。网络字节顺序。
h_addr - h_addr_list中的第一地址。
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 数据。
http://www.cnblogs.com/balaamwe/archive/2012/01/06/2313848.html
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体
- struct hostent结构体使用
- struct hostent 结构体与gethostbyname(),gethostbyaddr
- Linux网络编程--struct hostent结构体
- inux网络编程--struct hostent结构体
- Linux网络编程--struct hostent结构体
- 域名和网络地址结构体---struct hostent
- Linux网络编程--struct hostent结构体
- Linux下网络相关结构体 struct hostent
- hostent结构体
- 【转】hostent结构体
- 基础总结篇之一:Activity生命周期
- 装了anaconda,和opencv,caffe,但import cv2报错
- 单例模式
- Java 理论与实践: 正确使用 Volatile 变量
- httpClient 带验证码登录实现
- struct hostent结构体
- 【JAVA基础小问题】Math.round(11.5)等於多少? Math.round(-11.5)等於多少?
- apache虚拟主机配置及常用安全配置
- Velocity FieldTool
- JSON.parse()和JSON.stringify()
- Java基础知识学习总结(一)---深入理解Java的接口和抽象类
- JVM垃圾收集器
- jvm 笔记(1) jvm 总体概述
- linux ---- epoll