Blame SOURCES/python-ethtool-0.6-return-ipv6-only-interface-names.patch

1c5055
--- a/python-ethtool/ethtool.c.orig	2013-08-07 10:37:37.378764077 +0200
1c5055
+++ b/python-ethtool/ethtool.c	2013-08-07 10:39:27.111760146 +0200
1c5055
@@ -26,6 +26,7 @@
1c5055
 #include <sys/socket.h>
1c5055
 #include <sys/ioctl.h>
1c5055
 #include <sys/types.h>
1c5055
+#include <ifaddrs.h>
1c5055
 
1c5055
 #include "etherinfo_struct.h"
1c5055
 #include "etherinfo_obj.h"
1c5055
@@ -54,55 +55,24 @@
1c5055
 static PyObject *get_active_devices(PyObject *self __unused, PyObject *args __unused)
1c5055
 {
1c5055
 	PyObject *list;
1c5055
-	int numreqs = 30;
1c5055
-	struct ifconf ifc;
1c5055
-	struct ifreq *ifr;
1c5055
-	int n;
1c5055
+	struct ifaddrs *ifaddr, *ifa;
1c5055
 
1c5055
-	/* SIOCGIFCONF currently seems to only work properly on AF_INET sockets
1c5055
-	   (as of 2.1.128) */
1c5055
-	/* Open control socket. */
1c5055
-	int skfd = socket(AF_INET, SOCK_DGRAM, 0);
1c5055
-
1c5055
-	if (skfd < 0) {
1c5055
+	if (getifaddrs(&ifaddr) == -1) {
1c5055
 		PyErr_SetString(PyExc_OSError, strerror(errno));
1c5055
 		return NULL;
1c5055
 	}
1c5055
 
1c5055
-	ifc.ifc_buf = NULL;
1c5055
-	for (;;) {
1c5055
-		ifc.ifc_len = sizeof(struct ifreq) * numreqs;
1c5055
-		ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len);
1c5055
-
1c5055
-		if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
1c5055
-			PyErr_SetString(PyExc_OSError, strerror(errno));
1c5055
-			free(ifc.ifc_buf);
1c5055
-			close(skfd);
1c5055
-			return NULL;
1c5055
-		}
1c5055
-
1c5055
-		if (ifc.ifc_len == (int)sizeof(struct ifreq) * numreqs) {
1c5055
-			/* assume it overflowed and try again */
1c5055
-			numreqs += 10;
1c5055
-			continue;
1c5055
-		}
1c5055
-		break;
1c5055
-	}
1c5055
-
1c5055
 	list = PyList_New(0);
1c5055
-	ifr = ifc.ifc_req;
1c5055
-	for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) {
1c5055
-		if (!(ioctl(skfd, SIOCGIFFLAGS, ifr) < 0))
1c5055
-			if (ifr->ifr_flags & IFF_UP) {
1c5055
-				PyObject *str = PyString_FromString(ifr->ifr_name);
1c5055
-				PyList_Append(list, str);
1c5055
-				Py_DECREF(str);
1c5055
-			}
1c5055
-			ifr++;
1c5055
+	for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
1c5055
+		PyObject *str = PyString_FromString(ifa->ifa_name);
1c5055
+		/* names are not unique (listed for both ipv4 and ipv6) */
1c5055
+		if (!PySequence_Contains(list, str) && (ifa->ifa_flags & (IFF_UP))) {
1c5055
+			PyList_Append(list, str);
1c5055
+		}
1c5055
+	Py_DECREF(str);
1c5055
 	}
1c5055
 
1c5055
-	free(ifc.ifc_buf);
1c5055
-	close(skfd);
1c5055
+	freeifaddrs(ifaddr);
1c5055
 
1c5055
 	return list;
1c5055
 }