libvirt_nss.h 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * libvirt_nss: Name Service Switch plugin
 *
 * The aim is to enable users and applications to translate
 * domain names into IP addresses. However, this is currently
 * available only for those domains which gets their IP addresses
 * from a libvirt managed network.
 *
 * Copyright (C) 2016 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see
 * <http://www.gnu.org/licenses/>.
 */

26
#pragma once
27

28
#include <nss.h>
D
Daniel P. Berrangé 已提交
29 30
#include <sys/socket.h>
#include <netinet/in.h>
31
#include <netdb.h>
32

33 34

#if 0
35
# include <errno.h>
36 37 38
# define ERROR(...) \
do { \
    char ebuf[1024]; \
39
    strerror_r(errno, ebuf, sizeof(ebuf)); \
40 41
    fprintf(stderr, "ERROR %s:%d : ", __FUNCTION__, __LINE__); \
    fprintf(stderr, __VA_ARGS__); \
42
    fprintf(stderr, " : %s\n", ebuf); \
43 44 45 46 47 48 49 50 51 52 53 54 55 56
    fprintf(stderr, "\n"); \
} while (0)

# define DEBUG(...) \
do { \
    fprintf(stderr, "DEBUG %s:%d : ", __FUNCTION__, __LINE__); \
    fprintf(stderr, __VA_ARGS__); \
    fprintf(stderr, "\n"); \
} while (0)
#else
# define ERROR(...) do { } while (0)
# define DEBUG(...) do { } while (0)
#endif

57 58 59 60 61
#if !defined(LIBVIRT_NSS_GUEST)
# define NSS_NAME(s) _nss_libvirt_##s##_r
#else
# define NSS_NAME(s) _nss_libvirt_guest_##s##_r
#endif
62

63
enum nss_status
64 65 66
NSS_NAME(gethostbyname)(const char *name, struct hostent *result,
                        char *buffer, size_t buflen, int *errnop,
                        int *herrnop);
67 68

enum nss_status
69 70 71
NSS_NAME(gethostbyname2)(const char *name, int af, struct hostent *result,
                         char *buffer, size_t buflen, int *errnop,
                         int *herrnop);
72
enum nss_status
73 74 75
NSS_NAME(gethostbyname3)(const char *name, int af, struct hostent *result,
                         char *buffer, size_t buflen, int *errnop,
                         int *herrnop, int32_t *ttlp, char **canonp);
76
#ifdef HAVE_STRUCT_GAIH_ADDRTUPLE
77
enum nss_status
78 79 80
NSS_NAME(gethostbyname4)(const char *name, struct gaih_addrtuple **pat,
                         char *buffer, size_t buflen, int *errnop,
                         int *herrnop, int32_t *ttlp);
81
#endif /* HAVE_STRUCT_GAIH_ADDRTUPLE */
R
Roman Bogorodskiy 已提交
82

83
#if defined(HAVE_BSD_NSS)
R
Roman Bogorodskiy 已提交
84 85 86
ns_mtab*
nss_module_register(const char *name, unsigned int *size,
                    nss_module_unregister_fn *unregister);
87
#endif /* HAVE_BSD_NSS */