Show
Ignore:
Timestamp:
03/20/07 22:21:56 (22 months ago)
Author:
aturner
Message:

add support for getting DLT of interface for sendpacket
unfortunately, not all methods seem to support getting DLT :(
refs #125

Files:
1 modified

Legend:

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

    r1719 r1735  
    713713 
    714714#endif /* HAVE_BPF */ 
     715 
     716/* 
     717 * Return -1 if we can't figure it out, else return the DLT_ value 
     718 */ 
     719int  
     720sendpacket_get_dlt(sendpacket_t *sp) 
     721{ 
     722    int dlt; 
     723#if defined HAVE_PF_PACKET 
     724    dlt = -1; 
     725#elif defined HAVE_BPF 
     726    int fh, rcode; 
     727 
     728     
     729    if ((rcode = ioctl(sp->handle.fd, BIOCGDLT, &dlt)) < 0) { 
     730        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; 
     735#else /* HAVE_PCAP_SENDPACKET / HAVE_PCAP_INJECT */ 
     736    dlt = pcap_datalink(sp->handle.pcap); 
     737#endif 
     738    return dlt; 
     739} 
     740