summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.pp.se>2004-02-02 00:37:34 +0000
committerThomas Habets <thomas@habets.pp.se>2004-02-02 00:37:34 +0000
commit9c727cfb33f242b802ea17d160baa6a0fba9d9c9 (patch)
treee0ba0ed2211700200d7befef3174b518199d1261
parent5f137469b5e7913a606968dd841044332d06a0d2 (diff)
downloadarping-9c727cfb33f242b802ea17d160baa6a0fba9d9c9.tar.gz
2.03 == fixes some bugs
-rw-r--r--Makefile81
-rw-r--r--README17
-rw-r--r--arping-2/arping.c46
3 files changed, 111 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 266518d..c527824 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,16 @@
-# $Id: Makefile 984 2003-08-07 20:11:36Z marvin $
+# $Id: Makefile 1063 2004-02-02 00:37:34Z marvin $
TARGETS=arping
+CD=cd
+CP=cp
+TAR=tar
+GPG=gpg
+MAKE=make
+RM=rm
+SUDO=sudo
+
+# This is only for arping1, arping2 has it in the .c, and it should prolly
+# be moved to autoconf
USE_NETIF=0
FINDIF=1
OPENBSD=0
@@ -54,23 +64,23 @@ doc: arping.yodl
yodl2man -o arping.8 arping.yodl
linux-nofindif:
- make USE_NETIF=1 LINUX=1 FINDIF=0 arping1-make
+ $(MAKE) USE_NETIF=1 LINUX=1 FINDIF=0 arping1-make
linux:
- make USE_NETIF=1 LINUX=1 arping1-make
+ $(MAKE) USE_NETIF=1 LINUX=1 arping1-make
freebsd:
- make USE_NETIF=1 FREEBSD=1 arping1-make
+ $(MAKE) USE_NETIF=1 FREEBSD=1 arping1-make
macosx:
- make USE_NETIF=1 MACOSX=1 arping1-make
+ $(MAKE) USE_NETIF=1 MACOSX=1 arping1-make
openbsd:
- make OPENBSD=1 arping1-make
+ $(MAKE) OPENBSD=1 arping1-make
netbsd:
- make openbsd
+ $(MAKE) openbsd
solaris:
- make USE_NETIF=0 SOLARIS=1 arping1-make
+ $(MAKE) USE_NETIF=0 SOLARIS=1 arping1-make
install:
install -c arping /usr/local/bin/arping
@@ -83,10 +93,16 @@ O_arping=arping.o
arping1-make: $(O_arping)
$(CC) $(CFLAGS) -g -o arping $(O_arping) `libnet-config --libs` -lpcap
+SYS=$(shell uname -s)
+ifeq ($(SYS),SunOS)
+EXTRA_LIBS=-lsocket -lnsl
+endif
+
O_arping2=arping-2/arping.c
arping2: arping-2/arping
arping-2/arping: $(O_arping2)
- $(CC) `libnet-config --libs --defines --cflags` -o arping arping-2/arping.c -lnet -lpcap
+# $(CC) `libnet-config --libs --defines --cflags` -o arping arping-2/arping.c -lnet -lpcap
+ $(CC) -o arping arping-2/arping.c -lnet -lpcap $(EXTRA_LIBS)
clean:
rm -f *.o $(TARGETS)
@@ -94,5 +110,52 @@ clean:
distclean: clean
rm -f config{.cache,.h,.log,.status}
+V=$(shell grep version arping-2/arping.c|grep const|sed 's:[a-z =]*::;s:;::')
+DFILE=arping-$(V).tar.gz
+DDIR=arping-$(V)
+dist:
+ ($(CD) ..; \
+ $(CP) -ax arping $(DDIR); \
+ $(RM) -fr $(DDIR)/{.\#*,CVS,.svn,*~} \
+ $(DDIR)/arping-2/{.\#*,CVS,.svn,*~}; \
+ $(MAKE) -C $(DDIR) doc; \
+ $(TAR) cfz $(DFILE) $(DDIR); \
+ $(GPG) -b -a $(DFILE); \
+ )
+test: arping2
+ @echo Testing with destination host $(HOST) and MAC $(MAC)
+
+# Easy ones
+ @$(SUDO) ./arping -c 1 -q $(HOST) || echo fail: arping host
+ @$(SUDO) ./arping -c 1 -q $(shell $(SUDO) ./arping -c 1 -r $(HOST)) \
+ || echo fail: arping mac
+ $(shell $(SUDO) ./arping -c 1 -q -t 00:11:22:33:44:55 $(HOST) \
+ && echo fail: -t switch)
+
+# -A
+ $(shell $(SUDO) ./arping -c 1 -q -A $(HOST) \
+ && echo fail: -A switch)
+ $(shell $(SUDO) ./arping -c 1 -q -A $(MAC) \
+ && echo fail: -A switch)
+
+# Directed pings
+ $(shell $(SUDO) ./arping -c 1 -q -t $(MAC) $(HOST) \
+ || echo fail: -t switch 2)
+ $(shell $(SUDO) ./arping -c 1 -q -T $(HOST) $(MAC) \
+ || echo fail: -T switch)
+ $(shell $(SUDO) ./arping -c 1 -q -A -t $(MAC) $(HOST) \
+ || echo fail: -t switch with -A)
+ $(shell $(SUDO) ./arping -c 1 -q -A -T $(HOST) $(MAC) \
+ || echo fail: -T switch with -A)
+
+# Ok both ways?
+ $(shell [ `$(SUDO) ./arping -c 1 -r $(HOST)` = $(MAC) ] \
+ || echo fail: host to MAC translation weird)
+ $(shell [ `$(SUDO) ./arping -c 1 -R $(HOST)` = \
+ `$(SUDO) ./arping -c 1 -r $(MAC)` ] \
+ || echo fail: host to MAC translation and back weird)
+
+# FIXME: more tests listed in arping.c
+
maintainerclean: distclean
rm -f config{.h.in,ure}
diff --git a/README b/README
index 02ddd43..07fa87e 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-$Id: README 1052 2003-11-14 14:04:24Z marvin $
+$Id: README 1063 2004-02-02 00:37:34Z marvin $
ARP Ping
@@ -69,6 +69,13 @@ A: Arping 2.x will not work with Libnet 1.0.x. This is This is due to
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.
+
+A: On BSD, you'll prolly need to type something like:
+ gmake MAKE=gmake openbsd
+---
+Q: On sparc64, the IP shown in the output is 0.0.0.0.
+
+A: Libnets fault, should be fixed there.
---
Q: After compiling arping without any problem, i test it first with
localhost... but it doesn't respond. Isn't that strange?
@@ -211,14 +218,6 @@ 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.
----
-Q: Say hi to Psychad for me.
-
-A: Will do.
----
Misc
----
diff --git a/arping-2/arping.c b/arping-2/arping.c
index 6b68309..c242240 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 1055 2003-11-28 02:13:40Z marvin $
+ * $Id: arping.c 1063 2004-02-02 00:37:34Z marvin $
*/
/*
* Copyright (C) 2000-2002 Thomas Habets <thomas@habets.pp.se>
@@ -39,6 +39,7 @@
//#include <stdint.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -47,6 +48,11 @@
#include <libnet.h>
#include <pcap.h>
+#if defined(linux)
+#define HAVE_ESIZE_TYPES 1
+#define FINDIF 1
+#endif
+
#ifdef HAVE_NET_BPF_H
#include <net/bpf.h>
#endif
@@ -54,6 +60,10 @@
#ifndef HAVE_ESIZE_TYPES
/*
* let's hope we at least have these
+ * FIXME: bleh, this is not auto-detected, so fix it with os-dependent stuff
+ * like we have above for linux
+ * But this broken thing compiled on my solaris, openbsd and linux-boxes so
+ * it kinda works.
*/
#define u_int8_t uint8_t
#define u_int16_t uint16_t
@@ -68,7 +78,7 @@
#define IP_ALEN 4
#endif
-const float version = 2.02;
+const float version = 2.03;
static libnet_t *libnet = 0;
@@ -100,8 +110,13 @@ volatile int time_to_die = 0;
static void do_libnet_init(const char *ifname)
{
char ebuf[LIBNET_ERRBUF_SIZE];
+ if (verbose > 1) {
+ printf("libnet_init(%s)\n", ifname);
+ }
if (libnet) {
- return;
+ /* prolly going to switch interface from temp to real */
+ libnet_destroy(libnet);
+ libnet = 0;
}
if (getuid() && geteuid()) {
fprintf(stderr, "arping: must run as root\n");
@@ -109,7 +124,7 @@ static void do_libnet_init(const char *ifname)
}
if (!(libnet = libnet_init(LIBNET_LINK,
- ifname,
+ (char*)ifname,
ebuf))) {
fprintf(stderr, "arping: libnet_init(): %s\n", ebuf);
exit(1);
@@ -119,32 +134,27 @@ static void do_libnet_init(const char *ifname)
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;
+ return pcap_lookupdev(ebuf);
}
#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];
+ 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);
+ libnet_addr2name4_r(dstip,0,buf2);
+ libnet_addr2name4_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;
}
@@ -670,7 +680,7 @@ int main(int argc, char **argv)
int srcip_given = 0;
int srcmac_given = 0;
int dstip_given = 0;
- char *ifname = NULL;
+ const char *ifname = NULL;
char *parm;
int c;
unsigned int maxcount = -1;
@@ -923,9 +933,15 @@ int main(int argc, char **argv)
}
/*
+ * Init libnet again, because we now know the interface name.
+ * We should know it by know at least
+ */
+ do_libnet_init(ifname);
+
+ /*
* pcap init
*/
- if (!(pcap = pcap_open_live(ifname, 100, promisc, 10, ebuf))) {
+ if (!(pcap = pcap_open_live((char*)ifname, 100, promisc, 10, ebuf))) {
fprintf(stderr, "arping: pcap_open_live(): %s\n",ebuf);
exit(1);
}