summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorMichael Brown2006-03-24 17:43:12 +0100
committerMichael Brown2006-03-24 17:43:12 +0100
commit1c607470e33151b209c37af402b6963a07c18a25 (patch)
treebd44621a30e1a618fc544cfe2778ad875c7f5b51 /src/util
parentMoved "hello world" protocol implementation out of prototester.c and into (diff)
downloadipxe-1c607470e33151b209c37af402b6963a07c18a25.tar.gz
ipxe-1c607470e33151b209c37af402b6963a07c18a25.tar.xz
ipxe-1c607470e33151b209c37af402b6963a07c18a25.zip
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.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/hijack.c32
1 files changed, 32 insertions, 0 deletions
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
*