2012-11-13 12:01:31 +00:00
|
|
|
--- iputils-s20121112/arping.c.orig 2012-11-13 12:12:51.000000000 +0100
|
|
|
|
+++ iputils-s20121112/arping.c 2012-11-13 12:15:11.514261164 +0100
|
|
|
|
@@ -50,7 +50,7 @@
|
2011-11-10 09:22:22 +00:00
|
|
|
static void usage(void) __attribute__((noreturn));
|
|
|
|
|
|
|
|
int quit_on_reply=0;
|
|
|
|
-char *device="eth0";
|
|
|
|
+char *device=NULL;
|
|
|
|
int ifindex;
|
|
|
|
char *source;
|
|
|
|
struct in_addr src, dst;
|
2012-11-13 12:01:31 +00:00
|
|
|
@@ -71,6 +71,10 @@ struct timeval start, last;
|
|
|
|
int sent, brd_sent;
|
|
|
|
int received, brd_recv, req_recv;
|
2011-11-10 09:22:22 +00:00
|
|
|
|
2012-11-13 12:01:31 +00:00
|
|
|
+#define PREF_ETH "eth"
|
|
|
|
+#define PREF_EM "em"
|
2011-11-10 09:22:22 +00:00
|
|
|
+static char *dev_file = "/proc/self/net/dev";
|
|
|
|
+
|
2012-11-13 12:01:31 +00:00
|
|
|
#ifndef CAPABILITIES
|
|
|
|
static uid_t euid;
|
|
|
|
#endif
|
|
|
|
@@ -524,6 +528,46 @@ static void set_device_broadcast(char *d
|
|
|
|
return;
|
2011-11-10 09:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * get_first_ethernet - return the name of the first ethernet-style
|
|
|
|
+ * interface on this system.
|
|
|
|
+ */
|
|
|
|
+char * get_first_ethernet(void)
|
|
|
|
+{
|
2012-10-16 11:19:12 +00:00
|
|
|
+ FILE *f;
|
|
|
|
+ char buf[255], *dv, *smc;
|
|
|
|
+ char pci[16];
|
2011-11-10 09:22:22 +00:00
|
|
|
+
|
2012-10-16 11:19:12 +00:00
|
|
|
+ memset(pci, 0, sizeof(pci));
|
|
|
|
+ if ((f = fopen(dev_file, "r")) != NULL)
|
|
|
|
+ {
|
|
|
|
+ // go through network dev file
|
|
|
|
+ while (fgets (buf, sizeof(buf), f) != NULL)
|
|
|
|
+ {
|
|
|
|
+ // the line describes interface
|
|
|
|
+ if ((smc = strchr(buf, ':')) != NULL)
|
|
|
|
+ {
|
|
|
|
+ // trim white characters
|
|
|
|
+ for (dv=buf, *smc=0; *dv <= ' '; dv++) ;
|
|
|
|
+ // is "eth" (originial ethernet name) or "em" (ethernet on board)
|
|
|
|
+ if (!strncmp(dv, PREF_ETH, strlen(PREF_ETH)) ||
|
|
|
|
+ !strncmp(dv, PREF_EM, strlen(PREF_EM)))
|
|
|
|
+ {
|
|
|
|
+ return strdup(dv);
|
|
|
|
+ }
|
|
|
|
+ // remember the first pci NIC-card
|
|
|
|
+ if (strlen(pci) == 0 && dv[0] == 'p' && isdigit(dv[1]))
|
|
|
|
+ {
|
|
|
|
+ strcpy(pci, dv);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ fclose(f);
|
|
|
|
+ }
|
|
|
|
+ // return pci NIC-card or nil if no if name
|
|
|
|
+ return strlen(pci) > 0 ? strdup(pci) : 0L;
|
2011-11-10 09:22:22 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2012-11-13 12:01:31 +00:00
|
|
|
@@ -543,6 +587,8 @@ main(int argc, char **argv)
|
|
|
|
|
|
|
|
disable_capability_raw();
|
2011-11-10 09:22:22 +00:00
|
|
|
|
|
|
|
+ device = get_first_ethernet();
|
|
|
|
+
|
|
|
|
while ((ch = getopt(argc, argv, "h?bfDUAqc:w:s:I:V")) != EOF) {
|
|
|
|
switch(ch) {
|
|
|
|
case 'b':
|
2012-11-13 12:01:31 +00:00
|
|
|
@@ -569,6 +615,10 @@ main(int argc, char **argv)
|
2011-11-10 09:22:22 +00:00
|
|
|
timeout = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
+ if (device) {
|
|
|
|
+ free(device);
|
|
|
|
+ device = NULL;
|
|
|
|
+ }
|
|
|
|
device = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|