2
0
mirror of https://github.com/xcat2/xNBA.git synced 2024-11-23 01:51:58 +00:00

Put in a substitute pcap_inject() function, since earlier versions of

libpcap are lacking the function.  For now, we always use the
substitute version, since there's no easy way to determine whether or
not we need it.
This commit is contained in:
Michael Brown 2006-03-24 16:43:12 +00:00
parent 7e61f38799
commit 1c607470e3

View File

@ -19,6 +19,13 @@
#define SNAPLEN 1600
/*
* FIXME: is there a way to detect the version of the libpcap library?
* Version 0.9 has pcap_inject; version 0.8 doesn't, but both report
* their version number as 2.4.
*/
#define HAVE_PCAP_INJECT 0
struct hijack {
pcap_t *pcap;
int fd;
@ -46,6 +53,31 @@ static void flag_signalled ( int signal __attribute__ (( unused )) ) {
signalled = 1;
}
#if ! HAVE_PCAP_INJECT
/**
* Substitute for pcap_inject(), if this version of libpcap doesn't
* have it. Will almost certainly only work under Linux.
*
*/
static int pcap_inject ( pcap_t *pcap, const void *data, size_t len ) {
int fd;
char *errbuf = pcap_geterr ( pcap );
fd = pcap_get_selectable_fd ( pcap );
if ( fd < 0 ) {
snprintf ( errbuf, PCAP_ERRBUF_SIZE,
"could not get file descriptor" );
return -1;
}
if ( write ( fd, data, len ) != len ) {
snprintf ( errbuf, PCAP_ERRBUF_SIZE,
"could not write data: %s", strerror ( errno ) );
return -1;
}
return len;
}
#endif /* ! HAVE_PCAP_INJECT */
/**
* Log error message
*