From 3302072436f3b06a2d85f26d22c6c4727bc1d9b3 Mon Sep 17 00:00:00 2001 From: Kuba Sejdak Date: Fri, 24 Jun 2016 14:14:53 +0200 Subject: [PATCH] Add dummy implementation of getentropy(), if_nametoindex() and if_indextoname() functions. --- newlib/libc/sys/phoenix/Makefile.am | 6 +++ newlib/libc/sys/phoenix/Makefile.in | 41 ++++++++++++++----- newlib/libc/sys/phoenix/getentropy.c | 48 ++++++++++++++++++++++ newlib/libc/sys/phoenix/net/nametoindex.c | 50 +++++++++++++++++++++++ 4 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 newlib/libc/sys/phoenix/getentropy.c create mode 100644 newlib/libc/sys/phoenix/net/nametoindex.c 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 +#include +#include +#include + +#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 +#include +#include + +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; +}