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 ...
随机推荐
- Redis(六)Lua脚本的支持
Redis为什么需要Lua脚本的支持 当应用需要Redis完成一些Redis命令不支持的特性时,要么扩展Redis client或者更甚至编写c扩展Redis server.这都大大造成了应用的实现的 ...
- 2019-11-29-WPF-依赖属性绑定不上调试方法
原文:2019-11-29-WPF-依赖属性绑定不上调试方法 title author date CreateTime categories WPF 依赖属性绑定不上调试方法 lindexi 2019 ...
- NoSQL之redis用法
什么是NoSQL? 泛指非关系型的数据库 不支持SQL语法 存储结构跟传统关系型数据库中的那种关系表完全不同,nosql中存储的数据都是Key-Value(即键值对关系)形式 NoSQL的世界中没有一 ...
- Vue-员工管理系统
大二暑假进行了两周Vue的入门学习,主要内容就是关于前端的入门学习,在两周内学习了Vue的一些简单使用 主要就是使用数据的双向绑定,使用Vue进行数据处理,使用Bootstrap进行布局搭建,下面是我 ...
- 深入理解 Kubernetes 资源限制:CPU
原文地址:https://www.yangcs.net/posts/understanding-resource-limits-in-kubernetes-cpu-time/ 在关于 Kubernet ...
- .Net Core实战教程(三):使用Supervisor配置守护进程
安装Supervisor yum install python-setuptools easy_install supervisor 配置Supervisor mkdir /etc/superviso ...
- Python连接MongoDB数据库并执行操作
原文:https://blog.51cto.com/1767340368/2092813 环境设置: [root@mongodb ~]# cat /etc/redhat-release CentOS ...
- Go 语言基础语法-Go
Go 标记 Go 程序可以由多个标记组成,可以是关键字,标识符,常量,字符串,符号.如以下 GO 语句由 6 个标记组成: fmt.Println("Hello, World!") ...
- Spark源码执行逻辑分析【基于案例SparkPi】
一.案例SparkPi代码 package scala import org.apache.spark.sql.SparkSession import scala.math.random /** Co ...
- yaml格式配置文件
YAML 是一种可读性非常高,与程序语言数据结构非常接近.同时具备丰富的表达能力和可扩展性,并且易于使用的数据标记语言. python中处理 Yaml 格式的数据需要先下载pyyaml: pip in ...