*** l2ping.c.orig Wed Oct 5 02:44:48 2016 --- l2ping.c Wed Oct 5 02:53:28 2016 *************** *** 187,193 **** } /* Start ping'ing */ ! for (n = 0; count == -1 || count > 0; n ++) { struct ng_btsocket_l2cap_raw_ping r; struct timeval a, b; int32_t fail; --- 187,193 ---- } /* Start ping'ing */ ! for (n = 0; ; ++n) { struct ng_btsocket_l2cap_raw_ping r; struct timeval a, b; int32_t fail; *************** *** 223,237 **** tv2msec(&b), r.result, ((fail == 0)? "" : strerror(errno))); if (!flood) { /* Wait */ a.tv_sec = wait; a.tv_usec = 0; select(0, NULL, NULL, NULL, &a); } - - if (count != -1) - count --; } free(rname); --- 223,239 ---- tv2msec(&b), r.result, ((fail == 0)? "" : strerror(errno))); + fflush(stdout); + + if (count > 0 && --count == 0) /* unlimited if <= 0 */ + break; + if (!flood) { /* Wait */ a.tv_sec = wait; a.tv_usec = 0; select(0, NULL, NULL, NULL, &a); } } free(rname);