diff --git a/tools/isotest.c b/tools/isotest.c
index 0eae3cd..c71bc6f 100644
--- a/tools/isotest.c
+++ b/tools/isotest.c
#include <time.h>
#include <inttypes.h>
#include <sys/wait.h>
+#include <poll.h>
#include "lib/bluetooth.h"
#include "lib/hci.h"
socklen_t optlen;
int sk, nsk, fd = -1;
char ba[18];
+ struct pollfd fds;
+ int err, sk_err;
+ socklen_t len;
if (filename) {
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
goto error;
}
+ /* Check if connection was successful */
+ memset(&fds, 0, sizeof(fds));
+ fds.fd = nsk;
+ fds.events = POLLERR;
+
+ if (poll(&fds, 1, 0) > 0 && (fds.revents & POLLERR)) {
+ len = sizeof(sk_err);
+
+ if (getsockopt(nsk, SOL_SOCKET, SO_ERROR,
+ &sk_err, &len) < 0)
+ err = -errno;
+ else
+ err = -sk_err;
+
+ if (err < 0)
+ syslog(LOG_ERR, "Connection failed: %s (%d)",
+ strerror(-err), -err);
+
+ close(nsk);
+ continue;
+ }
+
if (fork()) {
/* Parent */
close(nsk);