]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/systemd/sd-resolve.h
tree-wide: remove Lennart's copyright lines
[thirdparty/systemd.git] / src / systemd / sd-resolve.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
3bedba4a
TG
2#ifndef foosdresolvehfoo
3#define foosdresolvehfoo
e963e3ad
DB
4
5/***
e963e3ad 6
1783d897
TG
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.
e963e3ad 11
1783d897 12 systemd is distributed in the hope that it will be useful, but
e963e3ad
DB
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
1783d897
TG
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/>.
e963e3ad
DB
19***/
20
04c01369 21#include <inttypes.h>
e963e3ad 22#include <netdb.h>
04c01369
LP
23#include <sys/socket.h>
24#include <sys/types.h>
968d3d24 25
93f1bcf4 26#include "sd-event.h"
71d35b6b 27
04c01369 28#include "_sd-common.h"
1783d897
TG
29
30_SD_BEGIN_DECLARATIONS;
31
93f1bcf4 32/* An opaque sd-resolve session structure */
4f809256 33typedef struct sd_resolve sd_resolve;
e963e3ad 34
93f1bcf4 35/* An opaque sd-resolve query structure */
4f809256 36typedef struct sd_resolve_query sd_resolve_query;
e963e3ad 37
93f1bcf4
LP
38/* A callback on completion */
39typedef int (*sd_resolve_getaddrinfo_handler_t)(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata);
40typedef int (*sd_resolve_getnameinfo_handler_t)(sd_resolve_query *q, int ret, const char *host, const char *serv, void *userdata);
93f1bcf4
LP
41
42enum {
9b505bc2
ZJS
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,
93f1bcf4
LP
46};
47
48int sd_resolve_default(sd_resolve **ret);
49
50/* Allocate a new sd-resolve session. */
968d3d24 51int sd_resolve_new(sd_resolve **ret);
e963e3ad 52
93f1bcf4 53/* Free a sd-resolve session. This destroys all attached
10b17992 54 * sd_resolve_query objects automatically. */
968d3d24 55sd_resolve* sd_resolve_unref(sd_resolve *resolve);
93f1bcf4 56sd_resolve* sd_resolve_ref(sd_resolve *resolve);
968d3d24 57
93f1bcf4 58/* Return the UNIX file descriptor to poll() for events on. Use this
968d3d24
LP
59 * function to integrate sd-resolve with your custom main loop. */
60int sd_resolve_get_fd(sd_resolve *resolve);
61
93f1bcf4 62/* Return the poll() events (a combination of flags like POLLIN,
968d3d24
LP
63 * POLLOUT, ...) to check for. */
64int sd_resolve_get_events(sd_resolve *resolve);
e963e3ad 65
93f1bcf4 66/* Return the poll() timeout to pass. Returns (uint64_t) -1 as
10b17992 67 * timeout if no timeout is needed. */
968d3d24 68int sd_resolve_get_timeout(sd_resolve *resolve, uint64_t *timeout_usec);
e963e3ad 69
93f1bcf4 70/* Process pending responses. After this function is called, you can
968d3d24
LP
71 * get the next completed query object(s) using
72 * sd_resolve_get_next(). */
73int sd_resolve_process(sd_resolve *resolve);
74
93f1bcf4 75/* Wait for a resolve event to complete. */
968d3d24 76int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec);
e963e3ad 77
93f1bcf4
LP
78int sd_resolve_get_tid(sd_resolve *resolve, pid_t *tid);
79
32d20645 80int sd_resolve_attach_event(sd_resolve *resolve, sd_event *e, int64_t priority);
93f1bcf4
LP
81int sd_resolve_detach_event(sd_resolve *resolve);
82sd_event *sd_resolve_get_event(sd_resolve *resolve);
83
84/* Issue a name-to-address query on the specified session. The
10b17992 85 * arguments are compatible with those of libc's
e963e3ad 86 * getaddrinfo(3). The function returns a new query object. When the
10b17992 87 * query is completed, you may retrieve the results using
968d3d24 88 * sd_resolve_getaddrinfo_done(). */
93f1bcf4
LP
89int 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
10b17992 92 * arguments are compatible with those of libc's
e963e3ad 93 * getnameinfo(3). The function returns a new query object. When the
10b17992 94 * query is completed, you may retrieve the results using
3bedba4a 95 * sd_resolve_getnameinfo_done(). Set gethost (resp. getserv) to non-zero
e963e3ad 96 * if you want to query the hostname (resp. the service name). */
93f1bcf4 97int 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);
e963e3ad 98
93f1bcf4
LP
99sd_resolve_query *sd_resolve_query_ref(sd_resolve_query* q);
100sd_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. */
103int sd_resolve_query_is_done(sd_resolve_query*q);
104
105void *sd_resolve_query_get_userdata(sd_resolve_query *q);
106void *sd_resolve_query_set_userdata(sd_resolve_query *q, void *userdata);
107
108sd_resolve *sd_resolve_query_get_resolve(sd_resolve_query *q);
e963e3ad 109
4afd3348
LP
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
1783d897
TG
113_SD_END_DECLARATIONS;
114
e963e3ad 115#endif