On Fri, 4 Aug 2006 16:11:32 +0200, Richard Braun wrote:
> I tried to build vISDN with uClibc (recent snapshot), and it failed
> because of getifaddrs() missing. It looks like this function comes from
> BSD, and doesn't appear anywhere in POSIX or SUSV3, so it's unlikely
> they'll implement it. Instead, it is suggested to use ioctl() with
> SIOCGIFCONF. Any comment / people wanting to work on this ? :-)

I found some time to do it myself, but I'm facing a bug : the visdn0
interface isn't returned by ioctl() with SIOCGIFCONF... Here is the
patch (against version 0.15.0) :


diff -Nurp visdn-0.15.0.orig/chan_visdn/chan_visdn.c 
visdn-0.15.0/chan_visdn/chan_visdn.c
--- visdn-0.15.0.orig/chan_visdn/chan_visdn.c   2006-06-06 15:20:44.000000000 
+0200
+++ visdn-0.15.0/chan_visdn/chan_visdn.c        2006-08-04 19:24:44.000000000 
+0200
@@ -31,7 +31,11 @@
 #include <linux/rtnetlink.h>
 
 #include <arpa/inet.h>
+
+#ifdef HAVE_GETIFADDRS
 #include <ifaddrs.h>
+#endif
+
 #include <netinet/in.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
diff -Nurp visdn-0.15.0.orig/chan_visdn/intf.c visdn-0.15.0/chan_visdn/intf.c
--- visdn-0.15.0.orig/chan_visdn/intf.c 2006-06-06 15:20:44.000000000 +0200
+++ visdn-0.15.0/chan_visdn/intf.c      2006-08-04 19:24:53.000000000 +0200
@@ -26,7 +26,10 @@
 #include <signal.h>
 #include <ctype.h>
 
+#ifdef HAVE_GETIFADDRS
 #include <ifaddrs.h>
+#endif
+
 #include <netinet/in.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
diff -Nurp visdn-0.15.0.orig/configure.ac visdn-0.15.0/configure.ac
--- visdn-0.15.0.orig/configure.ac      2006-06-06 15:20:59.000000000 +0200
+++ visdn-0.15.0/configure.ac   2006-08-04 19:24:26.000000000 +0200
@@ -42,7 +42,7 @@ AC_FUNC_SELECT_ARGTYPES
 AC_FUNC_SETVBUF_REVERSED
 AC_TYPE_SIGNAL
 AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([gettimeofday memset select socket strcasecmp strchr strdup 
strerror strncasecmp strrchr strstr])
+AC_CHECK_FUNCS([gettimeofday memset select socket strcasecmp strchr strdup 
strerror strncasecmp strrchr strstr getifaddrs])
 
 visdnhwconfdir="$sysconfdir/visdn"
 AC_SUBST(visdnhwconfdir)
diff -Nurp visdn-0.15.0.orig/visdnctl/netdev.c visdn-0.15.0/visdnctl/netdev.c
--- visdn-0.15.0.orig/visdnctl/netdev.c 2006-06-06 15:20:45.000000000 +0200
+++ visdn-0.15.0/visdnctl/netdev.c      2006-08-04 19:24:35.000000000 +0200
@@ -22,7 +22,12 @@
 #include <sys/ioctl.h>
 #include <fcntl.h>
 #include <sys/socket.h>
+
+#ifdef HAVE_GETIFADDRS
 #include <ifaddrs.h>
+#else
+#include <linux/if.h>
+#endif 
 
 #include <linux/sockios.h>
 
@@ -304,6 +309,7 @@ static int show_any()
                return 1;
        }
 
+#ifdef HAVE_GETIFADDRS
        struct ifaddrs *ifaddrs;
        struct ifaddrs *ifaddr;
 
@@ -320,7 +326,7 @@ static int show_any()
 
                if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
                        close(fd);
-                       fprintf(stderr, "ioctl(SIOCSIFHWBROADCAST): %s\n",
+                       fprintf(stderr, "ioctl(SIOCGIFHWADDR): %s\n",
                                strerror(errno));
                        break;
                }
@@ -335,6 +341,63 @@ static int show_any()
                        (ifaddr->ifa_flags & IFF_NOARP) ? "PtP" : "PtMP");
        }
 
+       freeifaddrs(ifaddrs);
+#else /* HAVE_GETIFADDRS */
+       struct ifconf ifc;
+       struct ifreq *ifr, *end;
+
+       ifc.ifc_buf = NULL;
+       ifc.ifc_len = 0;
+
+       if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
+               close(fd);
+               fprintf(stderr, "ioctl(SIOCGIFCONF): %s\n",
+                       strerror(errno));
+               return 1;
+       }
+
+       ifc.ifc_buf = malloc(ifc.ifc_len);
+
+       if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
+               free(ifc.ifc_buf);
+               close(fd);
+               fprintf(stderr, "ioctl(SIOCGIFCONF): %s\n",
+                       strerror(errno));
+               return 1;
+       }
+
+       end = (struct ifreq *)(ifc.ifc_buf + ifc.ifc_len);
+
+       for (ifr = ifc.ifc_req; ifr < end; ifr++) {
+               if (ioctl(fd, SIOCGIFHWADDR, ifr) < 0) {
+                       free(ifc.ifc_buf);
+                       close(fd);
+                       fprintf(stderr, "ioctl(SIOCGIFHWADDR): %s\n",
+                               strerror(errno));
+                       return 1;
+               }
+
+               if (ifr->ifr_hwaddr.sa_family != ARPHRD_LAPD)
+                       continue;
+
+               if (ioctl(fd, SIOCGIFFLAGS, ifr) < 0) {
+                       free(ifc.ifc_buf);
+                       close(fd);
+                       fprintf(stderr, "ioctl(SIOCGIFFLAGS): %s\n",
+                               strerror(errno));
+                       return 1;
+               }
+
+               printf("%s: %s %s %s\n",
+                       ifr->ifr_name,
+                       (ifr->ifr_flags & IFF_UP) ? "UP" : "DOWN",
+                       (ifr->ifr_flags & IFF_ALLMULTI) ? "NT" : "TE",
+                       (ifr->ifr_flags & IFF_NOARP) ? "PtP" : "PtMP");
+       }
+
+       free(ifc.ifc_buf);
+#endif /* HAVE_GETIFADDRS */
+
        close(fd);
 
        return 0;

-- 
Richard Braun
Proformatique - 67 rue Voltaire - 92800 Puteaux
Tel. : 01 41 38 99 60 - Fax. : 01 41 38 99 70
Email : [EMAIL PROTECTED] - http://proformatique.com/

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Visdn-hackers mailing list
[email protected]
https://mailman.uli.it/mailman/listinfo/visdn-hackers

Reply via email to