From a6e5c1293380c5c93ce02942a858dc876137a253 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Thu, 29 Aug 2024 10:21:08 +0200 Subject: [PATCH] Moved hostname resolver to logger --- sysdep/unix/io.c | 32 -------------------------------- sysdep/unix/log.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 427b22973..d9f863601 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -446,35 +446,3 @@ test_old_bird(const char *path) close(fd); } - -/* - * DNS resolver - */ - -ip_addr -resolve_hostname(const char *host, int type, const char **err_msg) -{ - struct addrinfo *res; - struct addrinfo hints = { - .ai_family = AF_UNSPEC, - .ai_socktype = (type == SK_UDP) ? SOCK_DGRAM : SOCK_STREAM, - .ai_flags = AI_ADDRCONFIG, - }; - - *err_msg = NULL; - - int err_code = getaddrinfo(host, NULL, &hints, &res); - if (err_code != 0) - { - *err_msg = gai_strerror(err_code); - return IPA_NONE; - } - - ip_addr addr = IPA_NONE; - uint unused; - - sockaddr_read((sockaddr *) res->ai_addr, res->ai_family, &addr, NULL, &unused); - freeaddrinfo(res); - - return addr; -} diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index d6614cd1a..8fb0d3c3d 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -15,10 +15,13 @@ * user's manual. */ +#include #include #include #include #include +#include +#include #include #include #include @@ -878,3 +881,35 @@ void set_daemon_name(char *path, char *def) { bird_name = get_bird_name(path, def); } + +/* + * DNS resolver + */ + +ip_addr +resolve_hostname(const char *host, int type, const char **err_msg) +{ + struct addrinfo *res; + struct addrinfo hints = { + .ai_family = AF_UNSPEC, + .ai_socktype = (type == SK_UDP) ? SOCK_DGRAM : SOCK_STREAM, + .ai_flags = AI_ADDRCONFIG, + }; + + *err_msg = NULL; + + int err_code = getaddrinfo(host, NULL, &hints, &res); + if (err_code != 0) + { + *err_msg = gai_strerror(err_code); + return IPA_NONE; + } + + ip_addr addr = IPA_NONE; + uint unused; + + sockaddr_read((sockaddr *) res->ai_addr, res->ai_family, &addr, NULL, &unused); + freeaddrinfo(res); + + return addr; +} -- 2.47.2