From bb86a878602bd05f91176ed2c3d554ee5a1bf8cc Mon Sep 17 00:00:00 2001 From: Bruno Bodin Date: Thu, 12 Jan 2017 12:05:52 +0100 Subject: [PATCH] ZSYS_INTERFACE variable can be a single digit --- src/zbeacon.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/zbeacon.c b/src/zbeacon.c index b92eff1c4..5c3b1f782 100644 --- a/src/zbeacon.c +++ b/src/zbeacon.c @@ -101,6 +101,32 @@ s_self_prepare_udp (self_t *self) send_to = INADDR_BROADCAST; found_iface = 1; } + // if ZSYS_INTERFACE is a single digit, use the corresponding interface in + // the interface list + else if (strlen(iface) == 1 && iface[0] >= '0' && iface[0] <= '9') + { + int if_number = atoi(iface); + ziflist_t *iflist = ziflist_new(); + assert(iflist); + const char *name = ziflist_first(iflist); + int idx = -1; + while (name) { + idx++; + if (idx==if_number) { + // Using inet_addr instead of inet_aton or inet_atop + // because these are not supported in Win XP + send_to = inet_addr(ziflist_broadcast(iflist)); + bind_to = inet_addr(ziflist_address(iflist)); + if (self->verbose) + zsys_info("zbeacon: interface=%s address=%s broadcast=%s", + name, ziflist_address(iflist), ziflist_broadcast(iflist)); + found_iface = 1; + break; // iface is known, so allow it + } + name = ziflist_next(iflist); + } + ziflist_destroy(&iflist); + } else { // Look for matching interface, or first ziflist item ziflist_t *iflist = ziflist_new ();