From 6fcbea000c436918f456fa258746e8d29512b905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Thu, 19 Jul 2012 17:14:35 +0200 Subject: [PATCH] libports: add libc_resolv libc_resolv is a {free,get}addrinfo() plugin, mainly for use with NOUX. We prefix the original libc functions to with 'libc_' so there is no symbol conflict with file_operations.cc. --- libports/lib/mk/libc_resolv.mk | 9 ++ .../src/lib/libc/patches/getaddrinfo_c.patch | 20 ++++ libports/src/lib/libc_resolv/README | 6 ++ libports/src/lib/libc_resolv/plugin.cc | 94 +++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 libports/lib/mk/libc_resolv.mk create mode 100644 libports/src/lib/libc/patches/getaddrinfo_c.patch create mode 100644 libports/src/lib/libc_resolv/README create mode 100644 libports/src/lib/libc_resolv/plugin.cc diff --git a/libports/lib/mk/libc_resolv.mk b/libports/lib/mk/libc_resolv.mk new file mode 100644 index 000000000..4985dba6a --- /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 000000000..03f64d9ef --- /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 000000000..4fb5aa51d --- /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 000000000..4e27bc090 --- /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; +}