#! /bin/sh /usr/share/dpatch/dpatch-run
## ifstate_exact_check.dpatch by Eduard Bloch <blade@debian.org>
##
## DP: Check the state of the interface with SIOCGIFFLAGS instead of traversing the SIOCGIFCONF output, also checking the link state more exactly (Debian bug #563371)

@DPATCH@
Index: icewm-1.3.7~pre2/src/apppstatus.cc
===================================================================
--- icewm-1.3.7~pre2.orig/src/apppstatus.cc	2010-04-28 21:00:30.000000000 +0200
+++ icewm-1.3.7~pre2/src/apppstatus.cc	2010-04-29 22:11:16.961086255 +0200
@@ -429,19 +429,18 @@
     }
     return false;
 #else
-    char buffer[32 * sizeof(struct ifreq)];
-    struct ifconf ifc;
-    struct ifreq *ifr;
-    long long len;
-
     if (fNetDev == null)
         return false;  
-    
-    int s = socket(PF_INET, SOCK_STREAM, 0);
 
+    int s = socket(PF_INET, SOCK_STREAM, 0);
     if (s == -1)
         return false;
 
+#if BROWSE_SIOCGIFCONF_LIST
+    char buffer[32 * sizeof(struct ifreq)];
+    struct ifconf ifc;
+    struct ifreq *ifr;
+    long long len;
     ifc.ifc_len = sizeof(buffer);
     ifc.ifc_buf = buffer;
     if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
@@ -459,6 +458,14 @@
         ifr++;
     }
 
+#else
+    struct ifreq ifr;
+    fNetDev.copy(ifr.ifr_name, IFNAMSIZ-1);
+    bool bUp = (ioctl(s, SIOCGIFFLAGS, &ifr) >= 0 && (ifr.ifr_flags & IFF_UP));
+    close(s);
+    return bUp;
+#endif
+
     close(s);
     return false;
 #endif
