Browse Source

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.
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
1c607470e3
1 changed files with 32 additions and 0 deletions
  1. 32
    0
      src/util/hijack.c

+ 32
- 0
src/util/hijack.c View File

@@ -19,6 +19,13 @@
19 19
 
20 20
 #define SNAPLEN 1600
21 21
 
22
+/*
23
+ * FIXME: is there a way to detect the version of the libpcap library?
24
+ * Version 0.9 has pcap_inject; version 0.8 doesn't, but both report
25
+ * their version number as 2.4.
26
+ */
27
+#define HAVE_PCAP_INJECT 0
28
+
22 29
 struct hijack {
23 30
 	pcap_t *pcap;
24 31
 	int fd;
@@ -46,6 +53,31 @@ static void flag_signalled ( int signal __attribute__ (( unused )) ) {
46 53
 	signalled = 1;
47 54
 }
48 55
 
56
+#if ! HAVE_PCAP_INJECT
57
+/**
58
+ * Substitute for pcap_inject(), if this version of libpcap doesn't
59
+ * have it.  Will almost certainly only work under Linux.
60
+ *
61
+ */
62
+static int pcap_inject ( pcap_t *pcap, const void *data, size_t len ) {
63
+	int fd;
64
+	char *errbuf = pcap_geterr ( pcap );
65
+
66
+	fd = pcap_get_selectable_fd ( pcap );
67
+	if ( fd < 0 ) {
68
+		snprintf ( errbuf, PCAP_ERRBUF_SIZE,
69
+			   "could not get file descriptor" );
70
+		return -1;
71
+	}
72
+	if ( write ( fd, data, len ) != len ) {
73
+		snprintf ( errbuf, PCAP_ERRBUF_SIZE,
74
+			   "could not write data: %s", strerror ( errno ) );
75
+		return -1;
76
+	}
77
+	return len;
78
+}
79
+#endif /* ! HAVE_PCAP_INJECT */
80
+
49 81
 /**
50 82
  * Log error message
51 83
  *

Loading…
Cancel
Save