summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.pp.se>2003-11-14 14:04:24 +0000
committerThomas Habets <thomas@habets.pp.se>2003-11-14 14:04:24 +0000
commitd2a9682ead71a70d4d34c224d66f9b3f78154b9e (patch)
treec8451cb3b07030721db064b246d8909136587820
parenta4dcdaf6aa81579ea7b4df0872b982cd0db1ec96 (diff)
downloadarping-d2a9682ead71a70d4d34c224d66f9b3f78154b9e.tar.gz
.
-rw-r--r--README12
-rw-r--r--arping-2/arping.c70
2 files changed, 55 insertions, 27 deletions
diff --git a/README b/README
index 509ca0a..02ddd43 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-$Id: README 984 2003-08-07 20:11:36Z marvin $
+$Id: README 1052 2003-11-14 14:04:24Z marvin $
ARP Ping
@@ -34,9 +34,8 @@ oops).
Compiling
---------
-Type 'make linux' to compile under Linux and 'make openbsd' to compile under
-openbsd. Follow this pattern for compilation under Solaris and FreeBSD.
-If you have some other OS, try all before mailing me.
+Type 'make to compile. You'll get a message saying that you are compiling
+arping 2.x, and how to compile arping 1.x if you want that.
'make install' will copy arping to /usr/local/bin, and put the manpage where
it belongs.
@@ -54,6 +53,11 @@ FAQ
---
Q: It doesn't compile!
+A: Maybe u_int32_t and co. are not defined. Try uncommenting the line:
+ #include <stdint.h> in arping-2/arping.c. This has been an issue on
+ MacOS X, I think. I don't have access to such a box so it's a bit hard
+ to fix.
+
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.
diff --git a/arping-2/arping.c b/arping-2/arping.c
index 7ba9dc4..ae92da8 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 974 2003-08-03 22:57:59Z marvin $
+ * $Id: arping.c 1052 2003-11-14 14:04:24Z marvin $
*/
/*
* Copyright (C) 2000-2002 Thomas Habets <thomas@habets.pp.se>
@@ -35,6 +35,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+// NOTE: try un-commenting this
+//#include <stdint.h>
#include <sys/time.h>
#include <sys/socket.h>
@@ -66,9 +68,9 @@
#define IP_ALEN 4
#endif
-const float version = 2.01;
+const float version = 2.02;
-static libnet_t *libnet;
+static libnet_t *libnet = 0;
static struct timeval lastpacketsent;
@@ -92,6 +94,28 @@ static char dstmac[ETH_ALEN];
volatile int time_to_die = 0;
+/*
+ *
+ */
+static void do_libnet_init(const char *ifname)
+{
+ char ebuf[LIBNET_ERRBUF_SIZE];
+ if (libnet) {
+ return;
+ }
+ if (getuid() && geteuid()) {
+ fprintf(stderr, "arping: must run as root\n");
+ exit(1);
+ }
+
+ if (!(libnet = libnet_init(LIBNET_LINK,
+ ifname,
+ ebuf))) {
+ fprintf(stderr, "arping: libnet_init(): %s\n", ebuf);
+ exit(1);
+ }
+}
+
const char *arping_lookupdev_default(u_int32_t srcip, u_int32_t dstip,
char *ebuf)
{
@@ -585,6 +609,9 @@ static void ping_recv(pcap_t *pcap,u_int32_t packetwait, pcap_handler func)
if (1 != (ret = pcap_dispatch(pcap, 1,
func,
NULL))) {
+ // rest, so we don't take 100% CPU... mostly
+ // hmm... does usleep() exist everywhere?
+ usleep(10);
#ifndef HAVE_WEIRD_BSD
// weird is normal on bsd :)
if (verbose) {
@@ -636,7 +663,7 @@ static void ping_recv(pcap_t *pcap,u_int32_t packetwait, pcap_handler func)
*/
int main(int argc, char **argv)
{
- char ebuf[LIBNET_ERRBUF_SIZE];
+ char ebuf[LIBNET_ERRBUF_SIZE + PCAP_ERRBUF_SIZE];
char *cp;
/* int nullip = 0;*/
int promisc = 0;
@@ -728,6 +755,7 @@ int main(int argc, char **argv)
break;
}
case 'S': // set source IP, may be null for don't-know
+ do_libnet_init(NULL);
if (-1 == (srcip = libnet_name2addr4(libnet,
optarg,
LIBNET_RESOLVE))){
@@ -764,6 +792,7 @@ int main(int argc, char **argv)
"in MAC ping mode\n");
exit(1);
}
+ do_libnet_init(NULL);
if (-1 == (dstip = libnet_name2addr4(libnet,
optarg,
LIBNET_RESOLVE))){
@@ -785,23 +814,6 @@ int main(int argc, char **argv)
}
}
- if (getuid() && geteuid()) {
- fprintf(stderr, "arping: must run as root\n");
- exit(1);
- }
-
- /*
- * libnet init
- */
- if (!(libnet = libnet_init(LIBNET_LINK,
- ifname,
- ebuf))) {
- fprintf(stderr, "arping: libnet_init(): %s\n", ebuf);
- exit(1);
- }
-
-
-
parm = argv[optind];
/*
@@ -813,14 +825,26 @@ int main(int argc, char **argv)
mode = is_mac_addr(parm)?PINGMAC:PINGIP;
} else if (dstip_given) {
mode = PINGIP;
- parm = strdup(libnet_addr2name4(dstip,
- 0));
+ do_libnet_init(NULL);
+ parm = strdup(libnet_addr2name4(dstip,0));
+ if (!parm) {
+ fprintf(stderr, "arping: out of mem\n");
+ exit(1);
+ }
}
}
+ /*
+ *
+ */
if (mode == NONE) {
usage(1);
}
+
+ /*
+ * libnet init (may be done already for resolving)
+ */
+ do_libnet_init(ifname);
/*
* Make sure dstip and parm like eachother