From 1c607470e33151b209c37af402b6963a07c18a25 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 24 Mar 2006 16:43:12 +0000 Subject: [PATCH] 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. --- src/util/hijack.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/util/hijack.c b/src/util/hijack.c index 78e720b4..f504e4fe 100644 --- a/src/util/hijack.c +++ b/src/util/hijack.c @@ -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 *