Move ifaddrs to glibc (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Wed, 20 Apr 2016 23:37:26 +0000 (16:37 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Wed, 20 Apr 2016 23:37:26 +0000 (16:37 -0700)
Note that the file is ifaddrs.c in glibc, as compared to ifaddr.c.  The
sysdep has to match exactly what glibc expects.

We also need the libc_hidden_def for some reason.  Basically whatever
glibc does in other versions of ifaddrs.c needs to be done in our.

Rebuild glibc.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/ifaddrs.c [new file with mode: 0644]
user/iplib/ifaddr.c [deleted file]

diff --git a/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/ifaddrs.c b/tools/compilers/gcc-glibc/glibc-2.19-akaros/sysdeps/akaros/ifaddrs.c
new file mode 100644 (file)
index 0000000..dfc7a99
--- /dev/null
@@ -0,0 +1,92 @@
+#define _LARGEFILE64_SOURCE /* needed to use lseek64 */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <parlib/arch/arch.h>
+#include <unistd.h>
+#include <errno.h>
+#include <dirent.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dirent.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <ifaddrs.h>
+#include <ros/syscall.h>
+#include <ros/fs.h>
+
+int getifaddrs(struct ifaddrs **ifap)
+{
+       DIR *net;
+       struct dirent *d;
+       int addr;
+       /* 6 is known everywhere, defined nowhere. So is 6 * 2 */
+       char etheraddr[12];
+       struct ifaddrs *ifa = NULL;
+       uint8_t *v;
+       int i;
+
+       *ifap = NULL;
+
+       net = opendir("/net");
+       if (net == NULL) {
+               fprintf(stderr, "/net: %r");
+               return -1;
+       }
+
+       for (d = readdir(net); d; d = readdir(net)) {
+               /*
+                * For now we only do ethernet MACs.  It's easy to
+                * change later: just get rid of the following 2
+                * lines.
+                */
+               if (strncmp(d->d_name, "ether", 5))
+                       continue;
+               sprintf(etheraddr, "/net/%s/addr", d->d_name);
+               addr = open(etheraddr, O_RDONLY);
+               if (addr < 0)
+                       continue;
+               if (read(addr, etheraddr, sizeof(etheraddr)) < sizeof(etheraddr)) {
+                       fprintf(stderr, "Read addr from %s: %r", d->d_name);
+                       close(addr);
+                       continue;
+               }
+               /* getifaddrds is a stupid design as it only admits of
+                * one address per interface.  Don't even bother
+                * filling in ifa_{addr,netmask}. They're allowed to
+                * be NULL.  Broadaddr need be set IFF a bit is set
+                * in the flags field. We don't set either one.
+                */
+               if (!ifa) {
+                       ifa = calloc(sizeof(*ifa), 1);
+                       *ifap = ifa;
+               } else {
+                       ifa->ifa_next = calloc(sizeof(*ifa), 1);
+                       ifa = ifa->ifa_next;
+               }
+               ifa->ifa_name = strdup(d->d_name);
+               /*
+                * 6 is known everywhere, not defined anywhere.  oh
+                * yeah, another binary thing. 1976 all over again.
+                */
+               v = malloc(6);
+               for (i = 0; i < 6; i++)
+                       sscanf(&etheraddr[i*2], "%02x", &v[i]);
+               ifa->ifa_data = v;
+               close(addr);
+       }
+       closedir(net);
+       return 0;
+}
+libc_hidden_def(getifaddrs)
+
+void freeifaddrs(struct ifaddrs *ifa)
+{
+       for (; ifa; ifa = ifa->ifa_next)
+               free(ifa);
+}
+libc_hidden_def(freeifaddrs)
diff --git a/user/iplib/ifaddr.c b/user/iplib/ifaddr.c
deleted file mode 100644 (file)
index f011b83..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-#define _LARGEFILE64_SOURCE /* needed to use lseek64 */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <parlib/arch/arch.h>
-#include <unistd.h>
-#include <errno.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <dirent.h>
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <ifaddrs.h>
-#include <ros/syscall.h>
-#include <ros/fs.h>
-
-int getifaddrs(struct ifaddrs **ifap)
-{
-       DIR *net;
-       struct dirent *d;
-       int addr;
-       /* 6 is known everywhere, defined nowhere. So is 6 * 2 */
-       char etheraddr[12];
-       struct ifaddrs *ifa = NULL;
-       uint8_t *v;
-       int i;
-
-       *ifap = NULL;
-
-       net = opendir("/net");
-       if (net == NULL) {
-               fprintf(stderr, "/net: %r");
-               return -1;
-       }
-
-       for (d = readdir(net); d; d = readdir(net)) {
-               /*
-                * For now we only do ethernet MACs.  It's easy to
-                * change later: just get rid of the following 2
-                * lines.
-                */
-               if (strncmp(d->d_name, "ether", 5))
-                       continue;
-               sprintf(etheraddr, "/net/%s/addr", d->d_name);
-               addr = open(etheraddr, O_RDONLY);
-               if (addr < 0)
-                       continue;
-               if (read(addr, etheraddr, sizeof(etheraddr)) < sizeof(etheraddr)) {
-                       fprintf(stderr, "Read addr from %s: %r", d->d_name);
-                       close(addr);
-                       continue;
-               }
-               /* getifaddrds is a stupid design as it only admits of
-                * one address per interface.  Don't even bother
-                * filling in ifa_{addr,netmask}. They're allowed to
-                * be NULL.  Broadaddr need be set IFF a bit is set
-                * in the flags field. We don't set either one.
-                */
-               if (!ifa) {
-                       ifa = calloc(sizeof(*ifa), 1);
-                       *ifap = ifa;
-               } else {
-                       ifa->ifa_next = calloc(sizeof(*ifa), 1);
-                       ifa = ifa->ifa_next;
-               }
-               ifa->ifa_name = strdup(d->d_name);
-               /*
-                * 6 is known everywhere, not defined anywhere.  oh
-                * yeah, another binary thing. 1976 all over again.
-                */
-               v = malloc(6);
-               for (i = 0; i < 6; i++)
-                       sscanf(&etheraddr[i*2], "%02x", &v[i]);
-               ifa->ifa_data = v;
-               close(addr);
-       }
-       closedir(net);
-       return 0;
-}
-
-void freeifaddrs(struct ifaddrs *ifa)
-{
-       for (; ifa; ifa = ifa->ifa_next)
-               free(ifa);
-}