1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3 #ifndef foosdresolvehfoo
4 #define foosdresolvehfoo
7 This file is part of systemd.
9 Copyright 2005-2014 Lennart Poettering
11 systemd is free software; you can redistribute it and/or modify it
12 under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
14 (at your option) any later version.
16 systemd is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/types.h>
26 #include <sys/socket.h>
29 #include "_sd-common.h"
32 _SD_BEGIN_DECLARATIONS;
34 /* An opaque sd-resolve session structure */
35 typedef struct sd_resolve sd_resolve;
37 /* An opaque sd-resolve query structure */
38 typedef struct sd_resolve_query sd_resolve_query;
40 /* A callback on completion */
41 typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
42 typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
43 typedef int (*sd_resolve_res_handler_t)(sd_resolve_query* q, int ret, unsigned char *answer, void *userdata);
46 SD_RESOLVE_GET_HOST = 1ULL,
47 SD_RESOLVE_GET_SERVICE = 2ULL,
48 SD_RESOLVE_GET_BOTH = 3ULL
51 int sd_resolve_default(sd_resolve **ret);
53 /* Allocate a new sd-resolve session. */
54 int sd_resolve_new(sd_resolve **ret);
56 /* Free a sd-resolve session. This destroys all attached
57 * sd_resolve_query objects automatically. */
58 sd_resolve* sd_resolve_unref(sd_resolve *resolve);
59 sd_resolve* sd_resolve_ref(sd_resolve *resolve);
61 /* Return the UNIX file descriptor to poll() for events on. Use this
62 * function to integrate sd-resolve with your custom main loop. */
63 int sd_resolve_get_fd(sd_resolve *resolve);
65 /* Return the poll() events (a combination of flags like POLLIN,
66 * POLLOUT, ...) to check for. */
67 int sd_resolve_get_events(sd_resolve *resolve);
69 /* Return the poll() timeout to pass. Returns (uint64_t) -1 as
70 * timeout if no timeout is needed. */
71 int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
73 /* Process pending responses. After this function is called, you can
74 * get the next completed query object(s) using
75 * sd_resolve_get_next(). */
76 int sd_resolve_process(sd_resolve *resolve);
78 /* Wait for a resolve event to complete. */
79 int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
81 int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
83 int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int priority);
84 int sd_resolve_detach_event(sd_resolve *resolve);
85 sd_event *sd_resolve_get_event(sd_resolve *resolve);
87 /* Issue a name-to-address query on the specified session. The
88 * arguments are compatible with those of libc's
89 * getaddrinfo(3). The function returns a new query object. When the
90 * query is completed, you may retrieve the results using
91 * sd_resolve_getaddrinfo_done(). */
92 int sd_resolve_getaddrinfo(sd_resolve *resolve, sd_resolve_query **q, const char *node, const char *service, const struct addrinfo *hints, sd_resolve_getaddrinfo_handler_t callback, void *userdata);
94 /* Issue an address-to-name query on the specified session. The
95 * arguments are compatible with those of libc's
96 * getnameinfo(3). The function returns a new query object. When the
97 * query is completed, you may retrieve the results using
98 * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
99 * if you want to query the hostname (resp. the service name). */
100 int sd_resolve_getnameinfo(sd_resolve *resolve, sd_resolve_query **q, const struct sockaddr *sa, socklen_t salen, int flags, uint64_t get, sd_resolve_getnameinfo_handler_t callback, void *userdata);
102 /* Issue a resolver query on the specified session. The arguments are
103 * compatible with those of libc's res_query(3). The function returns a new
104 * query object. When the query is completed, you may retrieve the results using
105 * sd_resolve_res_done(). */
106 int sd_resolve_res_query(sd_resolve *resolve, sd_resolve_query **q, const char *dname, int clazz, int type, sd_resolve_res_handler_t callback, void *userdata);
108 /* Issue a resolver query on the specified session. The arguments are
109 * compatible with those of libc's res_search(3). The function returns a new
110 * query object. When the query is completed, you may retrieve the results using
111 * sd_resolve_res_done(). */
112 int sd_resolve_res_search(sd_resolve *resolve, sd_resolve_query **q, const char *dname, int clazz, int type, sd_resolve_res_handler_t callback, void *userdata);
114 sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
115 sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);
117 /* Returns non-zero when the query operation specified by q has been completed. */
118 int sd_resolve_query_is_done(sd_resolve_query*q);
120 void *sd_resolve_query_get_userdata(sd_resolve_query *q);
121 void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
123 sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
125 _SD_END_DECLARATIONS;