mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-19 11:16:57 +00:00
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.
This commit is contained in:
parent
34bfb70946
commit
6fcbea000c
9
libports/lib/mk/libc_resolv.mk
Normal file
9
libports/lib/mk/libc_resolv.mk
Normal file
@ -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
|
20
libports/src/lib/libc/patches/getaddrinfo_c.patch
Normal file
20
libports/src/lib/libc/patches/getaddrinfo_c.patch
Normal file
@ -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;
|
6
libports/src/lib/libc_resolv/README
Normal file
6
libports/src/lib/libc_resolv/README
Normal file
@ -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.
|
94
libports/src/lib/libc_resolv/plugin.cc
Normal file
94
libports/src/lib/libc_resolv/plugin.cc
Normal file
@ -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 <base/printf.h>
|
||||
#include <base/env.h>
|
||||
|
||||
/* libc plugin includes */
|
||||
#include <libc-plugin/plugin.h>
|
||||
#include <libc-plugin/fd_alloc.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
|
||||
|
||||
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<Plugin_context *>(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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user