如何在连接的Wi-Fi用户的C程序中获取IP和MAC地址?

我尝试创建可以安装到Wi-Fi路由器的客户端应用程序(OpenWRT态度调整12.09)应用程序必须用C编写并实现OpenWRT守护进程方法。 当任何访客转向Wi-Fi并连接到我的SSID时,我需要在我的C程序中使用他的IP和MAC地址。 如何为我的C程序中的任何新连接用户(设计)获取IP和MAC地址? 我开始尝试对已经连接到路由器的任何IP使用arp命令:

#include  #include  #include  int main() { char* ip = "192.168.1.101"; char output[255]; char command [255]; //system("arp -a"); sprintf(command,"%s %s %s","arp","-a",ip); FILE* arp = popen(command, "r" ); int i = 1; while (fgets(output, sizeof(output), arp) != 0) { i++; if ( i == 2 ) { printf("%s",output); char macAddress[18]; int index = (int)(strchr(output,'-')-output); printf( "\n%d",index); printf ("\n----%c", output[index-2]); memcpy(macAddress, &output[index-2], 17); macAddress[17] = '\0'; printf("\n%s",macAddress); } } pclose(arp); return 0; } 

system("arp -a"); 在Cross编译后,在Ubuntu中工作,但不适用于OpenWRT! 也许我需要选择其他方式?

提前感谢您的帮助