Tag: openwrt

如何在连接的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 = […]

poll()返回POLLPRI和POLLERR

我开始使用Linux和嵌入式系统(路由器硬件和openwrt)进行C编程。 我已经启用了GPIO的中断,使用民意调查工作……差不多。 我可以使用poll(),如果我按下按钮来触发中断,poll()返回值> 0.到目前为止一切都很好。 现在我尝试在几个GPIO上同时使用poll(),因此想要分析每个潜在中断源的revents。 虽然中断似乎有效,但我得到了POLLPRI&POLLERR,我不明白为什么。 将pollfd结构减少到1个条目不会改变任何东西。 char value; int fd_btn1 = open(“/sys/class/gpio/gpio14/value”, O_RDONLY); int fd_left = open(“/sys/class/gpio/gpio12/value”, O_RDONLY); int fd_right = open(“/sys/class/gpio/gpio13/value”, O_RDONLY); struct pollfd fds[3]; fds[0].fd = fd_btn1; fds[1].fd = fd_left; fds[2].fd = fd_right; fds[0].events = POLLPRI; fds[1].events = POLLPRI; fds[2].events = POLLPRI; read(fd_btn1, &value, 1); read(fd_left, &value, 1); read(fd_right, &value, 1); ret […]