summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.pp.se>2009-09-30 13:10:22 +0200
committerThomas Habets <thomas@habets.pp.se>2009-09-30 13:10:22 +0200
commitd6c90136015a91e22a377e50360b3764ba590722 (patch)
tree174c88a89c39a2028a826ca965cf28a434f67c8d
parent445b28ce8e9e1b4df1797726c105140e09f18696 (diff)
downloadarping-d6c90136015a91e22a377e50360b3764ba590722.tar.gz
Split findif stuff into separate files
-rw-r--r--src/arping.c136
-rw-r--r--src/arping.h9
-rw-r--r--src/findif_bsd.c82
-rw-r--r--src/findif_linux.c84
-rw-r--r--src/findif_other.c37
5 files changed, 222 insertions, 126 deletions
diff --git a/src/arping.c b/src/arping.c
index 7bdadea..0f2367f 100644
--- a/src/arping.c
+++ b/src/arping.c
@@ -106,13 +106,19 @@
#define WIN32 0
#endif
+const char *
+arping_lookupdev(const char *ifname,
+ uint32_t srcip,
+ uint32_t dstip,
+ char *ebuf);
+
static const char *version = VERSION; /* from autoconf */
static libnet_t *libnet = 0;
static struct timeval lastpacketsent;
-static uint32_t srcip,dstip;
+uint32_t srcip,dstip;
static int beep = 0;
static int verbose = 0;
@@ -148,7 +154,8 @@ count_missing_dots()
/*
*
*/
-static void do_libnet_init(const char *ifname)
+void
+do_libnet_init(const char *ifname)
{
char ebuf[LIBNET_ERRBUF_SIZE];
if (verbose > 1) {
@@ -175,7 +182,7 @@ static void do_libnet_init(const char *ifname)
/*
*
*/
-static const char *
+const char *
arping_lookupdev_default(const char *ifname,
uint32_t srcip, uint32_t dstip,
char *ebuf)
@@ -193,129 +200,6 @@ arping_lookupdev_default(const char *ifname,
#endif
}
-#if defined(FINDIF) && defined(linux)
-/**
- *
- */
-static const char *arping_lookupdev(const char *ifname,
- uint32_t srcip,
- uint32_t dstip,
- char *ebuf)
-{
- FILE *f;
- static char buf[1024];
- char buf1[1024];
- char buf2[1024];
- char *p,*p2;
- int n;
-
- do_libnet_init(ifname);
- libnet_addr2name4_r(dstip,0,buf2,1024);
- libnet_addr2name4_r(srcip,0,buf1,1024);
-
- /*
- * Construct and run command
- */
- snprintf(buf, 1023, "/sbin/ip route get %s from %s 2>&1",
- buf2,buf1);
- if (!(f = popen(buf, "r"))) {
- goto failed;
- }
- if (0>(n = fread(buf, 1, sizeof(buf)-1, f))) {
- pclose(f);
- goto failed;
- }
- buf[n] = 0;
- if (-1 == pclose(f)) {
- perror("arping: pclose()");
- goto failed;
- }
-
- /*
- * Parse out device
- */
- p = strstr(buf, "dev ");
- if (!p) {
- goto failed;
- }
-
- p+=4;
-
- p2 = strchr(p, ' ');
- if (!p2) {
- goto failed;
- }
- *p2 = 0;
- return p;
- failed:
- return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
-}
-#elif defined(FINDIF) && defined(HAVE_WEIRD_BSD)
-static
-const char *
-arping_lookupdev(const char *ifname,
- uint32_t srcip, uint32_t dstip, char *ebuf)
-{
- FILE *f;
- static char buf[10240];
- char buf1[1024];
- char *p,*p2;
- int n;
-
- do_libnet_init(ifname);
- libnet_addr2name4_r(dstip,0,buf1, 1024);
- //libnet_addr2name4_r(srcip,0,buf1);
-
- /*
- * Construct and run command
- */
- snprintf(buf, 1023, "/sbin/route -n get %s 2>&1",
- buf1);
- if (!(f = popen(buf, "r"))) {
- goto failed;
- }
- if (0 > (n = fread(buf, 1, sizeof(buf)-1, f))) {
- pclose(f);
- goto failed;
- }
- buf[n] = 0;
- if (-1 == pclose(f)) {
- perror("arping: pclose()");
- goto failed;
- }
-
- /*
- * Parse out device
- */
- p = strstr(buf, "interface: ");
- if (!p) {
- goto failed;
- }
-
- p+=11;
-
- p2 = strchr(p, '\n');
- if (!p2) {
- goto failed;
- }
- *p2 = 0;
- return p;
- failed:
- return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
-}
-#else
-/*
- *
- */
-static const char *arping_lookupdev(const char *ifname,
- uint32_t srcip, uint32_t dstip,
- char *ebuf)
-{
- return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
-}
-#endif
-
-
#if WIN32
static BOOL WINAPI arping_console_ctrl_handler(DWORD dwCtrlType)
{
diff --git a/src/arping.h b/src/arping.h
new file mode 100644
index 0000000..93d8f66
--- /dev/null
+++ b/src/arping.h
@@ -0,0 +1,9 @@
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+extern uint32_t srcip,dstip;
+void do_libnet_init(const char *ifname);
+const char *arping_lookupdev_default(const char *ifname,
+ uint32_t srcip, uint32_t dstip,
+ char *ebuf);
diff --git a/src/findif_bsd.c b/src/findif_bsd.c
new file mode 100644
index 0000000..c15ed75
--- /dev/null
+++ b/src/findif_bsd.c
@@ -0,0 +1,82 @@
+/* arping/src/findif_bsd.c
+ *
+ * Copyright (C) 2000-2009 Thomas Habets <thomas@habets.pp.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+/**
+ *
+ */
+const char *
+arping_lookupdev(const char *ifname,
+ uint32_t srcip,
+ uint32_t dstip,
+ char *ebuf)
+{
+ FILE *f;
+ static char buf[10240];
+ char buf1[1024];
+ char *p,*p2;
+ int n;
+
+ do_libnet_init(ifname);
+ libnet_addr2name4_r(dstip,0,buf1, 1024);
+ //libnet_addr2name4_r(srcip,0,buf1);
+
+ /*
+ * Construct and run command
+ */
+ snprintf(buf, 1023, "/sbin/route -n get %s 2>&1",
+ buf1);
+ if (!(f = popen(buf, "r"))) {
+ goto failed;
+ }
+ if (0 > (n = fread(buf, 1, sizeof(buf)-1, f))) {
+ pclose(f);
+ goto failed;
+ }
+ buf[n] = 0;
+ if (-1 == pclose(f)) {
+ perror("arping: pclose()");
+ goto failed;
+ }
+
+ /*
+ * Parse out device
+ */
+ p = strstr(buf, "interface: ");
+ if (!p) {
+ goto failed;
+ }
+
+ p+=11;
+
+ p2 = strchr(p, '\n');
+ if (!p2) {
+ goto failed;
+ }
+ *p2 = 0;
+ return p;
+ failed:
+ return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
+}
diff --git a/src/findif_linux.c b/src/findif_linux.c
new file mode 100644
index 0000000..9bf35d2
--- /dev/null
+++ b/src/findif_linux.c
@@ -0,0 +1,84 @@
+/* arping/src/findif_linux.c
+ *
+ * Copyright (C) 2000-2009 Thomas Habets <thomas@habets.pp.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include "arping.h"
+
+/**
+ *
+ */
+const char *
+arping_lookupdev(const char *ifname,
+ uint32_t srcip,
+ uint32_t dstip,
+ char *ebuf)
+{
+ FILE *f;
+ static char buf[1024];
+ char buf1[1024];
+ char buf2[1024];
+ char *p,*p2;
+ int n;
+
+ do_libnet_init(ifname);
+ libnet_addr2name4_r(dstip,0,buf2,1024);
+ libnet_addr2name4_r(srcip,0,buf1,1024);
+
+ /*
+ * Construct and run command
+ */
+ snprintf(buf, 1023, "/sbin/ip route get %s from %s 2>&1",
+ buf2,buf1);
+ if (!(f = popen(buf, "r"))) {
+ goto failed;
+ }
+ if (0>(n = fread(buf, 1, sizeof(buf)-1, f))) {
+ pclose(f);
+ goto failed;
+ }
+ buf[n] = 0;
+ if (-1 == pclose(f)) {
+ perror("arping: pclose()");
+ goto failed;
+ }
+
+ /*
+ * Parse out device
+ */
+ p = strstr(buf, "dev ");
+ if (!p) {
+ goto failed;
+ }
+
+ p+=4;
+
+ p2 = strchr(p, ' ');
+ if (!p2) {
+ goto failed;
+ }
+ *p2 = 0;
+ return p;
+ failed:
+ return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
+}
diff --git a/src/findif_other.c b/src/findif_other.c
new file mode 100644
index 0000000..f402e73
--- /dev/null
+++ b/src/findif_other.c
@@ -0,0 +1,37 @@
+/* arping/src/findif_other.c
+ *
+ * Copyright (C) 2000-2009 Thomas Habets <thomas@habets.pp.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#if HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+/**
+ *
+ */
+const char *
+arping_lookupdev(const char *ifname,
+ uint32_t srcip,
+ uint32_t dstip,
+ char *ebuf)
+{
+ return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
+}