gethostbyaddr
函数原型:
#include<netdb.h>
struct hostent * gethostbyaddr(const char *addr, socklen_t len, int family);
函数功能:
返回对应于给定地址的主机信息。
参数说明:
addr:指向网络字节顺序地址的指针。
len: 地址的长度,在AF_INET类型地址中为4。
family: 地址类型,应为AF_INET。
返回值:
如果没有错误发生,返回一个指向hostent结构的指针,否则,返回一个空指针。
实例:
/***
gethostbyaddr.c
***/
#include<stdio.h>
#include<netdb.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<string.h> int main(int argc , char **argv)
{
if (argc < )
{
printf("the argc need more two\n");
return ;
} struct hostent *host;
const char *add = argv[];
char p[];
inet_pton(AF_INET, add, p);
host = gethostbyaddr(p, strlen(p), AF_INET);
printf("hostname : %s\n",host->h_name);
return ;
}
运行结果:

gethostbyaddr的更多相关文章
- UNIX网络编程——名字与地址转换(gethostbyname,gethostbyaddr,getservbyname,getservbyport,getaddrinfo,getnameinfo函数)
名字和数值地址间进行转换的函数:gethostbyname和gethostbyaddr在主机名字与IPv4地址之间进行转换.getservbyname和getservbyport在服务器名字和端口号之 ...
- gethostbyname和gethostbyaddr
一.gethostbyname函数原型 #include <netdb.h> struct hostent *gethostbyname(const char *ghostname); 返 ...
- 学习笔记之gethostbyaddr函数
刚才学了gethostbyname函数,这个gethostbyaddr函数的作用是通过一个IPv4的地址来获取主机信息,并放在hostent结构体中. #include <netdb.h> ...
- Python之Dijango的“坑” hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' cod
错误代码提示: hostname, aliases, ipaddrs = gethostbyaddr(name) UnicodeDecodeError: 'utf-8' codec can't dec ...
- Linux网络编程 gethostbyaddr()
C语言函数 概述: 返回对应于给定地址的主机信息. #include <winsock.h> struct hostent FAR *PASCAL FAR gethostbyaddr(co ...
- linux网络编程——域名转换 gethostbyname与gethostbyaddr
域名转换 #include <netdb.h> struct hostent *gethostbyname(const char *name); 参数: name: 执行主机名的指针 返回 ...
- gethostname gethostbyname gethostbyaddr 获得主机相关信息
网络编程里经常需要获得主机的相关信息,下面围绕相关的函数以及用到的结构来说明. 获得主机名:int gethostname( char FAR *name, //[out] Pointer to a ...
- Java DNS查询内部实现
源码分析 在Java中,DNS相关的操作都是通过通过InetAddress提供的API实现的.比如查询域名对应的IP地址: String dottedQuadIpAddress = InetAddre ...
- centos 7.0 编译安装php 7.0.3
php下载页面 http://cn2.php.net/downloads.php 7.0.3多地区下载页面 http://cn2.php.net/get/php-7.0.3.tar.gz/from/a ...
随机推荐
- 多年老项目添加cocoapod管理之后的各种问题解决方案
整个组件化过程中遇到的问题及解决方案原文出处 hehuoya.com pod install 报警告(debug.release..) 解决方案:other link flags : $(inheri ...
- CountDownLatch 一个复杂的例子
CountDownLatch复杂点的例子 public class CountDownLatchTest2 { private static Random random = new Random(Sy ...
- IScroll Unable to preventDefault inside passive event listener due to target being treated as passive
最近两天企业微信下IScroll突然无法滚动了,特别慢,之前好好的,发现主要是有红色的Unable to preventDefault inside passive event listener du ...
- Linux ip Command
Syntax ip OBJECT COMMAND ip [options] OBJECT COMMAND ip OBJECT help Understanding ip command OBJECTS ...
- HTML模版大全网
HTML模版大全网,里面有一部分是后台管理的网站模版,HTML全都有.大家有需要的话,可以自行去下载. http://www.htmlmbdq.com
- Delphi - 鼠标上下滚动基础消息事件
Delphi实现对鼠标上下滚动基础消息的截获并处理 前几天有客户提出需求:由于个人PC界面限制,有时候电子图档显示不全,希望通过鼠标上下滚动用来控制电子图档的放大和缩小. 下面通过一个测试Demo来说 ...
- 搜索引擎elasticsearch监控利器cat命令
目录 一.Cat通用参数 二.cat命令 三.示例 查询aurajike索引下的总文档数和有效文档数 查询aurajike各分片的调度情况 一.Cat通用参数 参数名 指令示例 功能 Verbose ...
- php操作cassandra
php操作 https://www.cnblogs.com/fakis/archive/2010/04/16/1976653.html 这篇文章还没试过.暂时留着有时间再实验
- 微信小程序环境配置和开发!!
1.登陆微信公众平台小程序,下载 普通小程序开发者工具.或者 小游戏开发者工具. 2.新建项目需要填以下几点,然后初始demo如下,注意rpx是分成750份的单位. 3.点击预览,用微信扫描二维码,代 ...
- 隐马尔科夫模型(Hidden Markov Models) 系列之三
转自:http://blog.csdn.net/eaglex/article/details/6418219 隐马尔科夫模型(Hidden Markov Models) 定义 隐马尔科夫模型可以用一个 ...