summaryrefslogtreecommitdiffstats
path: root/hbeat.c
diff options
context:
space:
mode:
Diffstat (limited to 'hbeat.c')
-rw-r--r--hbeat.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/hbeat.c b/hbeat.c
index ab0fb33..46b8ac1 100644
--- a/hbeat.c
+++ b/hbeat.c
@@ -27,6 +27,8 @@
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
+#include <netdb.h>
+#include <arpa/inet.h>
#include "btime.h"
#include "hbeat.h"
@@ -54,13 +56,25 @@ hbeat_t
hbeat_init(const char *host, int max_timeout)
{
struct hbeat_s *hbeatp;
+ struct hostent *hostent;
+ struct in_addr tmpaddr;
hbeatp = malloc(sizeof *hbeatp);
if (!hbeatp) {
return NULL;
}
- hbeatp->host = strdup(host);
+ /* Store the dotted quad instead of the hostname so we
+ * don't have to look it up ever time we hbeat. */
+ if (inet_addr(host) == INADDR_NONE) {
+ if ((hostent = gethostbyname(host)) == NULL) {
+ return NULL;
+ }
+ memcpy(&tmpaddr, hostent->h_addr, hostent->h_length);
+ hbeatp->host = strdup(inet_ntoa(tmpaddr));
+ } else {
+ hbeatp->host = strdup(host);
+ }
hbeatp->max_timeout = max_timeout;
hbeatp->rhost_state = HOST_ALIVE;
hbeatp->last_rhost_btime = 0;