Diff for /embedaddon/arping/src/findif_getifaddrs.c between versions 1.1 and 1.1.1.3

version 1.1, 2014/06/15 16:26:43 version 1.1.1.3, 2021/03/16 23:40:57
Line 1 Line 1
 /* arping/src/findif_getifaddrs.c  /* arping/src/findif_getifaddrs.c
  *   *
 *  Copyright (C) 2000-2011 Thomas Habets <thomas@habets.se> *  Copyright (C) 2000-2014 Thomas Habets <thomas@habets.se>
  *   *
 *  This library is free software; you can redistribute it and/or *  This program is free software; you can redistribute it and/or modify
 *  modify it under the terms of the GNU General Public *  it under the terms of the GNU General Public License as published by
 *  License as published by the Free Software Foundation; either *  the Free Software Foundation; either version 2 of the License, or
 *  version 2 of the License, or (at your option) any later version. *  (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   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  General Public License for more details. *  GNU General Public License for more details.
  *   *
  *  You should have received a copy of the GNU General Public License along   *  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.,   *  with this program; if not, write to the Free Software Foundation, Inc.,
Line 33 Line 33
 #include <net/if.h>  #include <net/if.h>
 #include <netinet/in.h>  #include <netinet/in.h>
   
   #if HAVE_LIBNET_H
   #include <libnet.h>
   #endif
   
 #include "arping.h"  #include "arping.h"
   
   #define UNUSED(x) (void)(x)
   
 const char *  const char *
 arping_lookupdev(uint32_t srcip,  arping_lookupdev(uint32_t srcip,
                  uint32_t dstip,                   uint32_t dstip,
Line 44  arping_lookupdev(uint32_t srcip, Line 50  arping_lookupdev(uint32_t srcip,
         struct ifaddrs *cur;          struct ifaddrs *cur;
         const char *ret = NULL;          const char *ret = NULL;
         int match_count = 0;     /* Matching interfaces */          int match_count = 0;     /* Matching interfaces */
           UNUSED(srcip);
   
         /* best match */          /* best match */
         in_addr_t best_mask = 0;          in_addr_t best_mask = 0;
         in_addr_t best_addr;  
   
         /* Results */          /* Results */
         static char ifname[IFNAMSIZ];          static char ifname[IFNAMSIZ];
   
           *ebuf = 0;
   
         if (getifaddrs(&ifa)) {          if (getifaddrs(&ifa)) {
                 if (verbose) {                  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;                  goto out;
         }          }
         for (cur = ifa; cur; cur = cur->ifa_next) {          for (cur = ifa; cur; cur = cur->ifa_next) {
Line 84  arping_lookupdev(uint32_t srcip, Line 94  arping_lookupdev(uint32_t srcip,
                 if (ntohl(mask) > ntohl(best_mask)) {                  if (ntohl(mask) > ntohl(best_mask)) {
                         memset(ifname, 0, sizeof(ifname));                          memset(ifname, 0, sizeof(ifname));
                         strncpy(ifname, cur->ifa_name, sizeof(ifname)-1);                          strncpy(ifname, cur->ifa_name, sizeof(ifname)-1);
                         best_addr = addr;  
                         best_mask = mask;                          best_mask = mask;
                 }                  }
         }          }
         if (match_count) {          if (match_count) {
                 ret = ifname;                  ret = ifname;
                 if (verbose) {                  if (verbose) {
                        printf("Autodetected interface %s\n", ret);                        printf("arping: Autodetected interface %s\n", ret);
                 }                  }
         } else {          } else {
                if (verbose) {                if (verbose > 1) {
                        printf("Failed to find iface using getifaddrs().\n");                        printf("arping: Failed to find iface using"
                                " getifaddrs().\n");
                 }                  }
                   snprintf(ebuf, LIBNET_ERRBUF_SIZE,
                            "No matching interface found using getifaddrs().");
         }          }
  out:   out:
         if (ifa) {          if (ifa) {

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>