mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 07:15:06 -05:00
Add -4 and -6 options to set address family when resolving names
This commit is contained in:
8
client.c
8
client.c
@@ -2619,11 +2619,17 @@ main(int argc, char **argv)
|
||||
}
|
||||
} else if (!strcmp(*argv, "-n")) {
|
||||
no_dns = 1;
|
||||
} else if (!strcmp(*argv, "-4")) {
|
||||
DNS_SetAddressFamily(IPADDR_INET4);
|
||||
hostname = "127.0.0.1";
|
||||
} else if (!strcmp(*argv, "-6")) {
|
||||
DNS_SetAddressFamily(IPADDR_INET6);
|
||||
hostname = "::1";
|
||||
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
||||
printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
|
||||
exit(0);
|
||||
} else if (!strncmp(*argv, "-", 1)) {
|
||||
fprintf(stderr, "Usage : %s [-h <hostname>] [-p <port-number>] [-n] [command]\n", progname);
|
||||
fprintf(stderr, "Usage : %s [-h <hostname>] [-p <port-number>] [-n] [-4|-6] [command]\n", progname);
|
||||
exit(1);
|
||||
} else {
|
||||
break; /* And process remainder of line as a command */
|
||||
|
||||
5
main.c
5
main.c
@@ -61,6 +61,7 @@
|
||||
#include "refclock.h"
|
||||
#include "clientlog.h"
|
||||
#include "broadcast.h"
|
||||
#include "nameserv.h"
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
@@ -268,6 +269,10 @@ int main
|
||||
exit(0);
|
||||
} else if (!strcmp("-d", *argv)) {
|
||||
debug = 1;
|
||||
} else if (!strcmp("-4", *argv)) {
|
||||
DNS_SetAddressFamily(IPADDR_INET4);
|
||||
} else if (!strcmp("-6", *argv)) {
|
||||
DNS_SetAddressFamily(IPADDR_INET6);
|
||||
} else {
|
||||
LOG(LOGS_WARN, LOGF_Main, "Unrecognized command line option [%s]", *argv);
|
||||
}
|
||||
|
||||
10
nameserv.c
10
nameserv.c
@@ -40,6 +40,14 @@
|
||||
#define MAXRETRIES 10
|
||||
static unsigned int retries = 0;
|
||||
|
||||
static int address_family = IPADDR_UNSPEC;
|
||||
|
||||
void
|
||||
DNS_SetAddressFamily(int family)
|
||||
{
|
||||
address_family = family;
|
||||
}
|
||||
|
||||
int
|
||||
DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry)
|
||||
{
|
||||
@@ -80,6 +88,8 @@ try_again:
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
if (result && address_family != IPADDR_UNSPEC && address_family != addr->family)
|
||||
result = 0;
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
|
||||
#include "addressing.h"
|
||||
|
||||
/* Resolve names only to selected address family */
|
||||
extern void DNS_SetAddressFamily(int family);
|
||||
|
||||
extern int DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry);
|
||||
|
||||
extern void DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len);
|
||||
|
||||
Reference in New Issue
Block a user