0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 18:08:45 +00:00

Moved hostname resolver to logger

This commit is contained in:
Maria Matejka 2024-08-29 10:21:08 +02:00
parent bd75a5253a
commit 60bd75c174
2 changed files with 35 additions and 32 deletions

View File

@ -444,35 +444,3 @@ test_old_bird(char *path)
close(fd); 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;
}

View File

@ -15,10 +15,13 @@
* user's manual. * user's manual.
*/ */
#include <netdb.h>
#include <stdatomic.h> #include <stdatomic.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -867,3 +870,35 @@ void set_daemon_name(char *path, char *def)
{ {
bird_name = get_bird_name(path, 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;
}