genode/repos/libports/src/lib/libc_resolv/plugin.cc

109 lines
2.4 KiB
C++

/*
* \brief Libc resolv
* \author Josef Soentgen
* \date 2012-07-19
*/
/*
* Copyright (C) 2012-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
/* 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>
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)
{
return ::libc_getaddrinfo(node, service, hints, res);
}
void freeaddrinfo(struct ::addrinfo *res)
{
return ::libc_freeaddrinfo(res);
}
::ssize_t getdirentries(Libc::File_descriptor *fd, char *buf, ::size_t nbytes,
::off_t *basep)
{
Genode::error(__FILE__, ":", __LINE__, " ", __func__, "not implemented");
return 0UL;
}
void *mmap(void *addr, ::size_t length, int prot, int flags,
Libc::File_descriptor *, ::off_t offset)
{
Genode::error(__FILE__, ":", __LINE__, " ", __func__, "not implemented");
return nullptr;
}
int msync(void *addr, ::size_t len, int flags)
{
Genode::error(__FILE__, ":", __LINE__, " ", __func__, "not implemented");
return 0;
}
};
} /* unnamed namespace */
void __attribute__((constructor)) init_libc_resolv(void)
{
static Plugin libc_resolv;
}