]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/systemd/sd-resolve.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / systemd / sd-resolve.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #ifndef foosdresolvehfoo
3 #define foosdresolvehfoo
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2005-2014 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <inttypes.h>
25 #include <netdb.h>
26 #include <sys/socket.h>
27 #include <sys/types.h>
28
29 #include "sd-event.h"
30
31 #include "_sd-common.h"
32
33 _SD_BEGIN_DECLARATIONS;
34
35 /* An opaque sd-resolve session structure */
36 typedef struct sd_resolve sd_resolve;
37
38 /* An opaque sd-resolve query structure */
39 typedef struct sd_resolve_query sd_resolve_query;
40
41 /* A callback on completion */
42 typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
43 typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
44
45 enum {
46 SD_RESOLVE_GET_HOST = UINT64_C(1),
47 SD_RESOLVE_GET_SERVICE = UINT64_C(2),
48 SD_RESOLVE_GET_BOTH = UINT64_C(3),
49 };
50
51 int sd_resolve_default(sd_resolve **ret);
52
53 /* Allocate a new sd-resolve session. */
54 int sd_resolve_new(sd_resolve **ret);
55
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);
60
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);
64
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);
68
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);
72
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);
77
78 /* Wait for a resolve event to complete. */
79 int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
80
81 int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
82
83 int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int64_t priority);
84 int sd_resolve_detach_event(sd_resolve *resolve);
85 sd_event *sd_resolve_get_event(sd_resolve *resolve);
86
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);
93
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);
101
102 sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
103 sd_resolve_query *sd_resolve_query_unref(sd_resolve_query* q);
104
105 /* Returns non-zero when the query operation specified by q has been completed. */
106 int sd_resolve_query_is_done(sd_resolve_query*q);
107
108 void *sd_resolve_query_get_userdata(sd_resolve_query *q);
109 void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
110
111 sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
112
113 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve, sd_resolve_unref);
114 _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_resolve_query, sd_resolve_query_unref);
115
116 _SD_END_DECLARATIONS;
117
118 #endif