--- embedaddon/arping/src/findif_getifaddrs.c 2014/06/15 16:26:43 1.1.1.1 +++ embedaddon/arping/src/findif_getifaddrs.c 2021/03/16 23:40:57 1.1.1.3 @@ -1,16 +1,16 @@ /* arping/src/findif_getifaddrs.c * - * Copyright (C) 2000-2011 Thomas Habets + * Copyright (C) 2000-2014 Thomas Habets * - * This library 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 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 library is distributed in the hope that it will be useful, + * 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. + * 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., @@ -33,8 +33,14 @@ #include #include +#if HAVE_LIBNET_H +#include +#endif + #include "arping.h" +#define UNUSED(x) (void)(x) + const char * arping_lookupdev(uint32_t srcip, uint32_t dstip, @@ -44,18 +50,22 @@ arping_lookupdev(uint32_t srcip, struct ifaddrs *cur; const char *ret = NULL; int match_count = 0; /* Matching interfaces */ + UNUSED(srcip); /* best match */ in_addr_t best_mask = 0; - in_addr_t best_addr; /* Results */ static char ifname[IFNAMSIZ]; + *ebuf = 0; + if (getifaddrs(&ifa)) { if (verbose) { - printf("getifaddrs(): %s\n", strerror(errno)); + printf("arping: getifaddrs(): %s\n", strerror(errno)); } + snprintf(ebuf, LIBNET_ERRBUF_SIZE, + "getifaddrs(): %s", strerror(errno)); goto out; } for (cur = ifa; cur; cur = cur->ifa_next) { @@ -84,19 +94,21 @@ arping_lookupdev(uint32_t srcip, if (ntohl(mask) > ntohl(best_mask)) { memset(ifname, 0, sizeof(ifname)); strncpy(ifname, cur->ifa_name, sizeof(ifname)-1); - best_addr = addr; best_mask = mask; } } if (match_count) { ret = ifname; if (verbose) { - printf("Autodetected interface %s\n", ret); + printf("arping: Autodetected interface %s\n", ret); } } else { - if (verbose) { - printf("Failed to find iface using getifaddrs().\n"); + if (verbose > 1) { + printf("arping: Failed to find iface using" + " getifaddrs().\n"); } + snprintf(ebuf, LIBNET_ERRBUF_SIZE, + "No matching interface found using getifaddrs()."); } out: if (ifa) {