summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.pp.se>2003-06-21 16:26:53 +0000
committerThomas Habets <thomas@habets.pp.se>2003-06-21 16:26:53 +0000
commitf831e2cdc39191b1bb20c5a16bb2b22aabf3c006 (patch)
tree10b65684606ae33cb1fa44e604cd9802fbba1e09
parentf572d086358b63311031abc3e53c49d4fce7e01b (diff)
downloadarping-f831e2cdc39191b1bb20c5a16bb2b22aabf3c006.tar.gz
.
-rw-r--r--Makefile30
-rw-r--r--README36
-rw-r--r--arping-2/arping.c216
-rwxr-xr-xarping-scan-net.sh9
-rw-r--r--arping.c138
-rw-r--r--arping.yodl37
6 files changed, 330 insertions, 136 deletions
diff --git a/Makefile b/Makefile
index 1dfe76e..4fd28bc 100644
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,21 @@
-# $Id: Makefile 737 2002-11-03 19:47:58Z marvin $
+# $Id: Makefile 922 2003-06-21 16:26:53Z marvin $
TARGETS=arping
USE_NETIF=0
+FINDIF=1
OPENBSD=0
LINUX=0
SOLARIS=0
FREEBSD=0
MACOSX=0
+CC=gcc
# explicit pcap include dir is for redhat which is fux0red
-CFLAGS=-g -I/usr/local/include -L/usr/local/lib -DUSE_NETIF=$(USE_NETIF) -DOPENBSD=$(OPENBSD) -DLINUX=$(LINUX) -DSOLARIS=$(SOLARIS) -DFREEBSD=$(FREEBSD) -DMACOSX=$(MACOSX) -I/usr/include/pcap
+CFLAGS=-g -I/usr/local/include -L/usr/local/lib -DFINDIF=$(FINDIF) -DUSE_NETIF=$(USE_NETIF) -DOPENBSD=$(OPENBSD) -DLINUX=$(LINUX) -DSOLARIS=$(SOLARIS) -DFREEBSD=$(FREEBSD) -DMACOSX=$(MACOSX) -I/usr/include/pcap
-usage:
+all: arping2
+
+arping1:
@echo
@echo "usage: make [ target ]"
@echo "Target can be one of: "
@@ -22,12 +26,12 @@ usage:
@echo
@echo "Important note!"
@echo
- @echo " Arping will only work with libnet 1.0.x, not 1.1.x"
- @echo " BUT, arping2 will work with 1.1.x."
+ @echo " Arping 1.x will only work with libnet 1.0.x, not 1.1.x"
+ @echo " BUT, arping 2.x will work with 1.1.x."
@echo
- @echo " Create the BETA arping2 by typing 'make arping2'"
- @echo " Arping2 has been known to work on linux, I'm still working"
- @echo " on BSD and other support."
+ @echo " Create the arping2 by typing 'make'"
+ @echo " Arping 2.x has been known to work on linux, I'm still "
+ @echo " working on BSD and other support."
@echo
@echo " Read README for more details."
@echo
@@ -35,6 +39,8 @@ usage:
doc: arping.yodl
yodl2man -o arping.8 arping.yodl
+linux-nofindif:
+ make USE_NETIF=1 LINUX=1 FINDIF=0 all
linux:
make USE_NETIF=1 LINUX=1 all
@@ -56,19 +62,17 @@ install:
install -c arping /usr/local/bin/arping
install arping.8 /usr/local/man/man8/arping.8
-all: $(TARGETS)
-
arping.o: arping.c
- gcc -Wall $(CFLAGS) -c `libnet-config --defines` `libnet-config --cflags` arping.c
+ $(CC) -Wall $(CFLAGS) -c `libnet-config --defines` `libnet-config --cflags` arping.c
O_arping=arping.o
arping: $(O_arping)
- gcc $(CFLAGS) -g -o $@ $(O_arping) `libnet-config --libs` -lpcap
+ $(CC) $(CFLAGS) -g -o $@ $(O_arping) `libnet-config --libs` -lpcap
O_arping2=arping-2/arping.c
arping2: arping-2/arping
arping-2/arping: $(O_arping2)
- gcc -I/usr/src/Libnet-1.1.0/include -L/usr/src/Libnet-1.1.0/src -o arping arping-2/arping.c -lnet -lpcap
+ $(CC) `libnet-config --libs --defines --cflags` -o arping arping-2/arping.c -lnet -lpcap
clean:
rm -f *.o $(TARGETS)
diff --git a/README b/README
index 6934408..965e609 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-$Id: README 902 2003-06-02 08:23:47Z marvin $
+$Id: README 922 2003-06-21 16:26:53Z marvin $
ARP Ping
@@ -49,20 +49,18 @@ FAQ
---
Q: It doesn't compile!
-A: Arping 1.x won't work with libnet 1.1.x. This is due to libnet 1.1.x
- being completely different from 1.0.x. There is no real way to
- write code that works on both 1.0.x and 1.1.x.
+A: Arping 2.x will not work with Libnet 1.0.x. This is This is due to
+ libnet 1.1.x being completely different from 1.0.x. There is no
+ real way to write code that works on both 1.0.x and 1.1.x.
Since I wanted to do some other things a bit differently, I wrote
- arping 2.x. It doesn't support as many architectures or features yet, but
- I'm slowly working on it.
+ arping 2.x. It isn't as widely tested as arping 1.x, but it seems
+ to work fine.
- Arping 2.x (BETA) is included in this release and can be created
- with "make arping2". If it doesn't compile, check the Makefile and
- adjust paths.
+ Arping 2.x is now the default target, but arping 1.x is still here.
+ Arping 1.x is included in this release and can be created
+ with "make arping1" and follow instructions.
- Once I get Arping 2.x working on all architectures I'll setup so that
- the right version is compiled automatically.
---
Q: After compiling arping without any problem, i test it first with
localhost... but it doesn't respond. Isn't that strange?
@@ -199,6 +197,12 @@ A: Ah, I see. A broadcast was changed to unicast, I don't know why I set it to
... Or you can run arping -s ff:ff:ff:ff:ff:ff <host>.
If this fixes it please LET ME KNOW.
---
+Q: 1.08 and up is broken, 1.07 and down worked. What's up with that?
+
+A: If there are any problems, it should be with the interface-finding code.
+ Try compiling with 'make linux-nofindif'.
+ Also, try with the -F switch, and mail me if that worked (or didn't work).
+---
Q: Hey! Wasn't this Marvins program? You thief!
A: We are the same person.
@@ -214,13 +218,13 @@ There, I added the stupid roundtrip time feature. Now I dare you to think of
any other applicable features. (IPv4 only, for now and probably forever)
Ok, two more were thought of. Both of which are non-trivially-portable.
-1) Automatically select interface depending on IP address pinged.
+1) Automatically select interface depending on IP address pinged for more than
+ Linux.
2) Don't use SIGARLM. Non-trivial because you can't (AFAIK) select() on a pcap-
opened device.
-Arping 2.x solves the second one. Still working on the first.
-But don't use arping 2.x unless you have to. Arping 1.x has more features
-and has been tested a *lot* more.
+Arping 2.x solves the second one, and the first one has a beta solution in
+Linux.
License
-------
@@ -278,7 +282,7 @@ For pinging MAC addresses:
-------
for d in $(seq 0 255); do
sudo arping -q -c 1 -T $a.$b.$c.$d 0:60:93:34:91:99
- if [ $? == 0 ]; then
+ if [ $? = 0 ]; then
echo "Got answer with address: 192.168.0.$d"
fi
done
diff --git a/arping-2/arping.c b/arping-2/arping.c
index 504fedc..35f44c2 100644
--- a/arping-2/arping.c
+++ b/arping-2/arping.c
@@ -12,7 +12,7 @@
*
* Also finds out IP of specified MAC
*
- * $Id: arping.c 902 2003-06-02 08:23:47Z marvin $
+ * $Id: arping.c 922 2003-06-21 16:26:53Z marvin $
*/
/*
* Copyright (C) 2000-2002 Thomas Habets <thomas@habets.pp.se>
@@ -66,7 +66,7 @@
#define IP_ALEN 4
#endif
-const float version = 2.0;
+const float version = 2.01;
static libnet_t *libnet;
@@ -80,6 +80,7 @@ static int verbose = 0;
static int finddup = 0;
static unsigned int numsent = 0;
static unsigned int numrecvd = 0;
+static int addr_must_be_same = 0;
// RAWRAW is RAW|RRAW
static enum { NORMAL,QUIET,RAW,RRAW,RAWRAW } display = NORMAL;
static char *target = "huh? bug in arping?";
@@ -90,6 +91,75 @@ static char dstmac[ETH_ALEN];
volatile int time_to_die = 0;
+
+const char *arping_lookupdev_default(u_int32_t srcip, u_int32_t dstip,
+ char *ebuf)
+{
+ static const char *ifname;
+ if (!(ifname = pcap_lookupdev(ebuf))) {
+ return 0;
+ }
+ return ifname;
+}
+
+#if defined(FINDIF) && defined(linux)
+const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
+{
+ FILE *f;
+ static const char buf[1024];
+ char buf1[1024];
+ char buf2[1024];
+ char *p,*p2;
+ int n;
+
+ libnet_host_lookup_r(dstip,0,buf2);
+ libnet_host_lookup_r(srcip,0,buf1);
+
+ /*
+ * Construct and run command
+ */
+ snprintf(buf, 1023, "/sbin/ip route get %s from %s 2>&1",
+ buf2,buf1);
+ DEBUG(printf("%s\n",buf));
+ 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(srcip,dstip,ebuf);
+}
+#else
+const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
+{
+ return arping_lookupdev_default(srcip,dstip,ebuf);
+}
+#endif
+
/*
*
*/
@@ -103,9 +173,9 @@ static void sigint(int i)
*/
static void usage(int ret)
{
- printf("ARPing %1.2f BETA, by Thomas Habets <thomas@habets.pp.se>\n",
+ printf("ARPing %1.2f, by Thomas Habets <thomas@habets.pp.se>\n",
version);
- printf("usage: arping [ -qvrRd0bp ] [ -w <us> ] [ -S <host/ip> ] "
+ printf("usage: arping [ -0aAbdFpqrRv ] [ -w <us> ] [ -S <host/ip> ] "
"[ -T <host/ip ]\n"
" [ -s <MAC> ] [ -t <MAC> ] [ -c <count> ] "
"[ -i <interface> ]\n"
@@ -307,6 +377,11 @@ static void pingip_recv(const char *unused, struct pcap_pkthdr *h,
u_int32_t ip;
memcpy(&ip, (char*)harp + harp->ar_hln
+ LIBNET_ARP_H,4);
+ if (addr_must_be_same
+ && (memcmp((u_char*)harp+sizeof(struct libnet_arp_hdr),
+ dstmac, ETH_ALEN))) {
+ return;
+ }
if (dstip == ip) {
switch(display) {
case NORMAL: {
@@ -380,6 +455,13 @@ static void pingmac_recv(const char *unused, struct pcap_pkthdr *h,
|| !memcmp(dstmac, ethxmas, ETH_ALEN)))
&& !memcmp(heth->_802_3_dhost, srcmac, ETH_ALEN)) {
/* u_int8_t *cp = heth->_802_3_shost; */
+ if (addr_must_be_same) {
+ u_int32_t tmp;
+ memcpy(&tmp, &hip->ip_src, 4);
+ if (dstip != tmp) {
+ return;
+ }
+ }
switch(display) {
case QUIET:
break;
@@ -531,6 +613,7 @@ int main(int argc, char **argv)
char *parm;
int c;
unsigned int maxcount = -1;
+ int dont_use_arping_lookupdev=0;
struct bpf_program bp;
pcap_t *pcap;
static enum { NONE, PINGMAC, PINGIP } mode = NONE;
@@ -543,13 +626,34 @@ int main(int argc, char **argv)
memset(dstmac, 0xff, ETH_ALEN);
memset(ethxmas, 0xff, ETH_ALEN);
- while ((c = getopt(argc, argv, "0bdS:T:Bvhi:rRc:qs:t:paw:")) != EOF) {
+ while (EOF!=(c = getopt(argc, argv, "0aAbBc:dFhi:pqrRs:S:t:T:vw:"))) {
switch(c) {
+ case '0':
+ srcip = 0;
+ srcip_given = 1;
+ break;
case 'a':
beep = 1;
break;
- case 'v':
- verbose++;
+ case 'A':
+ addr_must_be_same = 1;
+ break;
+ case 'b':
+ srcip = 0xffffffff;
+ srcip_given = 1;
+ break;
+ case 'B':
+ dstip = 0xffffffff;
+ dstip_given = 1;
+ break;
+ case 'c':
+ maxcount = atoi(optarg);
+ break;
+ case 'd':
+ finddup = 1;
+ break;
+ case 'F':
+ dont_use_arping_lookupdev=1;
break;
case 'h':
usage(0);
@@ -563,59 +667,17 @@ int main(int argc, char **argv)
}
ifname = optarg;
break;
- case 'r':
- display = (display==RRAW)?RAWRAW:RAW;
- break;
- case 'R':
- display = (display==RAW)?RAWRAW:RRAW;
+ case 'p':
+ promisc = 1;
break;
case 'q':
display = QUIET;
break;
- case 'c':
- maxcount = atoi(optarg);
- break;
- case 'd':
- finddup = 1;
- break;
- case 'S': // set source IP, may be null for don't-know
- if (-1 == (srcip = libnet_name2addr4(libnet,
- optarg,
- LIBNET_RESOLVE))){
- fprintf(stderr, "arping: Can't resolve %s, or "
- "%s is broadcast. If it is, use -b"
- " instead of -S\n", optarg,optarg);
- exit(1);
- }
- srcip_given = 1;
- break;
- case 'T': // set destination IP
- if (mode == PINGIP) {
- fprintf(stderr, "arping: -T can only be used "
- "in MAC ping mode\n");
- exit(1);
- }
- if (-1 == (dstip = libnet_name2addr4(libnet,
- optarg,
- LIBNET_RESOLVE))){
- fprintf(stderr,"arping: Can't resolve %s, or "
- "%s is broadcast. If it is, use -B "
- "instead of -T\n",optarg,optarg);
- exit(1);
- }
- mode = PINGMAC;
- break;
- case 'b':
- srcip = 0xffffffff;
- srcip_given = 1;
- break;
- case 'B':
- dstip = 0xffffffff;
- dstip_given = 1;
+ case 'r':
+ display = (display==RRAW)?RAWRAW:RAW;
break;
- case '0':
- srcip = 0;
- srcip_given = 1;
+ case 'R':
+ display = (display==RAW)?RAWRAW:RRAW;
break;
case 's': {// spoof source MAC
unsigned int n[6];
@@ -637,6 +699,17 @@ int main(int argc, char **argv)
}
break;
}
+ case 'S': // set source IP, may be null for don't-know
+ if (-1 == (srcip = libnet_name2addr4(libnet,
+ optarg,
+ LIBNET_RESOLVE))){
+ fprintf(stderr, "arping: Can't resolve %s, or "
+ "%s is broadcast. If it is, use -b"
+ " instead of -S\n", optarg,optarg);
+ exit(1);
+ }
+ srcip_given = 1;
+ break;
case 't': { // set taget mac
unsigned int n[6];
if (mode == PINGMAC) {
@@ -663,8 +736,24 @@ int main(int argc, char **argv)
break;
mode = PINGIP;
}
- case 'p':
- promisc = 1;
+ case 'T': // set destination IP
+ if (mode == PINGIP) {
+ fprintf(stderr, "arping: -T can only be used "
+ "in MAC ping mode\n");
+ exit(1);
+ }
+ if (-1 == (dstip = libnet_name2addr4(libnet,
+ optarg,
+ LIBNET_RESOLVE))){
+ fprintf(stderr,"arping: Can't resolve %s, or "
+ "%s is broadcast. If it is, use -B "
+ "instead of -T\n",optarg,optarg);
+ exit(1);
+ }
+ mode = PINGMAC;
+ break;
+ case 'v':
+ verbose++;
break;
case 'w':
packetwait = (unsigned)atoi(optarg);
@@ -769,12 +858,19 @@ int main(int argc, char **argv)
* right one.
*/
if (!ifname) {
- if (!(ifname = pcap_lookupdev(ebuf))) {
- fprintf(stderr, "arping: pcap_lookupdev(): %s\n",ebuf);
+ if (dont_use_arping_lookupdev) {
+ ifname = arping_lookupdev_default(srcip,dstip,ebuf);
+ } else {
+ ifname = arping_lookupdev(srcip,dstip,ebuf);
+ }
+ if (!ifname) {
+ fprintf(stderr, "arping: arping_lookupdev(): %s\n",
+ ebuf);
exit(1);
}
// FIXME: check for other probably-not interfaces
- if (!strncmp(ifname, "ipsec", 5)) {
+ if (!strcmp(ifname, "ipsec")
+ || !strcmp(ifname,"lo")) {
fprintf(stderr, "arping: Um.. %s looks like the wrong "
"interface to use. Is it? "
"(-i switch)\n", ifname);
diff --git a/arping-scan-net.sh b/arping-scan-net.sh
index 08114c0..cbd340e 100755
--- a/arping-scan-net.sh
+++ b/arping-scan-net.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# $Id: arping-scan-net.sh 902 2003-06-02 08:23:47Z marvin $
+# $Id: arping-scan-net.sh 922 2003-06-21 16:26:53Z marvin $
#
# Copyright (C) 2002 Thomas Habets <thomas@habets.pp.se>
#
@@ -30,6 +30,9 @@ if [ "$1" = "" ]; then
fi
TARGET_MAC="$1"
+# seq doesnt exist on some boxen
+seq() { echo "for (i=$1; i<=$2; i++) i;" | bc | tr "\012" " "; }
+
#
# first number after 'seq' is range start, second is range end
#
@@ -43,7 +46,7 @@ for a in $(seq 192 192); do
for c in $(seq 0 0); do
for d in $(seq 0 255); do
sh -c "arping -A -q -c 1 -T $a.$b.$c.$d $TARGET_MAC
- if [ \$? == 0 ]; then
+ if [ \$? = 0 ]; then
echo Got answer with address: $a.$b.$c.$d
fi" &
done
@@ -51,4 +54,4 @@ for a in $(seq 192 192); do
done
done
done
-exit 1
+#exit 1
diff --git a/arping.c b/arping.c
index 4bc1a84..43cb972 100644
--- a/arping.c
+++ b/arping.c
@@ -12,24 +12,24 @@
*
* Also finds out IP of specified MAC
*
- * $Id: arping.c 861 2003-04-07 18:05:59Z marvin $
+ * $Id: arping.c 922 2003-06-21 16:26:53Z marvin $
*/
/*
- * Copyright (C) 2000-2002 Thomas Habets <thomas@habets.pp.se>
+ * Copyright (C) 2000-2003 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 program 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.
+ * This program 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 library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Note to self:
@@ -52,10 +52,11 @@
*
* Arch checklist:
* Solaris/sparc
- * NetBSD/alpha (is libnet or I unaligned? -- libnet I think)
- * OpenBSD/sparc64 (libnet a bit buggy)
+ * NetBSD/alpha (is libnet or arping unaligned? -- libnet I think)
+ * OpenBSD/sparc64 (libnet a bit buggy here)
* Linux/x86
* Linux/sparc
+ * Linux/hppa
*
*/
#include <stdio.h>
@@ -105,7 +106,7 @@
#define DEBUG(a)
#endif
-const float version = 1.07;
+const float version = 1.08;
struct ether_addr *mymac;
static u_char eth_xmas[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@ -142,6 +143,75 @@ static unsigned int nullip = 0;
static unsigned int is_promisc = 0;
static unsigned int addr_must_be_same = 0;
+
+const char *arping_lookupdev_default(u_int32_t srcip, u_int32_t dstip,
+ char *ebuf)
+{
+ static const char *ifname;
+ if (!(ifname = pcap_lookupdev(ebuf))) {
+ return 0;
+ }
+ return ifname;
+}
+
+#if defined(FINDIF) && defined(linux)
+const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
+{
+ FILE *f;
+ static char buf[1024];
+ char buf1[1024];
+ char buf2[1024];
+ char *p,*p2;
+ int n;
+
+ libnet_host_lookup_r(dstip,0,buf2);
+ libnet_host_lookup_r(srcip,0,buf1);
+
+ /*
+ * Construct and run command
+ */
+ snprintf(buf, 1023, "/sbin/ip route get %s from %s 2>&1",
+ buf2,buf1);
+ DEBUG(printf("%s\n",buf));
+ 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(srcip,dstip,ebuf);
+}
+#else
+const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
+{
+ return arping_lookupdev_default(srcip,dstip,ebuf);
+}
+#endif
+
static void sigint(int i)
{
DEBUG(printf("sigint()\n"));
@@ -187,7 +257,7 @@ static void alasend(int i)
if (searchmac) {
libnet_build_icmp_echo(ICMP_ECHO, /* type */
0, /* code */
- (short)random(), /* id */
+ (short)rand(), /* id */
htons(numsent-1), /* seq */
NULL, /* pointer to payload */
0, /* payload length */
@@ -407,6 +477,7 @@ int main(int argc, char **argv)
struct bpf_program bp;
char must_be_pingip = 0;
char have_eth_source = 0;
+ int dont_use_arping_lookupdev=0;
DEBUG(printf("main()\n"));
@@ -415,7 +486,7 @@ int main(int argc, char **argv)
memcpy(eth_target, eth_xmas, ETH_ALEN);
- while ((c = getopt(argc, argv, "0bdS:T:Bvhi:rRc:qs:t:paA")) != EOF) {
+ while ((c = getopt(argc, argv, "aAbBc:dF0S:T:hi:rRqs:t:pv")) != EOF) {
switch (c) {
case 'A':
addr_must_be_same = 1;
@@ -423,6 +494,19 @@ int main(int argc, char **argv)
case 'a':
beep = 1;
break;
+ case 'c':
+ maxcount = atoi(optarg);
+ break;
+ case 'd':
+ finddup = 1;
+ break;
+ case 'F':
+#if !defined(FINDIF)
+ fprintf(stderr, "arping: find-interface support not "
+ "compiled in\n";
+#endif
+ dont_use_arping_lookupdev=1;
+ break;
case 'v':
verbose++;
break;
@@ -447,12 +531,6 @@ int main(int argc, char **argv)
case 'q':
quiet = rawoutput = 1;
break;
- case 'c':
- maxcount = atoi(optarg);
- break;
- case 'd':
- finddup = 1;
- break;
case 'S':
if ((myip = libnet_name_resolve(optarg,
LIBNET_RESOLVE))
@@ -588,12 +666,18 @@ int main(int argc, char **argv)
* libnet init
*/
if (!ifname) {
- if (!(ifname = pcap_lookupdev(ebuf))) {
- fprintf(stderr, "pcap_lookupdev(): %s\n", ebuf);
+ if (dont_use_arping_lookupdev) {
+ ifname = arping_lookupdev_default(myip,dip,ebuf);
+ } else {
+ ifname = arping_lookupdev(myip,dip,ebuf);
+ }
+ if (!ifname) {
+ fprintf(stderr,"arping_lookupdev(): %s\n", ebuf);
exit(1);
}
// FIXME: check for other probably-not interfaces
- if (!strncmp(ifname, "ipsec", 5)) {
+ if (!strcmp(ifname, "ipsec")
+ || !strcmp(ifname, "lo")) {
fprintf(stderr, "arping: Um.. %s looks like the wrong "
"interface to use. Is it? "
"(-i switch)\n", ifname);
diff --git a/arping.yodl b/arping.yodl
index 43f5d52..1ce9c5d 100644
--- a/arping.yodl
+++ b/arping.yodl
@@ -1,4 +1,4 @@
-manpage(arping)(8)(4th Feb, 2003)(arping)()
+manpage(arping)(8)(21th June, 2003)(arping)()
manpagename(arping)(sends arp and/or ip pings to a given host)
@@ -35,27 +35,35 @@ manpageoptions()
startdit()
- dit(-h) Displays a help message and exits.
- dit(-q) Does not display messages, except error messages.
- dit(-a) Audiable ping.
- dit(-v) Verbose output. Use twice for more messages.
- dit(-r) Raw output: only the MAC/IP address is displayed for each reply.
- dit(-R) Raw output: Like -r but shows "the other one", can be combined with
--r.
- dit(-d) Find duplicate replies.
- dit(-B) Use instead of host if you want to address 255.255.255.255.
dit(-0) Use this option to ping with source IP address 0.0.0.0. Use this
when you haven't configured your interface yet.
Note that this may get the MAC-ping unanswered.
This is an alias for -S 0.0.0.0.
+ dit(-a) Audiable ping.
+ dit(-A) Only count addresses matching requested address (This *WILL*
+ break most things you do. Only useful if you are arpinging many
+ hosts at once. See arping-scan-net.sh for an example).
dit(-b) Like -0 but source broadcast source address (255.255.255.255).
Note that this may get the arping unanswered since it's not normal behavior
for a host.
+ dit(-B) Use instead of host if you want to address 255.255.255.255.
+ dit(-c em(count)) Only send em(count) requests.
+ dit(-d) Find duplicate replies.
+ dit(-F) Don't try to be smart about the interface name. (even if this
+switch is not given, -i overrides smartness.
+ dit(-h) Displays a help message and exits.
+ dit(-i em(interface)) Use the specified interface.
+ dit(-q) Does not display messages, except error messages.
+ dit(-r) Raw output: only the MAC/IP address is displayed for each reply.
+ dit(-R) Raw output: Like -r but shows "the other one", can be combined with
+-r.
+ dit(-s em(MAC)) Set source MAC address. You may need to use -p with this.
dit(-S em(IP)) Like -b and -0 but with set source address.
Note that this may get the arping unanswered if the target does not have
routing to the IP. If you don't own the IP you are using, you may need to turn
on promiscious mode on the interface (with -p). With this switch you can find
out what IP-address a host has without taking an IP-address yourself.
+ dit(-t em(MAC)) Set target MAC address to use when pinging IP address.
dit(-T em(IP)) Use -T as target address when pinging MACs that won't
respond to a broadcast ping but perhaps to a directed broadcast.
@@ -65,13 +73,8 @@ em(Example): \
$ arping -S <IP-B> -s <MAC-B> -p <MAC-A>
dit(-p) Turn on promiscious mode on interface, use this if you don't
"own" the MAC address you are using.
- dit(-s em(MAC)) Set source MAC address. You may need to use -p with this.
- dit(-t em(MAC)) Set target MAC address to use when pinging IP address.
- dit(-c em(count)) Only send em(count) requests.
- dit(-i em(interface)) Use the specified interface.
- dit(-A) Only count addresses matching requested address (This *WILL*
- break most things you do. Only useful if you are arpinging many
- hosts at once. See arping-scan-net.sh for an example).
+ dit(-v) Verbose output. Use twice for more messages.
+ dit(-w) (arping 2.x only)
enddit()
manpagebugs()