Diff for /embedaddon/libnet/src/libnet_link_snoop.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2013/07/22 11:54:42 version 1.1.1.3, 2023/09/27 11:11:38
Line 27 Line 27
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */   */
   
   #include "common.h"
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/file.h>  #include <sys/file.h>
 #include <netinet/in.h>  #include <netinet/in.h>
 #include <netinet/udp.h>  #include <netinet/udp.h>
 #include <netinet/tcp.h>  #include <netinet/tcp.h>
   
 #if (HAVE_CONFIG_H)  
 #include "../include/config.h"  
 #endif  
 #include "../include/libnet.h"  
   
 #include <net/raw.h>  #include <net/raw.h>
 #include <net/if.h>  #include <net/if.h>
   
 #include <netinet/ip_var.h>  #include <netinet/ip_var.h>
 #include <netinet/if_ether.h>  #include <netinet/if_ether.h>
 #include <netinet/udp_var.h>  #include <netinet/udp_var.h>
 #include <netinet/tcpip.h>  
   
 #include "../include/gnuc.h"  #include "../include/gnuc.h"
 #include "../include/bpf.h"  #include "../include/bpf.h"
Line 63  libnet_open_link(libnet_t *l) Line 59  libnet_open_link(libnet_t *l)
     struct sockaddr_raw sr;      struct sockaddr_raw sr;
     uint v;      uint v;
   
    if (l == NULL)     if (l == NULL)
     {
         return -1;          return -1;
     }      }
   
     l->fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN);      l->fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN);
   
    if (l->fd < 0) {    if (l->fd < 0)
        sprintf(l->err_buf, "drain socket: %s", strerror(errno));    {
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                  "drain socket: %s", strerror(errno));
         goto bad;          goto bad;
     }      }
   
Line 79  libnet_open_link(libnet_t *l) Line 78  libnet_open_link(libnet_t *l)
     strncpy(sr.sr_ifname, l->device, sizeof(sr.sr_ifname) - 1);      strncpy(sr.sr_ifname, l->device, sizeof(sr.sr_ifname) - 1);
     sr.sr_ifname[sizeof(sr.sr_ifname) - 1] = '\0';      sr.sr_ifname[sizeof(sr.sr_ifname) - 1] = '\0';
   
    if (bind(l->fd, (struct sockaddr *)&sr, sizeof(sr))) {    if (bind(l->fd, (struct sockaddr *)&sr, sizeof(sr)))
        sprintf(l->err_buf, "drain bind: %s", strerror(errno));    {
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                  "drain bind: %s", strerror(errno));
         goto bad;          goto bad;
     }      }
   
Line 95  libnet_open_link(libnet_t *l) Line 96  libnet_open_link(libnet_t *l)
             strncmp("ep", l->device, 2) == 0  ||   /* Challenge 8x10 Mbit EPLEX */              strncmp("ep", l->device, 2) == 0  ||   /* Challenge 8x10 Mbit EPLEX */
             strncmp("vfe", l->device, 3) == 0 ||   /* Challenge VME 100Mbit */              strncmp("vfe", l->device, 3) == 0 ||   /* Challenge VME 100Mbit */
             strncmp("fa", l->device, 2) == 0  ||              strncmp("fa", l->device, 2) == 0  ||
            strncmp("qaa", l->device, 3) == 0) {            strncmp("qaa", l->device, 3) == 0)
     {
         l->link_type = DLT_EN10MB;          l->link_type = DLT_EN10MB;
     }      }
     else if (strncmp("ipg", l->device, 3) == 0 ||      else if (strncmp("ipg", l->device, 3) == 0 ||
             strncmp("rns", l->device, 3) == 0 ||        /* O2/200/2000 FDDI */              strncmp("rns", l->device, 3) == 0 ||        /* O2/200/2000 FDDI */
            strncmp("xpi", l->device, 3) == 0) {            strncmp("xpi", l->device, 3) == 0)
     {
         l->link_type = DLT_FDDI;          l->link_type = DLT_FDDI;
     }      }
    else if (strncmp("ppp", l->device, 3) == 0) {    else if (strncmp("ppp", l->device, 3) == 0)
     {
         l->link_type = DLT_RAW;          l->link_type = DLT_RAW;
    } else if (strncmp("lo", l->device, 2) == 0) {    }
     else if (strncmp("lo", l->device, 2) == 0)
     {
         l->link_type = DLT_NULL;          l->link_type = DLT_NULL;
    } else {    }
        sprintf(l->err_buf, "drain: unknown physical layer type");    else
     {
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                  "drain: unknown physical layer type");
         goto bad;          goto bad;
     }      }
   
Line 166  libnet_get_hwaddr(libnet_t *l) Line 175  libnet_get_hwaddr(libnet_t *l)
 {  {
     struct ifreq ifdat;      struct ifreq ifdat;
     int s = -1;      int s = -1;
     struct libnet_ether_addr *ea = NULL;  
   
    if (-1 == (s = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP))) {    if (-1 == (s = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP)))
     {
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,          snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                 "socket(): %s", strerror(errno));                  "socket(): %s", strerror(errno));
         goto errout;          goto errout;
     }      }
   
     memset(&ifdat, 0, sizeof(struct ifreq));      memset(&ifdat, 0, sizeof(struct ifreq));
     strncpy(ifdat.ifr_name, l->device, IFNAMSIZ);      strncpy(ifdat.ifr_name, l->device, IFNAMSIZ);
    if (ioctl(s, SIOCGIFADDR, &ifdat)) {    if (ioctl(s, SIOCGIFADDR, &ifdat) < 0)
     {
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,          snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
                 "SIOCGIFADDR: %s", strerror(errno));                  "SIOCGIFADDR: %s", strerror(errno));
         goto errout;          goto errout;
     }      }
     if (!(ea = malloc(sizeof(struct libnet_ether_addr)))) {  
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,  
                 "malloc(): %s", strerror(errno));  
         goto errout;  
     }  
     memcpy(ea, &ifdat.ifr_addr.sa_data, ETHER_ADDR_LEN);  
     close(s);      close(s);
     s = -1;  
     return ea;  
   
       return memcpy(l->link_addr.ether_addr_octet, &ifdat.ifr_addr.sa_data,
                     ETHER_ADDR_LEN);
   
  errout:   errout:
    if (s > 0) {    if (s > 0)
     {
         close(s);          close(s);
     }      }
    if (ea) {    if (ea)
     {
         free(ea);          free(ea);
         ea = 0;          ea = 0;
     }      }
    return 0;
     return NULL;
 }  }
/* ---- Emacs Variables ----
 /**
  * Local Variables:   * Local Variables:
 * c-basic-offset: 4 *  indent-tabs-mode: nil
 * indent-tabs-mode: nil   * End:
  * End:   * End:
  */   */

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


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