aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-04-10 14:59:26 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2009-04-10 14:59:26 +0000
commit200662291aca6d1c6c45537c24ec9df8ad5135ef (patch)
tree8666a48841ad95b6777d3ef824ffeb3badeb05b8
parent2a42d9d6eea91f6cb7458b1620d784dd83cdc188 (diff)
downloadalpine_aports-200662291aca6d1c6c45537c24ec9df8ad5135ef.tar.bz2
alpine_aports-200662291aca6d1c6c45537c24ec9df8ad5135ef.tar.xz
alpine_aports-200662291aca6d1c6c45537c24ec9df8ad5135ef.zip
core/libpcap: fix for tcpdump -i any
patch found here: http://github.com/mcr/libpcap/commit/8fa17a5a554aaeb85d3ec4118b45a31f1efd6808
-rw-r--r--core/libpcap/APKBUILD14
-rw-r--r--core/libpcap/libpcap-any.patch157
2 files changed, 167 insertions, 4 deletions
diff --git a/core/libpcap/APKBUILD b/core/libpcap/APKBUILD
index 3db64d26cf..ebe0996161 100644
--- a/core/libpcap/APKBUILD
+++ b/core/libpcap/APKBUILD
@@ -1,19 +1,24 @@
1# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
1pkgname=libpcap 2pkgname=libpcap
2pkgver=1.0.0 3pkgver=1.0.0
3pkgrel=0 4pkgrel=1
4pkgdesc="A system-independent interface for user-level packet capture" 5pkgdesc="A system-independent interface for user-level packet capture"
5url="http://www.tcpdump.org/" 6url="http://www.tcpdump.org/"
6license="BSD" 7license="BSD"
7depends="uclibc" 8depends="uclibc"
8makedepends="bison flex" 9makedepends="bison flex"
9source="http://www.tcpdump.org/release/$pkgname-$pkgver.tar.gz 10source="http://www.tcpdump.org/release/$pkgname-$pkgver.tar.gz
10 $pkgname-1.0.0-LDFLAGS.patch" 11 $pkgname-1.0.0-LDFLAGS.patch
12 $pkgname-any.patch"
11subpackages="$pkgname-doc $pkgname-dev" 13subpackages="$pkgname-doc $pkgname-dev"
12 14
13build () 15build ()
14{ 16{
15 cd ${startdir}/src/${pkgname}-${pkgver} 17 cd ${startdir}/src/${pkgname}-${pkgver}
16 patch -Np1 -i ${startdir}/libpcap-1.0.0-LDFLAGS.patch || return 1 18 for i in ../*.patch; do
19 msg "Applying $i..."
20 patch -p1 -i $i || return 1
21 done
17 22
18 ./configure --prefix=/usr --enable-ipv6 23 ./configure --prefix=/usr --enable-ipv6
19 24
@@ -26,4 +31,5 @@ build ()
26# ln -s ../pcap-bpf.h bpf.h 31# ln -s ../pcap-bpf.h bpf.h
27} 32}
28md5sums="9ad1358c5dec48456405eac197a46d3d libpcap-1.0.0.tar.gz 33md5sums="9ad1358c5dec48456405eac197a46d3d libpcap-1.0.0.tar.gz
292bf7e986980c6e5d99758ba55b48d706 libpcap-1.0.0-LDFLAGS.patch" 342bf7e986980c6e5d99758ba55b48d706 libpcap-1.0.0-LDFLAGS.patch
351e6b01c4f283b497e81e137c3f35e744 libpcap-any.patch"
diff --git a/core/libpcap/libpcap-any.patch b/core/libpcap/libpcap-any.patch
new file mode 100644
index 0000000000..7754513b88
--- /dev/null
+++ b/core/libpcap/libpcap-any.patch
@@ -0,0 +1,157 @@
1commit 8fa17a5a554aaeb85d3ec4118b45a31f1efd6808
2Author: guy <guy>
3Date: Wed Nov 19 08:20:39 2008 +0000
4
5 Fix the handling of the "any" device, including making it reject
6 attempts to open it in monitor mode.
7
8diff --git a/pcap-linux.c b/pcap-linux.c
9index 2a92d30..b18c4d2 100644
10--- a/pcap-linux.c
11+++ b/pcap-linux.c
12@@ -297,6 +297,12 @@ pcap_create(const char *device, char *ebuf)
13 {
14 pcap_t *handle;
15
16+ /*
17+ * A null device name is equivalent to the "any" device.
18+ */
19+ if (device == NULL)
20+ device = "any";
21+
22 #ifdef HAVE_DAG_API
23 if (strstr(device, "dag")) {
24 return dag_create(device, ebuf);
25@@ -338,10 +344,9 @@ pcap_can_set_rfmon_linux(pcap_t *p)
26 struct iwreq ireq;
27 #endif
28
29- if (p->opt.source == NULL) {
30+ if (strcmp(p->opt.source, "any") == 0) {
31 /*
32- * This is equivalent to the "any" device, and we don't
33- * support monitor mode on it.
34+ * Monitor mode makes no sense on the "any" device.
35 */
36 return 0;
37 }
38@@ -518,12 +523,11 @@ pcap_activate_linux(pcap_t *handle)
39 handle->stats_op = pcap_stats_linux;
40
41 /*
42- * NULL and "any" are special devices which give us the hint to
43- * monitor all devices.
44+ * The "any" device is a special device which causes us not
45+ * to bind to a particular device and thus to look at all
46+ * devices.
47 */
48- if (!device || strcmp(device, "any") == 0) {
49- device = NULL;
50- handle->md.device = strdup("any");
51+ if (strcmp(device, "any") == 0) {
52 if (handle->opt.promisc) {
53 handle->opt.promisc = 0;
54 /* Just a warning. */
55@@ -531,10 +535,9 @@ pcap_activate_linux(pcap_t *handle)
56 "Promiscuous mode not supported on the \"any\" device");
57 status = PCAP_WARNING_PROMISC_NOTSUP;
58 }
59+ }
60
61- } else
62- handle->md.device = strdup(device);
63-
64+ handle->md.device = strdup(device);
65 if (handle->md.device == NULL) {
66 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "strdup: %s",
67 pcap_strerror(errno) );
68@@ -1657,19 +1660,21 @@ static int
69 activate_new(pcap_t *handle)
70 {
71 #ifdef HAVE_PF_PACKET_SOCKETS
72+ const char *device = handle->opt.source;
73+ int is_any_device = (strcmp(device, "any") == 0);
74 int sock_fd = -1, arptype, val;
75 int err = 0;
76 struct packet_mreq mr;
77- const char* device = handle->opt.source;
78
79 /*
80- * Open a socket with protocol family packet. If a device is
81- * given we try to open it in raw mode otherwise we use
82- * the cooked interface.
83+ * Open a socket with protocol family packet. If the
84+ * "any" device was specified, we open a SOCK_DGRAM
85+ * socket for the cooked interface, otherwise we first
86+ * try a SOCK_RAW socket for the raw interface.
87 */
88- sock_fd = device ?
89- socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))
90- : socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL));
91+ sock_fd = is_any_device ?
92+ socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_ALL)) :
93+ socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
94
95 if (sock_fd == -1) {
96 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "socket: %s",
97@@ -1704,7 +1709,7 @@ activate_new(pcap_t *handle)
98 * to cooked mode if we have an unknown interface type
99 * or a type we know doesn't work well in raw mode.
100 */
101- if (device) {
102+ if (!is_any_device) {
103 /* Assume for now we don't need cooked mode. */
104 handle->md.cooked = 0;
105
106@@ -1819,15 +1824,23 @@ activate_new(pcap_t *handle)
107 }
108 } else {
109 /*
110- * This is cooked mode.
111+ * The "any" device.
112+ */
113+ if (handle->opt.rfmon) {
114+ /*
115+ * It doesn't support monitor mode.
116+ */
117+ return PCAP_ERROR_RFMON_NOTSUP;
118+ }
119+
120+ /*
121+ * It uses cooked mode.
122 */
123 handle->md.cooked = 1;
124 handle->linktype = DLT_LINUX_SLL;
125
126 /*
127 * We're not bound to a device.
128- * XXX - true? Or true only if we're using
129- * the "any" device?
130 * For now, we're using this as an indication
131 * that we can't transmit; stop doing that only
132 * if we figure out how to transmit in cooked
133@@ -1852,10 +1865,13 @@ activate_new(pcap_t *handle)
134
135 /*
136 * Hmm, how can we set promiscuous mode on all interfaces?
137- * I am not sure if that is possible at all.
138+ * I am not sure if that is possible at all. For now, we
139+ * silently ignore attempts to turn promiscuous mode on
140+ * for the "any" device (so you don't have to explicitly
141+ * disable it in programs such as tcpdump).
142 */
143
144- if (device && handle->opt.promisc) {
145+ if (!is_any_device && handle->opt.promisc) {
146 memset(&mr, 0, sizeof(mr));
147 mr.mr_ifindex = handle->md.ifindex;
148 mr.mr_type = PACKET_MR_PROMISC;
149@@ -3118,7 +3134,7 @@ activate_old(pcap_t *handle)
150
151 /* Bind to the given device */
152
153- if (!device) {
154+ if (strcmp(device, "any") == 0) {
155 strncpy(handle->errbuf, "pcap_activate: The \"any\" device isn't supported on 2.0[.x]-kernel systems",
156 PCAP_ERRBUF_SIZE);
157 return PCAP_ERROR;