IPAddr ip;
/* Note, this call could block for a while */
- if (!DNS_Name2IPAddress(hostname, &ip, 0)) {
+ if (DNS_Name2IPAddress(hostname, &ip) != DNS_Success) {
fprintf(stderr, "Could not get IP address for %s\n", hostname);
exit(1);
}
fprintf(stderr, "Invalid syntax for address value\n");
ok = 0;
} else {
- if (!DNS_Name2IPAddress(hostname, address, 0)) {
+ if (DNS_Name2IPAddress(hostname, address) != DNS_Success) {
fprintf(stderr, "Could not get address for hostname\n");
ok = 0;
} else {
fprintf(stderr, "Invalid syntax for address value\n");
ok = 0;
} else {
- if (!DNS_Name2IPAddress(hostname, address, 0)) {
+ if (DNS_Name2IPAddress(hostname, address) != DNS_Success) {
fprintf(stderr, "Could not get address for hostname\n");
ok = 0;
} else {
if (*q == '\n') *q = 0;
q++;
}
- if (!DNS_Name2IPAddress(p, &ip, 0)) {
+ if (DNS_Name2IPAddress(p, &ip) != DNS_Success) {
fprintf(stderr, "Could not read address\n");
return 0;
} else {
if (*q == '\n') *q = 0;
q++;
}
- if (!DNS_Name2IPAddress(p, &ip, 0)) {
+ if (DNS_Name2IPAddress(p, &ip) != DNS_Success) {
return 0;
} else {
*addr = ip;
fprintf(stderr, "Invalid syntax for address\n");
ok = 0;
} else {
- if (!DNS_Name2IPAddress(hostname, &address, 0)) {
+ if (DNS_Name2IPAddress(hostname, &address) != DNS_Success) {
fprintf(stderr, "Could not get address for hostname\n");
ok = 0;
} else {
int ok, n, done;
char cmd[MAXLEN+1], hostname[MAXLEN+1];
CPS_Status result;
+ DNS_Status s;
src->port = 123;
src->params.minpoll = 6;
ok = 0;
if (sscanf(line, "%" SMAXLEN "s%n", hostname, &n) == 1) {
- if (DNS_Name2IPAddress(hostname, &src->ip_addr, 1)) {
+ s = DNS_Name2IPAddress(hostname, &src->ip_addr);
+ if (s == DNS_Success) {
ok = 1;
}
}
}
while (*p) {
if (sscanf(p, "%" SHOSTNAME_LEN "s%n", hostname, &n) == 1) {
- if (DNS_Name2IPAddress(hostname, &ip_addr, 1)) {
+ if (DNS_Name2IPAddress(hostname, &ip_addr) == DNS_Success) {
init_srcs_ip[n_init_srcs] = ip_addr;
++n_init_srcs;
}
}
} else {
- if (DNS_Name2IPAddress(p, &ip_addr, 1)) {
+ if (DNS_Name2IPAddress(p, &ip_addr) == DNS_Success) {
new_node = MallocNew(AllowDeny);
new_node->allow = allow;
new_node->all = all;
/* ================================================== */
-#define MAXRETRIES 10
-static unsigned int retries = 0;
-
static int address_family = IPADDR_UNSPEC;
void
address_family = family;
}
-int
-DNS_Name2IPAddress(const char *name, IPAddr *addr, int retry)
+DNS_Status
+DNS_Name2IPAddress(const char *name, IPAddr *addr)
{
#ifdef HAVE_IPV6
struct addrinfo hints, *res, *ai;
hints.ai_flags = AI_ADDRCONFIG;
#endif
-try_again:
result = getaddrinfo(name, NULL, &hints, &res);
if (result) {
- if (retry && result == EAI_AGAIN && retries < MAXRETRIES) {
- sleep(2 << retries);
- retries++;
- res_init();
- goto try_again;
- }
- return 0;
+ return result == EAI_AGAIN ? DNS_TryAgain : DNS_Failure;
}
for (ai = res; !result && ai != NULL; ai = ai->ai_next) {
}
freeaddrinfo(res);
- return result;
+ return result ? DNS_Success : DNS_Failure;
#else
struct hostent *host;
char *address0;
-try_again:
host = gethostbyname(name);
if (host == NULL) {
- if (retry && h_errno == TRY_AGAIN && retries < MAXRETRIES) {
- sleep(2 << retries);
- retries++;
- res_init();
- goto try_again;
- }
+ if (h_errno == TRY_AGAIN)
+ return DNS_TryAgain;
} else {
addr->family = IPADDR_INET4;
address0 = host->h_addr_list[0];
(((unsigned long)address0[1])<<16) |
(((unsigned long)address0[2])<<8) |
(((unsigned long)address0[3])));
- return 1;
+ return DNS_Success;
}
- return 0;
+ return DNS_Failure;
#endif
}
/* ================================================== */
+void
+DNS_Reload(void)
+{
+ res_init();
+}
+
+/* ================================================== */
+
#include "addressing.h"
+typedef enum {
+ DNS_Success,
+ DNS_TryAgain,
+ DNS_Failure
+} DNS_Status;
+
/* 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 DNS_Status DNS_Name2IPAddress(const char *name, IPAddr *addr);
extern int DNS_IPAddress2Name(IPAddr *ip_addr, char *name, int len);
+extern void DNS_Reload(void);
+
#endif /* GOT_NAMESERV_H */