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