diff --git a/libports/lib/mk/libc_resolv.mk b/libports/lib/mk/libc_resolv.mk new file mode 100644 index 0000000000..4985dba6a8 --- /dev/null +++ b/libports/lib/mk/libc_resolv.mk @@ -0,0 +1,9 @@ +LIBS = libc libc-resolv libc-isc libc-nameser libc-net libc-rpc + +SRC_CC = plugin.cc + +vpath %.cc $(REP_DIR)/src/lib/libc_resolv + +include $(REP_DIR)/lib/mk/libc-common.inc + +SHARED_LIB = yes diff --git a/libports/src/lib/libc/patches/getaddrinfo_c.patch b/libports/src/lib/libc/patches/getaddrinfo_c.patch new file mode 100644 index 0000000000..03f64d9ef2 --- /dev/null +++ b/libports/src/lib/libc/patches/getaddrinfo_c.patch @@ -0,0 +1,20 @@ +--- libc/net/getaddrinfo.c.orig ++++ libc/net/getaddrinfo.c +@@ -329,7 +329,7 @@ do { \ + ((x) == (y) || (/*CONSTCOND*/(w) && ((x) == ANY || (y) == ANY))) + + void +-freeaddrinfo(struct addrinfo *ai) ++libc_freeaddrinfo(struct addrinfo *ai) + { + struct addrinfo *next; + +@@ -362,7 +362,7 @@ str2number(const char *p, int *portp) + } + + int +-getaddrinfo(const char *hostname, const char *servname, ++libc_getaddrinfo(const char *hostname, const char *servname, + const struct addrinfo *hints, struct addrinfo **res) + { + struct addrinfo sentinel; diff --git a/libports/src/lib/libc_resolv/README b/libports/src/lib/libc_resolv/README new file mode 100644 index 0000000000..4fb5aa51de --- /dev/null +++ b/libports/src/lib/libc_resolv/README @@ -0,0 +1,6 @@ +This libc plugin uses libc's own resolv facilities to do DNS resolving +etc. pp. It is much more advanced than the functions which lwip has to +offer. + +Its current use is for noux-pkgs only. ``Native'' Genode programs should +use getaddrinfo() provided by lwip for now. diff --git a/libports/src/lib/libc_resolv/plugin.cc b/libports/src/lib/libc_resolv/plugin.cc new file mode 100644 index 0000000000..4e27bc0908 --- /dev/null +++ b/libports/src/lib/libc_resolv/plugin.cc @@ -0,0 +1,94 @@ +/* + * \brief Libc resolv + * \author Josef Soentgen + * \date 2012-07-19 + */ + +/* + * Copyright (C) 2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +/* Genode includes */ +#include +#include + +/* libc plugin includes */ +#include +#include + +/* libc includes */ +#include +#include +#include + + +void *operator new (size_t, void *ptr) { return ptr; } + +extern "C" void libc_freeaddrinfo(struct ::addrinfo *); +extern "C" int libc_getaddrinfo(const char *, const char *, + const struct ::addrinfo *, + struct ::addrinfo **); + +/************ + ** Plugin ** + ************/ + +namespace { + + struct Plugin_context : Libc::Plugin_context { }; + + static inline Plugin_context *context(Libc::File_descriptor *fd) + { + return static_cast(fd->context); + } + + class Plugin : public Libc::Plugin + { + private: + + Plugin_context _context; + + public: + + /** + * Constructor + */ + Plugin() { } + + bool supports_freeaddrinfo(struct ::addrinfo *res) + { + return true; + } + bool supports_getaddrinfo(const char *node, const char *service, + const struct ::addrinfo *hints, + struct ::addrinfo **res) + { + return true; + } + + int getaddrinfo(const char *node, const char *service, + const struct ::addrinfo *hints, + struct ::addrinfo **res) + { + PDBG("libc_resolv getaddrinfo() called"); + return ::libc_getaddrinfo(node, service, hints, res); + } + + void freeaddrinfo(struct ::addrinfo *res) + { + PDBG("libc_resolv freeaddrinfo() called"); + + return ::libc_freeaddrinfo(res); + } + + }; + +} /* unnamed namespace */ + +void __attribute__((constructor)) init_libc_resolv(void) +{ + static Plugin libc_resolv; +}