+static void hostapd_cli_action(struct wpa_ctrl *ctrl)
+{
+ fd_set rfds;
+ int fd, res;
+ struct timeval tv;
+ char buf[256];
+ size_t len;
+
+ fd = wpa_ctrl_get_fd(ctrl);
+
+ while (!hostapd_cli_quit) {
+ FD_ZERO(&rfds);
+ FD_SET(fd, &rfds);
+ tv.tv_sec = ping_interval;
+ tv.tv_usec = 0;
+ res = select(fd + 1, &rfds, NULL, NULL, &tv);
+ if (res < 0 && errno != EINTR) {
+ perror("select");
+ break;
+ }
+
+ if (FD_ISSET(fd, &rfds))
+ hostapd_cli_recv_pending(ctrl, 0, 1);
+ else {
+ len = sizeof(buf) - 1;
+ if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
+ hostapd_cli_action_process) < 0 ||
+ len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
+ printf("hostapd did not reply to PING "
+ "command - exiting\n");
+ break;
+ }
+ }
+ }
+}
+
+