本文主要通过shell命令来实现获取网卡信息。通过cmd_shell函数可以将运行命令后的输出返回。
int cmd_shell(char *shellcmd, char *outbuffer, int size) { FILE *stream; char buffer[size]; memset(buffer, 0, sizeof(buffer)); stream = popen(shellcmd, "r"); if (stream != NULL) { fread(buffer, sizeof(char), sizeof(buffer), stream); pclose(stream); memcpy(outbuffer, buffer, strlen(buffer) + 1); return 0; } else { outbuffer[0] = '