[netcf-devel] [PATCH 3/3] Don't attempt SIOCGIFADDR/NETMASK on downed interfaces.

Laine Stump laine at laine.org
Tue Sep 29 18:39:05 UTC 2009


Both of these ioctls return an error if the interface is down.
---
 src/dutil.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/dutil.c b/src/dutil.c
index d2090a7..f3f89a5 100644
--- a/src/dutil.c
+++ b/src/dutil.c
@@ -447,6 +447,10 @@ int if_is_active(struct netcf *ncf, const char *intf) {
 unsigned int if_ipv4_address(struct netcf *ncf, const char *intf) {
     struct ifreq ifr;
 
+    if (!if_is_active(ncf, intf)) {
+        /* SIOCGIFADDR fails on a device that is down */
+        return 0;
+        }
     MEMZERO(&ifr, 1);
     strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
     ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
@@ -461,6 +465,10 @@ unsigned int if_ipv4_address(struct netcf *ncf, const char *intf) {
 unsigned int if_ipv4_netmask(struct netcf *ncf, const char *intf) {
     struct ifreq ifr;
 
+    if (!if_is_active(ncf, intf)) {
+        /* SIOCGIFNETMASK fails on a device that is down */
+        return 0;
+        }
     MEMZERO(&ifr, 1);
     strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
     ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
-- 
1.6.2.5



More information about the netcf-devel mailing list