fixes #752397 - arping uses eth0 as default interface

This commit is contained in:
Jiri Skala 2011-11-10 10:22:22 +01:00
parent 1d48d0662b
commit 10798d348d
2 changed files with 97 additions and 1 deletions

View File

@ -0,0 +1,91 @@
diff -up iputils-s20101006/arping.c.eth iputils-s20101006/arping.c
--- iputils-s20101006/arping.c.eth 2011-11-10 09:06:08.101748109 +0100
+++ iputils-s20101006/arping.c 2011-11-10 09:34:09.880501394 +0100
@@ -37,7 +37,7 @@
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;
@@ -66,6 +66,11 @@ int received, brd_recv, req_recv;
#define SYSFS_PATH_LEN 256
#define SOCKADDR_LEN (2 * sizeof(struct sockaddr_ll))
+#define PREF_ETH "eth"
+#define PREF_EM "em"
+
+static char *dev_file = "/proc/self/net/dev";
+
#define MS_TDIFF(tv1,tv2) ( ((tv1).tv_sec-(tv2).tv_sec)*1000 + \
((tv1).tv_usec-(tv2).tv_usec)/1000 )
@@ -377,6 +382,46 @@ char * read_sysfs_broadcast(char *brdcas
return brdcast;
}
+/*
+ * get_first_ethernet - return the name of the first ethernet-style
+ * interface on this system.
+ */
+char * get_first_ethernet(void)
+{
+ FILE *f;
+ char buf[255], *dv, *smc;
+ char pci[16];
+
+ 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;
+}
+
int
main(int argc, char **argv)
{
@@ -403,6 +448,8 @@ main(int argc, char **argv)
exit(1);
}
+ device = get_first_ethernet();
+
while ((ch = getopt(argc, argv, "h?bfDUAqc:w:s:I:V")) != EOF) {
switch(ch) {
case 'b':
@@ -429,6 +476,10 @@ main(int argc, char **argv)
timeout = atoi(optarg);
break;
case 'I':
+ if (device) {
+ free(device);
+ device = NULL;
+ }
device = strdup(optarg);
break;
case 'f':

View File

@ -1,7 +1,7 @@
Summary: Network monitoring tools including ping Summary: Network monitoring tools including ping
Name: iputils Name: iputils
Version: 20101006 Version: 20101006
Release: 10%{?dist} Release: 11%{?dist}
License: BSD License: BSD
URL: http://www.skbuff.net/iputils URL: http://www.skbuff.net/iputils
Group: System Environment/Daemons Group: System Environment/Daemons
@ -29,6 +29,7 @@ Patch13: iputils-20100418-flowlabel.patch
Patch14: iputils-20101006-drop_caps.patch Patch14: iputils-20101006-drop_caps.patch
Patch15: iputils-20101006-unused.patch Patch15: iputils-20101006-unused.patch
Patch16: iputils-20101006-man.patch Patch16: iputils-20101006-man.patch
Patch17: iputils-20101006-eth.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: docbook-utils perl-SGMLSpm BuildRequires: docbook-utils perl-SGMLSpm
@ -78,6 +79,7 @@ The iputils-sysvinit contains SysV initscritps support.
%patch14 -p1 -b .drop_caps %patch14 -p1 -b .drop_caps
%patch15 -p1 -b .unused %patch15 -p1 -b .unused
%patch16 -p1 -b .man %patch16 -p1 -b .man
%patch17 -p1 -b .eth
%build %build
%ifarch s390 s390x %ifarch s390 s390x
@ -182,6 +184,9 @@ rm -rf ${RPM_BUILD_ROOT}
%{_sysconfdir}/rc.d/init.d/rdisc %{_sysconfdir}/rc.d/init.d/rdisc
%changelog %changelog
* Thu Nov 10 2011 Jiri Skala <jskala@redhat.com> - 20101006-11
- fixes #752397 - arping uses eth0 as default interface
* Mon Aug 01 2011 Jiri Skala <jskala@redhat.com> - 20101006-10 * Mon Aug 01 2011 Jiri Skala <jskala@redhat.com> - 20101006-10
- rebuild for libcap - rebuild for libcap