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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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"); 在Ubuntu中工作,但在Cross编译后不适用于OpenWRT!也许我需要选择其他方式?

提前感谢您的帮助