您的位置:首页 > 运维架构 > Linux

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信息失败";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: