Add package python-ifconfig
authorHamish Guthrie <hcg@openwrt.org>
Mon, 13 Dec 2010 12:27:11 +0000 (12:27 +0000)
committerHamish Guthrie <hcg@openwrt.org>
Mon, 13 Dec 2010 12:27:11 +0000 (12:27 +0000)
SVN-Revision: 24543

lang/python-ifconfig/Makefile [new file with mode: 0644]
lang/python-ifconfig/patches/001-errorcheck.patch [new file with mode: 0644]
lang/python-ifconfig/patches/002-checkflags-up.patch [new file with mode: 0644]

diff --git a/lang/python-ifconfig/Makefile b/lang/python-ifconfig/Makefile
new file mode 100644 (file)
index 0000000..d16baf2
--- /dev/null
@@ -0,0 +1,48 @@
+#
+# Copyright (C) 2010 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=python-ifconfig
+PKG_VERSION:=0.1
+PKG_RELEASE:=2
+
+PKG_SOURCE:=python-ifconfig-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=http://python-ifconfig.googlecode.com/files/
+PKG_MD5SUM:=6d780d29c1df1acc17195bde7be0e394
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/python-ifconfig-$(PKG_VERSION)
+PKG_BUILD_DEPENDS:=python
+
+include $(INCLUDE_DIR)/package.mk
+$(call include_mk, python-package.mk)
+
+define Package/python-ifconfig
+  SUBMENU:=Python
+  SECTION:=lang
+  CATEGORY:=Languages
+  TITLE:=python-ifconfig
+  URL:=http://code.google.com/p/python-ifconfig/
+  DEPENDS:=+python
+endef
+
+define Package/python-ifconfig/description
+  Display network interface status.
+endef
+
+define Build/Compile
+       $(call Build/Compile/PyMod,,install --prefix="$(PKG_INSTALL_DIR)/usr")
+endef
+
+define Package/python-ifconfig/install
+       $(INSTALL_DIR) $(1)$(PYTHON_PKG_DIR)
+       $(CP) \
+           $(PKG_INSTALL_DIR)$(PYTHON_PKG_DIR)/* \
+           $(1)$(PYTHON_PKG_DIR)
+endef
+
+$(eval $(call BuildPackage,python-ifconfig))
diff --git a/lang/python-ifconfig/patches/001-errorcheck.patch b/lang/python-ifconfig/patches/001-errorcheck.patch
new file mode 100644 (file)
index 0000000..86048f4
--- /dev/null
@@ -0,0 +1,69 @@
+--- a/ifconfig.old     2010-12-10 11:18:19.890041196 +0100
++++ b/ifconfig.c       2010-12-10 11:59:58.170347114 +0100
+@@ -43,6 +43,9 @@
+     char addr[20];
+     char brdaddr[20];
+     char netmask[20];
++    short int flags = 0;
++
++    hwaddr[0] = addr[0] = brdaddr[0] = netmask[0] = 0;
+     if (!PyArg_ParseTuple(args, "s", &itf))
+       return NULL;
+@@ -51,29 +54,35 @@
+     strcpy(ifreq.ifr_name, itf);
+-    /* hardware address */
+-    ioctl(fd, SIOCGIFHWADDR, &ifreq);
+-    hw = ifreq.ifr_hwaddr.sa_data;
+-    sprintf(hwaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
+-          *hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5));
+-
+-    /* address */
+-    ioctl(fd, SIOCGIFADDR, &ifreq);
+-    sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+-    sprintf(addr, "%s", inet_ntoa(sin->sin_addr));
+-
+-    /* broadcast */
+-    ioctl(fd, SIOCGIFBRDADDR, &ifreq);
+-    sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+-    sprintf(brdaddr, "%s", inet_ntoa(sin->sin_addr));
+-
+-    /* netmask */
+-    ioctl(fd, SIOCGIFNETMASK, &ifreq);
+-    sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+-    sprintf(netmask, "%s", inet_ntoa(sin->sin_addr));
++    /* flags */
++    if (ioctl(fd, SIOCGIFFLAGS, &ifreq) == 0) {
++        flags = ifreq.ifr_flags;
++
++        /* hardware address */
++        ioctl(fd, SIOCGIFHWADDR, &ifreq);
++        hw = ifreq.ifr_hwaddr.sa_data;
++        sprintf(hwaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
++              *hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5));
++
++        /* address */
++        ioctl(fd, SIOCGIFADDR, &ifreq);
++        sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
++        sprintf(addr, "%s", inet_ntoa(sin->sin_addr));
++
++        /* broadcast */
++        ioctl(fd, SIOCGIFBRDADDR, &ifreq);
++        sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
++        sprintf(brdaddr, "%s", inet_ntoa(sin->sin_addr));
++
++        /* netmask */
++        ioctl(fd, SIOCGIFNETMASK, &ifreq);
++        sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
++        sprintf(netmask, "%s", inet_ntoa(sin->sin_addr));
++    }
+     close(fd);
+-    return Py_BuildValue("{s:s,s:s,s:s,s:s}",
++    return Py_BuildValue("{s:i,s:s,s:s,s:s,s:s}",
++                         "flags", flags,
+                        "hwaddr", hwaddr,
+                        "addr", addr,
+                        "brdaddr", brdaddr,
diff --git a/lang/python-ifconfig/patches/002-checkflags-up.patch b/lang/python-ifconfig/patches/002-checkflags-up.patch
new file mode 100644 (file)
index 0000000..9f98c9e
--- /dev/null
@@ -0,0 +1,39 @@
+--- a/ifconfig.old     2010-12-10 12:14:12.026329707 +0100
++++ b/ifconfig.c       2010-12-10 12:15:18.374672352 +0100
+@@ -64,20 +64,22 @@
+         sprintf(hwaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
+               *hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5));
+-        /* address */
+-        ioctl(fd, SIOCGIFADDR, &ifreq);
+-        sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+-        sprintf(addr, "%s", inet_ntoa(sin->sin_addr));
+-
+-        /* broadcast */
+-        ioctl(fd, SIOCGIFBRDADDR, &ifreq);
+-        sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+-        sprintf(brdaddr, "%s", inet_ntoa(sin->sin_addr));
+-
+-        /* netmask */
+-        ioctl(fd, SIOCGIFNETMASK, &ifreq);
+-        sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
+-        sprintf(netmask, "%s", inet_ntoa(sin->sin_addr));
++        if (flags & IFF_UP) {
++            /* address */
++            ioctl(fd, SIOCGIFADDR, &ifreq);
++            sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
++            sprintf(addr, "%s", inet_ntoa(sin->sin_addr));
++
++            /* broadcast */
++            ioctl(fd, SIOCGIFBRDADDR, &ifreq);
++            sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
++            sprintf(brdaddr, "%s", inet_ntoa(sin->sin_addr));
++
++            /* netmask */
++            ioctl(fd, SIOCGIFNETMASK, &ifreq);
++            sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
++            sprintf(netmask, "%s", inet_ntoa(sin->sin_addr));
++        }
+     }
+     close(fd);