Changeset 1760

Show
Ignore:
Timestamp:
03/22/07 22:54:17 (22 months ago)
Author:
aturner
Message:

use libpcap for libnet & pf_packet. fixes #125

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/sendpacket.c

    r1758 r1760  
    721721{ 
    722722    int dlt; 
    723 #if defined HAVE_PF_PACKET 
    724     dlt = -1; 
     723#if defined HAVE_PF_PACKET || defined HAVE_LIBNET 
     724    /* use libpcap to get dlt */ 
     725    pcap_t *pcap; 
     726    char errbuf[PCAP_ERRBUF_SIZE]; 
     727    if ((pcap = pcap_open_live(sp->device, 65535, 0, 0, errbuf)) == NULL) { 
     728        warnx("Unable to get DLT value for %s: %s", sp->device, errbuf); 
     729        return(-1); 
     730    } 
     731    dlt = pcap_datalink(pcap); 
     732    pcap_close(pcap); 
    725733#elif defined HAVE_BPF 
    726734    int rcode; 
    727735 
    728      
    729736    if ((rcode = ioctl(sp->handle.fd, BIOCGDLT, &dlt)) < 0) { 
    730737        warnx("Unable to get DLT value for BPF device (%s): %s", sp->device, strerror(errno)); 
    731         return -1; 
    732     } 
    733 #elif defined HAVE_LIBNET 
    734     dlt = -1; 
     738        return(-1); 
     739    } 
    735740#else /* HAVE_PCAP_SENDPACKET / HAVE_PCAP_INJECT */ 
    736741    dlt = pcap_datalink(sp->handle.pcap);