]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-resolve.h
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / systemd / sd-resolve.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #ifndef foosdresolvehfoo
3 #define foosdresolvehfoo
4
5 /***
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 ***/
20
21 #include <inttypes.h>
22 #include <netdb.h>
23 #include <sys/socket.h>
24 #include <sys/types.h>
25
26 #include "sd-event.h"
27
28 #include "_sd-common.h"
29
30 _SD_BEGIN_DECLARATIONS;
31
32 /* An opaque sd-resolve session structure */
33 typedef struct sd_resolve sd_resolve;
34
35 /* An opaque sd-resolve query structure */
36 typedef struct sd_resolve_query sd_resolve_query;
37
38 /* A callback on completion */
39 typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
40 typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
41
42 enum {
43 SD_RESOLVE_GET_HOST = 1 << 0,
44 SD_RESOLVE_GET_SERVICE = 1 << 1,
45 SD_RESOLVE_GET_BOTH = SD_RESOLVE_GET_HOST | SD_RESOLVE_GET_SERVICE,
46 };
47
48 int sd_resolve_default(sd_resolve **ret);
49
50 /* Allocate a new sd-resolve session. */
51 int sd_resolve_new(sd_resolve **ret);
52
53 /* Free a sd-resolve session. This destroys all attached
54 * sd_resolve_query objects automatically. */
55 sd_resolve* sd_resolve_unref(sd_resolve *resolve);
56 sd_resolve* sd_resolve_ref(sd_resolve *resolve);
57
58 /* Return the UNIX file descriptor to poll() for events on. Use this
59 * function to integrate sd-resolve with your custom main loop. */
60 int sd_resolve_get_fd(sd_resolve *resolve);
61
62 /* Return the poll() events (a combination of flags like POLLIN,
63 * POLLOUT, ...) to check for. */
64 int sd_resolve_get_events(sd_resolve *resolve);
65
66 /* Return the poll() timeout to pass. Returns (uint64_t) -1 as
67 * timeout if no timeout is needed. */
68 int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
69
70 /* Process pending responses. After this function is called, you can
71 * get the next completed query object(s) using
72 * sd_resolve_get_next(). */
73 int sd_resolve_process(sd_resolve *resolve);
74
75 /* Wait for a resolve event to complete. */
76 int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
77
78 int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
79
80 int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int64_t priority);
81 int sd_resolve_detach_event(sd_resolve *resolve);
82 sd_event *sd_resolve_get_event(sd_resolve *resolve);
83
84 /* Issue a name-to-address query on the specified session. The
85 * arguments are compatible with those of libc's
86 * getaddrinfo(3). The function returns a new query object. When the
87 * query is completed, you may retrieve the results using
88 * sd_resolve_getaddrinfo_done(). */
89 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);
90
91 /* Issue an address-to-name query on the specified session. The
92 * arguments are compatible with those of libc's
93 * getnameinfo(3). The function returns a new query object. When the
94 * query is completed, you may retrieve the results using
95 * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
96 * if you want to query the hostname (resp. the service name). */
97 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);
98
99 sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
100 sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);
101
102 /* Returns non-zero when the query operation specified by q has been completed. */
103 int sd_resolve_query_is_done(sd_resolve_query*q);
104
105 void *sd_resolve_query_get_userdata(sd_resolve_query *q);
106 void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
107
108 sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
109
110 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve, sd_resolve_unref);
111 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve_query, sd_resolve_query_unref);
112
113 _SD_END_DECLARATIONS;
114
115 #endif