X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fdiscovery.c;h=8fc6895e671c8ec32a39d825e0bd25e6de8457c5;hb=c31f626c3a252a0d6805a5f3ca9154d934ea41f5;hp=65c197409808acbc65469f6139dc164b4fdba735;hpb=e8f5354b354e8e875beab6bcc7351bac88c8f28a;p=meshlink diff --git a/src/discovery.c b/src/discovery.c index 65c19740..8fc6895e 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -1,3 +1,22 @@ +/* + discovery.c -- local network discovery + Copyright (C) 2014-2021 Guus Sliepen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + #define __APPLE_USE_RFC_3542 #include "system.h" @@ -413,8 +432,9 @@ static void addr_del(meshlink_handle_t *mesh, const discovery_address_t *addr) { memmove(p, p + 1, (mesh->discovery.addresses + --mesh->discovery.address_count - p) * sizeof(*p)); } -#if !defined(__linux) && (defined(RTM_NEWADDR) || defined(__APPLE__)) -static void scan_ifaddrs(meshlink_handle_t *mesh) { +void scan_ifaddrs(meshlink_handle_t *mesh) { +#ifdef HAVE_GETIFADDRS + logger(mesh, MESHLINK_WARNING, "Calling getifaddrs()"); struct ifaddrs *ifa = NULL; if(getifaddrs(&ifa) == -1) { @@ -506,14 +526,23 @@ static void scan_ifaddrs(meshlink_handle_t *mesh) { addr.address.sa.sa_family = AF_UNKNOWN; } + if(addr.address.sa.sa_family != AF_UNKNOWN) { + char *host = NULL; + sockaddr2str(sa, &host, NULL); + logger(mesh, MESHLINK_WARNING, "iface %d (%s) address %s", index, ifap->ifa_name, host); + free(host); + } + if(addr.address.sa.sa_family != AF_UNKNOWN) { addr_add(mesh, &addr); } } freeifaddrs(ifa); -} +#else + logger(mesh, MESHLINK_ERROR, "getifaddrs() not supported"); #endif +} #if defined(__linux) static void netlink_getlink(int fd) { @@ -932,9 +961,11 @@ bool discovery_start(meshlink_handle_t *mesh) { netlink_getlink(sock); } else { logger(mesh, MESHLINK_WARNING, "Could not bind AF_NETLINK socket: %s", strerror(errno)); + scan_ifaddrs(mesh); } } else { logger(mesh, MESHLINK_WARNING, "Could not open AF_NETLINK socket: %s", strerror(errno)); + scan_ifaddrs(mesh); } #elif defined(__APPLE__)