[packages/python-ifconfig] Add package python-ifconfig

git-svn-id: svn://svn.openwrt.org/openwrt/packages@24543 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
hcg 2010-12-13 12:27:11 +00:00
parent 74cf38451b
commit a266acc54c
3 changed files with 156 additions and 0 deletions

View File

@ -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))

View File

@ -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,

View File

@ -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);