获得主机IP
来源:互联网 发布:网络与新媒体概论 pdf 编辑:程序博客网 时间:2024/04/30 23:14
gethostbyname将返回一个struct hostent的指针,这个结构定义如下:
struct hostent
{
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses */
};
#include<stdio.h>
#include<unistd.h>
#include<netdb.h>
#include<arpa/inet.h>
int get_hostip()
{
char name[100] = {0};
int ret = gethostname(name, 100);
if (ret!=0)
{
printf("get host name failed!");
return -1;
}
struct hostent * pHost = gethostbyname(name);
if (pHost == NULL)
{
printf("get host byname failed/n");
return -1;
}
printf("host name = %s/n", pHost->h_name);
char ** adder = pHost->h_addr_list;
while(*adder)
{
printf("adder = %s/n", inet_ntoa(*(struct in_addr *)*adder));
adder++;
}
return 0;
}
int main()
{
get_hostip();
return 0;
}
- 获得本地主机IP
- 获得主机IP
- 获得主机IP
- C++获得主机IP地址
- 获得主机的ip地址
- C++获得主机IP地址
- 通过域名获得主机ip
- 根据主机域名获得主机IP
- 获得主机的IP和主机名
- 获得本主机的IP地址
- 通过ip获得远程主机的MAC
- Delphi 实现获得主机IP地址和主机名
- 获得主机域名及其IP和Port端口
- linux下获得所有主机通信的ip包
- 利用IP,用C#来获得远程主机的MAC地址
- 如何用DOS获得目标主机的IP(媒介类似qq聊天等通讯工具)
- 获得IP
- 获得IP
- Linux设置环境变量
- CF 141 Div2 C Fractal Detector(状态压缩DP)
- __int64 与long long int
- GDB手册
- Eclipse快捷键
- 获得主机IP
- 仿射变换实例
- oracle 11g 学习笔记2012_10_23(2)
- android 通讯录中贾(jia|gu)处理
- 信号量和自旋锁区别
- [Happy BASH] BASH 编程学习点点滴滴
- Adobe Flash CS4 序列号-Adobe Dreamweaver CS4 序列号
- C语言可变参数列表应用——多字符串复制和链接
- HTTP协议详解