标签:color 微信 cgi erro ++i amp code https col
#include <stdio.h>
#include <net/if.h>
int main(){
struct if_nameindex *idxlist, *idx;
idxlist = if_nameindex();
if(idxlist == NULL){
perror("if_nameindex");
return 1;
}
for(idx = idxlist; idx->if_name != NULL && idx->if_index != 0;++idx){
printf("%s\t%d\n", idx->if_name, idx->if_index);
}
if_freenameindex(idxlist);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/ioctl.h>
int main(){
ifconf ifc;
ifreq* ifr;
int fd;
int nifs, i;
fd = socket(AF_INET, SOCK_DGRAM, 0);
ifc.ifc_len = 0;
ifc.ifc_ifcu.ifcu_buf = NULL;
ioctl(fd, SIOCGIFCONF, &ifc);
printf("%d\n", ifc.ifc_len);
if(ifc.ifc_len == 0){return 1;}
ifc.ifc_ifcu.ifcu_buf = (char*)malloc(ifc.ifc_len);
ioctl(fd, SIOCGIFCONF, &ifc);
nifs = ifc.ifc_len / sizeof(ifreq);
ifr = (ifreq*)ifc.ifc_ifcu.ifcu_buf;
for(i = 0; i < nifs; ++i){
printf("%s\n",ifr[i].ifr_name);
}
close(fd);
return 0;
}
c/c++ 网络编程 UDP 用if_nameindex和ioctl取得主机网络信息
标签:color 微信 cgi erro ++i amp code https col
原文地址:https://www.cnblogs.com/xiaoshiwang/p/9789111.html