[arpwatch] fix devlookup to start when -i interface specified
aledvink
aledvink at fedoraproject.org
Mon Oct 15 14:16:06 UTC 2012
commit befc39955506cb319ba97f15eef6380e273ee4bb
Author: Ales Ledvinka <aledvink at redhat.com>
Date: Mon Oct 15 16:15:49 2012 +0200
fix devlookup to start when -i interface specified
arpwatch-2.1a15-lookupiselect.patch | 98 +++++++++++++++++++++++++++++++++++
arpwatch.spec | 7 ++-
2 files changed, 104 insertions(+), 1 deletions(-)
---
diff --git a/arpwatch-2.1a15-lookupiselect.patch b/arpwatch-2.1a15-lookupiselect.patch
new file mode 100644
index 0000000..cc3a5bd
--- /dev/null
+++ b/arpwatch-2.1a15-lookupiselect.patch
@@ -0,0 +1,98 @@
+diff -up ./arpwatch.c.iselect ./arpwatch.c
+--- ./arpwatch.c.iselect 2012-10-15 16:01:24.701335291 +0200
++++ ./arpwatch.c 2012-10-15 16:07:18.626322639 +0200
+@@ -162,50 +162,52 @@ void dropprivileges(const char* user)
+ }
+
+ char *
+-get_first_dev(pcap_t **pd, int *linktype, char *errbuf)
++try_dev(char *interface, pcap_t **pd, int *linktype, char *errbuf)
+ {
+- static char interface[IF_NAMESIZE + 1];
+ register int snaplen, timeout;
+- pcap_if_t *alldevs;
+- pcap_if_t *dev;
+- char *ret = NULL;
+
+ snaplen = max(sizeof(struct ether_header),
+ sizeof(struct fddi_header)) + sizeof(struct ether_arp);
+ timeout = 1000;
+
+- if (pcap_findalldevs(&alldevs, errbuf) == -1) {
+- (void)fprintf(stderr, "%s: lookup_device: %s\n",
+- prog, errbuf);
+- exit(1);
++ *pd = pcap_open_live(interface, snaplen, 1, timeout, errbuf);
++ if (NULL == pd) {
++ syslog(LOG_ERR, "pcap open %s: %s", interface, errbuf);
++ return NULL;
+ }
++ *linktype = pcap_datalink(*pd);
++ /* Must be ethernet or fddi */
++ if (*linktype != DLT_EN10MB && *linktype != DLT_FDDI) {
++ syslog(LOG_ERR, "(%s) Link layer type %d not ethernet or fddi",
++ interface, *linktype);
++ pcap_close(*pd);
++ return NULL;
++ }
++ return interface;
++}
+
+- for (dev = alldevs; dev; dev = dev->next) {
+- strncpy(interface, dev->name, strlen(dev->name)+1);
+-
+- *pd = pcap_open_live(interface, snaplen, 1, timeout, errbuf);
+- if (*pd == NULL) {
+- syslog(LOG_ERR, "pcap open %s: %s, trying next...", interface, errbuf);
+- continue;
+- /* exit(1); */
+- }
++char *
++iterate_dev(char *arginterface, pcap_t **pd, int *linktype, char *errbuf)
++{
++ static char interface[IF_NAMESIZE + 1];
++ pcap_if_t *alldevs;
++ pcap_if_t *dev;
+
+- *linktype = pcap_datalink(*pd);
+- /* Must be ethernet or fddi */
+- if (*linktype != DLT_EN10MB && *linktype != DLT_FDDI) {
+- syslog(LOG_ERR, "(%s) Link layer type %d not ethernet or fddi, trying next...",
+- interface, *linktype);
+- pcap_close(*pd);
++ if (NULL != arginterface) {
++ return try_dev(arginterface, pd, linktype, errbuf);
++ } else {
++ if (pcap_findalldevs(&alldevs, errbuf) == -1) {
++ (void)fprintf(stderr, "%s: lookup_device: %s\n",
++ prog, errbuf);
++ exit(1);
+ }
+- else {
+- /* First match, use it */
+- ret = interface;
+- break;
++ for (dev = alldevs; dev && (arginterface == NULL); dev = dev->next) {
++ strncpy(interface, dev->name, strlen(dev->name)+1);
++ arginterface = try_dev(interface, pd, linktype, errbuf);
+ }
+-
++ pcap_freealldevs(alldevs);
++ return arginterface;
+ }
+- pcap_freealldevs(alldevs);
+- return (ret);
+ }
+
+ int
+@@ -315,8 +317,8 @@ main(int argc, char **argv)
+ } else {
+
+ /* Determine interface if not specified */
+- if (interface == NULL &&
+- (interface = get_first_dev(&pd, &linktype, errbuf)) == NULL) {
++ interface = iterate_dev(interface, &pd, &linktype, errbuf);
++ if (interface == NULL) {
+ (void)fprintf(stderr, "%s: lookup_device: no suitable interface found\n",
+ prog);
+ exit(1);
diff --git a/arpwatch.spec b/arpwatch.spec
index 1fcc43d..285c8fe 100644
--- a/arpwatch.spec
+++ b/arpwatch.spec
@@ -3,7 +3,7 @@
Name: arpwatch
Epoch: 14
Version: 2.1a15
-Release: 23%{?dist}
+Release: 24%{?dist}
Summary: Network monitoring tools for tracking IP addresses on a network
Group: Applications/System
License: BSD with advertising
@@ -35,6 +35,7 @@ Patch10: arpwatch-2.1a15-extraman.patch
Patch11: arpwatch-exitcode.patch
Patch12: arpwatch-2.1a15-dropgroup.patch
Patch13: arpwatch-2.1a15-devlookup.patch
+Patch14: arpwatch-2.1a15-lookupiselect.patch
%description
The arpwatch package contains arpwatch and arpsnmp. Arpwatch and
@@ -62,6 +63,7 @@ network.
%patch11 -p1 -b .exitcode
%patch12 -p1 -b .dropgroup
%patch13 -p1 -b .devlookup
+%patch14 -p1 -b .iselect
%build
%configure
@@ -139,6 +141,9 @@ fi
%attr(-,arpwatch,arpwatch) %verify(not md5 size mtime) %config(noreplace) %{_vararpwatch}/ethercodes.dat
%changelog
+* Mon Oct 15 2012 Ales Ledvinka <aledvink at redhat.com> - 14:2.1a15-24
+- fix devlookup to start with -i interface specified (#842660)
+
* Wed Aug 22 2012 Jan Synáček <jsynacek at redhat.com> - 14:2.1a15-23
- Add system-rpm macros (#850032)
More information about the scm-commits
mailing list