Add -4 and -6 options to set address family when resolving names
This commit is contained in:
parent
a7892a1a15
commit
fbd20c429e
4 changed files with 25 additions and 1 deletions
8
client.c
8
client.c
|
@ -2619,11 +2619,17 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
} else if (!strcmp(*argv, "-n")) {
|
} else if (!strcmp(*argv, "-n")) {
|
||||||
no_dns = 1;
|
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)) {
|
} else if (!strcmp("-v", *argv) || !strcmp("--version",*argv)) {
|
||||||
printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
|
printf("chronyc (chrony) version %s\n", PROGRAM_VERSION_STRING);
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strncmp(*argv, "-", 1)) {
|
} 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);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
break; /* And process remainder of line as a command */
|
break; /* And process remainder of line as a command */
|
||||||
|
|
5
main.c
5
main.c
|
@ -61,6 +61,7 @@
|
||||||
#include "refclock.h"
|
#include "refclock.h"
|
||||||
#include "clientlog.h"
|
#include "clientlog.h"
|
||||||
#include "broadcast.h"
|
#include "broadcast.h"
|
||||||
|
#include "nameserv.h"
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
@ -268,6 +269,10 @@ int main
|
||||||
exit(0);
|
exit(0);
|
||||||
} else if (!strcmp("-d", *argv)) {
|
} else if (!strcmp("-d", *argv)) {
|
||||||
debug = 1;
|
debug = 1;
|
||||||
|
} else if (!strcmp("-4", *argv)) {
|
||||||
|
DNS_SetAddressFamily(IPADDR_INET4);
|
||||||
|
} else if (!strcmp("-6", *argv)) {
|
||||||
|
DNS_SetAddressFamily(IPADDR_INET6);
|
||||||
} else {
|
} else {
|
||||||
LOG(LOGS_WARN, LOGF_Main, "Unrecognized command line option [%s]", *argv);
|
LOG(LOGS_WARN, LOGF_Main, "Unrecognized command line option [%s]", *argv);
|
||||||
}
|
}
|
||||||
|
|
10
nameserv.c
10
nameserv.c
|
@ -40,6 +40,14 @@
|
||||||
#define MAXRETRIES 10
|
#define MAXRETRIES 10
|
||||||
static unsigned int retries = 0;
|
static unsigned int retries = 0;
|
||||||
|
|
||||||
|
static int address_family = IPADDR_UNSPEC;
|
||||||
|
|
||||||
|
void
|
||||||
|
DNS_SetAddressFamily(int family)
|
||||||
|
{
|
||||||
|
address_family = family;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry)
|
DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +88,8 @@ try_again:
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
if (result && address_family != IPADDR_UNSPEC && address_family != addr->family)
|
||||||
|
result = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(res);
|
freeaddrinfo(res);
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
|
|
||||||
#include "addressing.h"
|
#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 int DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry);
|
||||||
|
|
||||||
extern void DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len);
|
extern void DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len);
|
||||||
|
|
Loading…
Reference in a new issue