Linux获取本机IP
2011-09-27 16:31
204 查看
string localip = "";
int fd;
struct ifconf if_conf; /* net/if.h */
struct sockaddr_in *sin;
fd = socket(PF_INET, SOCK_DGRAM, 0);
if_conf.ifc_req = (struct ifreq *)malloc(MaxIFs * sizeof(struct ifreq));
if_conf.ifc_len = MaxIFs * sizeof(struct ifreq);
if(ioctl(fd, SIOCGIFCONF, &if_conf) == -1)
{
free(if_conf.ifc_req);
close(fd);
return "取IP信息失败";
}
int fd;
struct ifconf if_conf; /* net/if.h */
struct sockaddr_in *sin;
fd = socket(PF_INET, SOCK_DGRAM, 0);
if_conf.ifc_req = (struct ifreq *)malloc(MaxIFs * sizeof(struct ifreq));
if_conf.ifc_len = MaxIFs * sizeof(struct ifreq);
if(ioctl(fd, SIOCGIFCONF, &if_conf) == -1)
{
free(if_conf.ifc_req);
close(fd);
return "取IP信息失败";
}
相关文章推荐
- Python获取linux主机ip的简单实现方法
- linux查看本机IP:ifconfig获取不到ip
- linux获取主机名后用gethostbyname() 不能获取主机ip,该怎么处理
- Linux C 网络编程 - 获取本地 ip 地址,mac,通过域名获取对应的 ip
- Linux 设置IP,gate, 以及自动获取IP的方法
- Linux 获取本机IP、MAC地址用法大全
- linux分析apache日志获取最多访问的前10个IP
- linux使用dhclient自动获取IP
- linux 下获取外网IP的方法 适用ADSL
- linux下的shell命令的编写,以及java如何调用linux的shell命令(java如何获取linux上的网卡的ip信息)
- Linux下使用ioctl获取本地接口IP
- linux下java获取ip
- 将linux系统的固定ip改为自动获取
- linux 静态IP设置 DHCP自动获取IP
- linux 局域网机器如何获取路由器外网IP
- linux分析apache日志获取最多访问的前10个IP
- 用纯Java代码根据IP获取windows和linux的MAC物理地址
- Linux——获取IP及其中发现的问题
- linux编程获取本机IP地址的三种方法
- Linux下获取IP、MAC、网关、掩码的shell脚本