取本机IP
来源:互联网 发布:查字典c语言链表 编辑:程序博客网 时间:2024/04/30 09:36
#include <sys/types.h>
#include <utmpx.h>
#include <pwd.h>
#include <stdio.h>
int
main()
{
char ipaddr[100];
memset( ipaddr,0,sizeof( ipaddr ) );
getclientaddr(ipaddr);
printf( "ip==[%s]/n", ipaddr );
return 0;
}
int
getclientaddr(char *outIpAddr)
{
struct utmpx * entry=NULL;
char * mytty;
mytty=ttyname(0)+(unsigned char *)strlen("/dev/");
/*** ttyname(0) 等价终端输入tty ****/
setutxent();
while(entry=getutxent())
{
if(!strcmp(entry->ut_line,mytty))
{
strcpy(outIpAddr,entry->ut_host);
endutxent();
return 0;
}
}
endutxent();
return -1;
}
//可参考:http://www.ejiaoxue.com/article/detail/61710.htm
- 取本机IP
- 如何取本机IP地址列表
- 利用Java取本机IP地址
- shell取本机的IP地址
- pb直接在注册表取本机全部IP方法
- 取本机IP地址和网卡号
- 关于JAVA取本机ip的一些传说
- 关于JAVA取本机ip的一些传说
- 关于JAVA取本机ip的一些传说
- Delphi 中取本机的计算机名、IP地址、Windows登录的用户名
- 取iphone本机ip地址方法(非调用私有api方法)
- JAVA与Jsp取本机ip地址的正确方法,ipv6有效
- 取iphone本机ip地址方法(非调用私有api方法)
- 取iphone本机ip地址方法(非调用私有api方法)
- 取iphone本机ip地址方法(非调用私有api方法)
- 获得本机IP
- 查询本机IP
- 得到本机IP
- 2007高考作文北京卷(I)
- 因为后悔而死去
- tomcat的注释
- 关于不能识别4GB内存条的问题!
- 最快速度找到内存泄漏
- 取本机IP
- gcc的组件和软件工具
- 将数据库里的某些字段的大小写的转换
- 鼠标从这里开始 全球十大搜索引擎工作原理(转载自小新技术网)
- SaaS价值被夸大
- 夏天,空调
- 2007高考作文北京卷(II)
- Google外传系列--低成本硬件的可行性 ->七年前的Google什么样?
- 用GDB调试程序