diff options
author | Kuba Sejdak <jakub.sejdak@phoesys.com> | 2016-06-24 14:14:53 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2016-06-27 13:23:35 +0200 |
commit | 3302072436f3b06a2d85f26d22c6c4727bc1d9b3 (patch) | |
tree | c3ed8a267d2fc7da3ca1d5b380ea9a802439ae56 | |
parent | 75c98c35c304421c717b6e30a9fc366ecd6eb965 (diff) | |
download | cygnal-3302072436f3b06a2d85f26d22c6c4727bc1d9b3.tar.gz cygnal-3302072436f3b06a2d85f26d22c6c4727bc1d9b3.tar.bz2 cygnal-3302072436f3b06a2d85f26d22c6c4727bc1d9b3.zip |
Add dummy implementation of getentropy(), if_nametoindex() and if_indextoname() functions.
-rw-r--r-- | newlib/libc/sys/phoenix/Makefile.am | 6 | ||||
-rw-r--r-- | newlib/libc/sys/phoenix/Makefile.in | 41 | ||||
-rw-r--r-- | newlib/libc/sys/phoenix/getentropy.c | 48 | ||||
-rw-r--r-- | newlib/libc/sys/phoenix/net/nametoindex.c | 50 |
4 files changed, 134 insertions, 11 deletions
diff --git a/newlib/libc/sys/phoenix/Makefile.am b/newlib/libc/sys/phoenix/Makefile.am index e57a3343c..e83be5303 100644 --- a/newlib/libc/sys/phoenix/Makefile.am +++ b/newlib/libc/sys/phoenix/Makefile.am @@ -31,6 +31,7 @@ SOURCES = \ net/inet_ntoa.c \ net/inet_ntop.c \ net/inet_pton.c \ + net/nametoindex.c \ net/network.c \ alarm.c \ chmod.c \ @@ -42,6 +43,7 @@ SOURCES = \ fcntl.c \ fork.c \ fs.c \ + getentropy.c \ getmntent.c \ getpagesize.c \ groups.c \ @@ -130,4 +132,8 @@ install-data-local: $(mkinstalldirs) $(DESTDIR)$(tooldir)/include/netinet6; \ for i in $(srcdir)/include/netinet6/*.h; do \ $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/netinet6/`basename $$i`; \ + done; \ + $(mkinstalldirs) $(DESTDIR)$(tooldir)/include/netpacket; \ + for i in $(srcdir)/include/netpacket/*.h; do \ + $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/netpacket/`basename $$i`; \ done; diff --git a/newlib/libc/sys/phoenix/Makefile.in b/newlib/libc/sys/phoenix/Makefile.in index bcd63885b..18e76fa0a 100644 --- a/newlib/libc/sys/phoenix/Makefile.in +++ b/newlib/libc/sys/phoenix/Makefile.in @@ -81,17 +81,18 @@ am__objects_1 = lib_a-domainname.$(OBJEXT) \ lib_a-inet_net_pton.$(OBJEXT) lib_a-inet_netof.$(OBJEXT) \ lib_a-inet_network.$(OBJEXT) lib_a-inet_ntoa.$(OBJEXT) \ lib_a-inet_ntop.$(OBJEXT) lib_a-inet_pton.$(OBJEXT) \ - lib_a-network.$(OBJEXT) lib_a-alarm.$(OBJEXT) \ - lib_a-chmod.$(OBJEXT) lib_a-chown.$(OBJEXT) \ - lib_a-clocks.$(OBJEXT) lib_a-dup.$(OBJEXT) \ - lib_a-endmntent.$(OBJEXT) lib_a-exec.$(OBJEXT) \ - lib_a-fcntl.$(OBJEXT) lib_a-fork.$(OBJEXT) lib_a-fs.$(OBJEXT) \ - lib_a-getmntent.$(OBJEXT) lib_a-getpagesize.$(OBJEXT) \ - lib_a-groups.$(OBJEXT) lib_a-ids.$(OBJEXT) lib_a-io.$(OBJEXT) \ - lib_a-ioctl.$(OBJEXT) lib_a-mmap.$(OBJEXT) \ - lib_a-mount.$(OBJEXT) lib_a-nanosleep.$(OBJEXT) \ - lib_a-phoenix.$(OBJEXT) lib_a-pid.$(OBJEXT) \ - lib_a-pipe.$(OBJEXT) lib_a-poll.$(OBJEXT) \ + lib_a-nametoindex.$(OBJEXT) lib_a-network.$(OBJEXT) \ + lib_a-alarm.$(OBJEXT) lib_a-chmod.$(OBJEXT) \ + lib_a-chown.$(OBJEXT) lib_a-clocks.$(OBJEXT) \ + lib_a-dup.$(OBJEXT) lib_a-endmntent.$(OBJEXT) \ + lib_a-exec.$(OBJEXT) lib_a-fcntl.$(OBJEXT) \ + lib_a-fork.$(OBJEXT) lib_a-fs.$(OBJEXT) \ + lib_a-getentropy.$(OBJEXT) lib_a-getmntent.$(OBJEXT) \ + lib_a-getpagesize.$(OBJEXT) lib_a-groups.$(OBJEXT) \ + lib_a-ids.$(OBJEXT) lib_a-io.$(OBJEXT) lib_a-ioctl.$(OBJEXT) \ + lib_a-mmap.$(OBJEXT) lib_a-mount.$(OBJEXT) \ + lib_a-nanosleep.$(OBJEXT) lib_a-phoenix.$(OBJEXT) \ + lib_a-pid.$(OBJEXT) lib_a-pipe.$(OBJEXT) lib_a-poll.$(OBJEXT) \ lib_a-realpath.$(OBJEXT) lib_a-reboot.$(OBJEXT) \ lib_a-resource.$(OBJEXT) lib_a-sbrk.$(OBJEXT) \ lib_a-sched.$(OBJEXT) lib_a-select.$(OBJEXT) \ @@ -266,6 +267,7 @@ SOURCES = \ net/inet_ntoa.c \ net/inet_ntop.c \ net/inet_pton.c \ + net/nametoindex.c \ net/network.c \ alarm.c \ chmod.c \ @@ -277,6 +279,7 @@ SOURCES = \ fcntl.c \ fork.c \ fs.c \ + getentropy.c \ getmntent.c \ getpagesize.c \ groups.c \ @@ -506,6 +509,12 @@ lib_a-inet_pton.o: net/inet_pton.c lib_a-inet_pton.obj: net/inet_pton.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-inet_pton.obj `if test -f 'net/inet_pton.c'; then $(CYGPATH_W) 'net/inet_pton.c'; else $(CYGPATH_W) '$(srcdir)/net/inet_pton.c'; fi` +lib_a-nametoindex.o: net/nametoindex.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nametoindex.o `test -f 'net/nametoindex.c' || echo '$(srcdir)/'`net/nametoindex.c + +lib_a-nametoindex.obj: net/nametoindex.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-nametoindex.obj `if test -f 'net/nametoindex.c'; then $(CYGPATH_W) 'net/nametoindex.c'; else $(CYGPATH_W) '$(srcdir)/net/nametoindex.c'; fi` + lib_a-network.o: net/network.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-network.o `test -f 'net/network.c' || echo '$(srcdir)/'`net/network.c @@ -572,6 +581,12 @@ lib_a-fs.o: fs.c lib_a-fs.obj: fs.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fs.obj `if test -f 'fs.c'; then $(CYGPATH_W) 'fs.c'; else $(CYGPATH_W) '$(srcdir)/fs.c'; fi` +lib_a-getentropy.o: getentropy.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getentropy.o `test -f 'getentropy.c' || echo '$(srcdir)/'`getentropy.c + +lib_a-getentropy.obj: getentropy.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getentropy.obj `if test -f 'getentropy.c'; then $(CYGPATH_W) 'getentropy.c'; else $(CYGPATH_W) '$(srcdir)/getentropy.c'; fi` + lib_a-getmntent.o: getmntent.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getmntent.o `test -f 'getmntent.c' || echo '$(srcdir)/'`getmntent.c @@ -1087,6 +1102,10 @@ install-data-local: $(mkinstalldirs) $(DESTDIR)$(tooldir)/include/netinet6; \ for i in $(srcdir)/include/netinet6/*.h; do \ $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/netinet6/`basename $$i`; \ + done; \ + $(mkinstalldirs) $(DESTDIR)$(tooldir)/include/netpacket; \ + for i in $(srcdir)/include/netpacket/*.h; do \ + $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/netpacket/`basename $$i`; \ done; # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/newlib/libc/sys/phoenix/getentropy.c b/newlib/libc/sys/phoenix/getentropy.c new file mode 100644 index 000000000..097fb90ee --- /dev/null +++ b/newlib/libc/sys/phoenix/getentropy.c @@ -0,0 +1,48 @@ +/* Copyright (c) 2016 Phoenix Systems + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE.*/ + +#include <errno.h> +#include <fcntl.h> +#include <sys/types.h> +#include <unistd.h> + +#define DEV_RANDOM "/dev/random" +#define MAX_ENTROPY 256 + +int getentropy(void *buf, size_t buflen) +{ + if (buflen > MAX_ENTROPY) { + errno = -EIO; + return -1; + } + + int ret = -1; + int fd = open(DEV_RANDOM, O_RDONLY); + if (fd >= 0) { + ret = read(fd, buf, buflen); + close(fd); + } + + return (ret > 0) ? 0 : -1; +} diff --git a/newlib/libc/sys/phoenix/net/nametoindex.c b/newlib/libc/sys/phoenix/net/nametoindex.c new file mode 100644 index 000000000..b11b10f5f --- /dev/null +++ b/newlib/libc/sys/phoenix/net/nametoindex.c @@ -0,0 +1,50 @@ +/* Copyright (c) 2016 Phoenix Systems + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE.*/ + +#include "syscall.h" + +#include <errno.h> +#include <stdio.h> +#include <string.h> + +unsigned int if_nametoindex(const char *ifname) +{ + if (strcmp(ifname, "eth0") != 0) { + errno = EINVAL; + return 0; + } + + return 1; +} + +char *if_indextoname(unsigned int ifindex, char *ifname) +{ + if (ifindex != 1) { + errno = ENXIO; + return NULL; + } + + strcpy(ifname, "eth0"); + return ifname; +} |