// SPDX-FileCopyrightText: Matteo Settenvini // SPDX-License-Identifier: GPL-3.0-or-later #pragma once #include "wrapper.hh" #include "cares_init.hh" #include #include #include #include #include namespace malcontent { struct ResolverArgs { const char *name; // in int family; // in hostent *result; // out char *buffer; // out size_t buflen; // in int *errnop; // out HErrno *h_errnop; // out int32_t *ttlp; // out }; class Resolver { public: Resolver(std::vector dns); auto resolve(ResolverArgs& args) -> nss_status; private: struct CAresDeletor { auto operator() (ares_channel_t *ch) const -> void { ares_destroy(ch); } }; using CAresChannel = std::unique_ptr; static auto resolve_cb(void *arg, int status, int timeouts, unsigned char *abuf, int alen) -> void; auto resolved(ResolverArgs& result, int status, int timeouts, unsigned char *abuf, int alen) -> nss_status; std::shared_ptr _ensure_cares_initialized; CAresChannel _channel; }; } // ~ namespace malcontent