summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.pp.se>2008-02-04 13:03:47 +0000
committerThomas Habets <thomas@habets.pp.se>2008-02-04 13:03:47 +0000
commit04148e9236934f38133b48d5196ad65510daa04d (patch)
tree1c5b05980c4b65a198ee973253163b58fbd37807
parentb646c32fe438f79ecbcdd08903330905e11029c0 (diff)
downloadarping-04148e9236934f38133b48d5196ad65510daa04d.tar.gz
work around libnet bug: never call libnet_init() with ifname=NULL.
Thanks Pavol Babincak <scroolik@gmail.com>
-rw-r--r--arping-2/arping.c37
-rw-r--r--arping.865
2 files changed, 57 insertions, 45 deletions
diff --git a/arping-2/arping.c b/arping-2/arping.c
index a9326f6..5d97382 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 1972 2007-09-19 12:35:16Z marvin $
+ * $Id: arping.c 2040 2008-02-04 13:03:47Z marvin $
*/
/*
* Copyright (C) 2000-2002 Thomas Habets <thomas@habets.pp.se>
@@ -151,8 +151,10 @@ static void do_libnet_init(const char *ifname)
/*
*
*/
-static const char *arping_lookupdev_default(u_int32_t srcip, u_int32_t dstip,
- char *ebuf)
+static const char *
+arping_lookupdev_default(const char *ifname,
+ u_int32_t srcip, u_int32_t dstip,
+ char *ebuf)
{
#ifdef WIN32
WCHAR buf[LIBNET_ERRBUF_SIZE + PCAP_ERRBUF_SIZE];
@@ -171,7 +173,9 @@ static const char *arping_lookupdev_default(u_int32_t srcip, u_int32_t dstip,
/*
*
*/
-static const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip,
+static const char *arping_lookupdev(const char *ifname,
+ u_int32_t srcip,
+ u_int32_t dstip,
char *ebuf)
{
FILE *f;
@@ -181,7 +185,7 @@ static const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip,
char *p,*p2;
int n;
- do_libnet_init(NULL);
+ do_libnet_init(ifname);
libnet_addr2name4_r(dstip,0,buf2);
libnet_addr2name4_r(srcip,0,buf1);
@@ -220,12 +224,13 @@ static const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip,
*p2 = 0;
return p;
failed:
- return arping_lookupdev_default(srcip,dstip,ebuf);
+ return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
}
#elif defined(FINDIF) && defined(HAVE_WEIRD_BSD)
static
const char *
-arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
+arping_lookupdev(const char *ifname,
+ u_int32_t srcip, u_int32_t dstip, char *ebuf)
{
FILE *f;
static char buf[10240];
@@ -233,7 +238,7 @@ arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
char *p,*p2;
int n;
- do_libnet_init(NULL);
+ do_libnet_init(ifname);
libnet_addr2name4_r(dstip,0,buf1);
//libnet_addr2name4_r(srcip,0,buf1);
@@ -278,10 +283,11 @@ arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
/*
*
*/
-static const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip,
+static const char *arping_lookupdev(const char *ifname,
+ u_int32_t srcip, u_int32_t dstip,
char *ebuf)
{
- return arping_lookupdev_default(srcip,dstip,ebuf);
+ return arping_lookupdev_default(ifname,srcip,dstip,ebuf);
}
#endif
@@ -1042,7 +1048,7 @@ int main(int argc, char **argv)
break;
}
case 'S': // set source IP, may be null for don't-know
- do_libnet_init(NULL);
+ do_libnet_init(ifname);
if (-1 == (srcip = libnet_name2addr4(libnet,
optarg,
LIBNET_RESOLVE))){
@@ -1079,7 +1085,7 @@ int main(int argc, char **argv)
"in MAC ping mode\n");
exit(1);
}
- do_libnet_init(NULL);
+ do_libnet_init(ifname);
if (-1 == (dstip = libnet_name2addr4(libnet,
optarg,
LIBNET_RESOLVE))){
@@ -1114,7 +1120,7 @@ int main(int argc, char **argv)
mode = is_mac_addr(parm)?PINGMAC:PINGIP;
} else if (dstip_given) {
mode = PINGIP;
- do_libnet_init(NULL);
+ do_libnet_init(ifname);
parm = strdup(libnet_addr2name4(dstip,0));
if (!parm) {
fprintf(stderr, "arping: out of mem\n");
@@ -1194,9 +1200,10 @@ int main(int argc, char **argv)
*/
if (!ifname) {
if (dont_use_arping_lookupdev) {
- ifname = arping_lookupdev_default(srcip,dstip,ebuf);
+ ifname = arping_lookupdev_default(ifname,
+ srcip,dstip,ebuf);
} else {
- ifname = arping_lookupdev(srcip,dstip,ebuf);
+ ifname = arping_lookupdev(ifname,srcip,dstip,ebuf);
}
if (!ifname) {
fprintf(stderr, "arping: arping_lookupdev(): %s\n",
diff --git a/arping.8 b/arping.8
index dae27ff..122950f 100644
--- a/arping.8
+++ b/arping.8
@@ -1,12 +1,13 @@
-.TH "arping" "8" "21th June, 2003" "arping" ""
+.TH "arping" "8" "21th June, 2003" "arping" ""
+
.PP
-.SH "NAME"
+.SH "NAME"
arping \- sends arp and/or ip pings to a given host
.PP
-.SH "SYNOPSIS"
+.SH "SYNOPSIS"
\fBarping\fP [-abhpqrRd0uv] [-S \fIhost/ip\fP] [-T \fIhost/ip\fP] [-s \fIMAC\fP] [-t \fIMAC\fP] [-c \fIcount\fP] [-i \fIinterface\fP] [ -w \fIus\fP ] <\fIhost\fP | -B>
.PP
-.SH "DESCRIPTION"
+.SH "DESCRIPTION"
The \fIarping\fP utility sends \fBARP\fP and/or \fBICMP\fP requests to the specified \fIhost\fP and displays the replies\&. The \fIhost\fP may be specified by its \fBhostname\fP, its \fBIP\fP address, or its \fBMAC\fP address\&.
.PP
One request is sent each second\&.
@@ -31,81 +32,85 @@ This is not just an issue with arping, it is with normal ping also
since arping packets (when pinging IP) doesn\&'t traverse the IP stack when
received and are therefore replied to faster\&.
.PP
-.SH "OPTIONS"
+.SH "OPTIONS"
+
.PP
-.IP
-.IP "-0"
+.IP "-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\&.
-.IP "-a"
+.IP "-a"
Audible ping\&.
-.IP "-A"
+.IP "-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)\&.
-.IP "-b"
+.IP "-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\&.
-.IP "-B"
+.IP "-B"
Use instead of host if you want to address 255\&.255\&.255\&.255\&.
-.IP "-c \fIcount\fP"
+.IP "-c \fIcount\fP"
Only send \fIcount\fP requests\&.
-.IP "-d"
+.IP "-d"
Find duplicate replies\&.
-.IP "-F"
+.IP "-F"
Don\&'t try to be smart about the interface name\&. (even if this
switch is not given, -i overrides smartness\&.
-.IP "-h"
+.IP "-h"
Displays a help message and exits\&.
-.IP "-i \fIinterface\fP"
+.IP "-i \fIinterface\fP"
Use the specified interface\&.
-.IP "-q"
+.IP "-q"
Does not display messages, except error messages\&.
-.IP "-r"
+.IP "-r"
Raw output: only the MAC/IP address is displayed for each reply\&.
-.IP "-R"
+.IP "-R"
Raw output: Like -r but shows "the other one", can be combined with
-r\&.
-.IP "-s \fIMAC\fP"
+.IP "-s \fIMAC\fP"
Set source MAC address\&. You may need to use -p with this\&.
-.IP "-S \fIIP\fP"
+.IP "-S \fIIP\fP"
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\&.
-.IP "-t \fIMAC\fP"
+.IP "-t \fIMAC\fP"
Set target MAC address to use when pinging IP address\&.
-.IP "-T \fIIP\fP"
+.IP "-T \fIIP\fP"
Use -T as target address when pinging MACs that won\&'t
respond to a broadcast ping but perhaps to a directed broadcast\&.
.IP
\fIExample\fP: To check the address of MAC-A, use knowledge of MAC-B and IP-B\&.
.IP
$ arping -S <IP-B> -s <MAC-B> -p <MAC-A>
-.IP "-p"
+.IP "-p"
Turn on promiscious mode on interface, use this if you don\&'t
"own" the MAC address you are using\&.
-.IP "-u"
+.IP "-u"
Show index=received/sent instead of just index=received when
pinging MACs\&.
-.IP "-v"
+.IP "-v"
Verbose output\&. Use twice for more messages\&.
-.IP "-w"
+.IP "-w"
(arping 2\&.x only) Time to wait between pings, in microseconds\&.
+
.PP
-.SH "BUGS"
+.SH "BUGS"
+
.PP
You have to use -B instead of arpinging 255\&.255\&.255\&.255, and -b
instead of -S 255\&.255\&.255\&.255\&. This is libnets fault\&.
.PP
-.SH "SEE ALSO"
+.SH "SEE ALSO"
+
.PP
\fBping(8)\fP, \fBarp(8)\fP, \fBrarp(8)\fP
.PP
-.SH "AUTHOR"
+.SH "AUTHOR"
+
.PP
Arping was written by Thomas Habets <thomas@habets\&.pp\&.se>\&.