From b70de725cacb699280e4c172228954b68da56c7a Mon Sep 17 00:00:00 2001 From: "Joseph C. Lehner" Date: Sun, 6 Jun 2021 13:32:05 +0200 Subject: [PATCH] Don't wait for physical connection on WiFi interfaces --- ethsock.c | 15 +++++++++++++++ nmrp.c | 5 +++++ nmrpd.h | 1 + 3 files changed, 21 insertions(+) diff --git a/ethsock.c b/ethsock.c index 3200308..1b67f76 100644 --- a/ethsock.c +++ b/ethsock.c @@ -546,6 +546,21 @@ inline uint8_t *ethsock_get_hwaddr(struct ethsock *sock) return sock->hwaddr; } +bool ethsock_is_wifi(struct ethsock *sock) +{ +#if defined(NMRPFLASH_WINDOWS) + MIB_IF_ROW2 row; + + if (intf_get_if_row(sock->index, &row)) { + return row.Type == IF_TYPE_IEEE80211; + } + + return false; +#else + return false; +#endif +} + bool ethsock_is_unplugged(struct ethsock *sock) { #if defined(NMRPFLASH_LINUX) diff --git a/nmrp.c b/nmrp.c index e8d5255..e9e5194 100644 --- a/nmrp.c +++ b/nmrp.c @@ -448,6 +448,11 @@ int nmrp_do(struct nmrpd_args *args) sigh_orig = signal(SIGINT, sigh); if (ethsock_is_unplugged(sock)) { + if (ethsock_is_wifi(sock)) { + fprintf(stderr, "Error: WiFi not connected.\n"); + goto out; + } + printf("Waiting for Ethernet connection.\n"); bool unplugged = true; diff --git a/nmrpd.h b/nmrpd.h index 9faaa27..e536a5b 100644 --- a/nmrpd.h +++ b/nmrpd.h @@ -126,6 +126,7 @@ struct ethsock_ip_undo; struct ethsock *ethsock_create(const char *intf, uint16_t protocol); bool ethsock_is_unplugged(struct ethsock *sock); +bool ethsock_is_wifi(struct ethsock *sock); int ethsock_close(struct ethsock *sock); int ethsock_send(struct ethsock *sock, void *buf, size_t len); ssize_t ethsock_recv(struct ethsock *sock, void *buf, size_t len);