Diff for /embedaddon/arping/src/findif_bsdroute.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2014/06/15 16:26:43 version 1.1.1.2, 2016/10/18 13:16:10
Line 1 Line 1
 /* arping/src/findif_bsdroute.c  /* arping/src/findif_bsdroute.c
  *   *
 *  Copyright (C) 2000-2009 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 27 Line 27
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
   
   #if HAVE_LIBNET_H
   #include <libnet.h>
   #endif
   
 #include "arping.h"  #include "arping.h"
   
 /**  /**
Line 37  arping_lookupdev(uint32_t srcip, Line 41  arping_lookupdev(uint32_t srcip,
                  uint32_t dstip,                   uint32_t dstip,
                  char *ebuf)                   char *ebuf)
 {  {
        FILE *f;        FILE *f = NULL;
         static char buf[10240];          static char buf[10240];
         char buf1[1024];          char buf1[1024];
         char *p,*p2;          char *p,*p2;
         int n;          int n;
   
        do_libnet_init(NULL);        *ebuf = 0;
 
         do_libnet_init(NULL, 0);
         libnet_addr2name4_r(dstip,0,buf1, 1024);          libnet_addr2name4_r(dstip,0,buf1, 1024);
   
         /*          /*
Line 52  arping_lookupdev(uint32_t srcip, Line 58  arping_lookupdev(uint32_t srcip,
         snprintf(buf, 1023, "/sbin/route -n get %s 2>&1",          snprintf(buf, 1023, "/sbin/route -n get %s 2>&1",
                  buf1);                   buf1);
         if (!(f = popen(buf, "r"))) {          if (!(f = popen(buf, "r"))) {
                   snprintf(ebuf, LIBNET_ERRBUF_SIZE,
                            "popen(/sbin/route): %s", strerror(errno));
                 goto failed;                  goto failed;
         }          }
         if (0 > (n = fread(buf, 1, sizeof(buf)-1, f))) {          if (0 > (n = fread(buf, 1, sizeof(buf)-1, f))) {
                pclose(f);                snprintf(ebuf, LIBNET_ERRBUF_SIZE,
                          "fread(/sbin/route): %s", strerror(errno));
                 goto failed;                  goto failed;
         }          }
         buf[n] = 0;          buf[n] = 0;
         if (-1 == pclose(f)) {          if (-1 == pclose(f)) {
                perror("arping: pclose()");                snprintf(ebuf, LIBNET_ERRBUF_SIZE,
                          "pclose(/sbin/route): %s", strerror(errno));
                 goto failed;                  goto failed;
         }          }
           f = NULL;
   
         /*          /*
          * Parse interface name           * Parse interface name
          */           */
        p = strstr(buf, "interface: ");        const char* head = "interface: ";
         p = strstr(buf, head);
         if (!p) {          if (!p) {
                   if (verbose) {
                           printf("arping: /sbin/route output: %s\n", buf);
                   }
                   snprintf(ebuf, LIBNET_ERRBUF_SIZE,
                            "\"interface:\" not found in /sbin/route output.");
                 goto failed;                  goto failed;
         }          }
   
        p+=11;        p += strlen(head);
   
         p2 = strchr(p, '\n');          p2 = strchr(p, '\n');
         if (!p2) {          if (!p2) {
                   if (verbose) {
                           printf("arping: /sbin/route output: %s\n", buf);
                   }
                   snprintf(ebuf, LIBNET_ERRBUF_SIZE,
                            "interface not found in /sbin/route output.");
                 goto failed;                  goto failed;
         }          }
         *p2 = 0;          *p2 = 0;
         return p;          return p;
  failed:   failed:
           if (f) {
                   pclose(f);
           }
         return NULL;          return NULL;
 }  }
 /* ---- Emacs Variables ----  /* ---- Emacs Variables ----

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


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