diff options
author | Nate Straz <nstraz@redhat.com> | 2008-04-07 15:57:00 +0000 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2008-09-23 09:37:47 -0400 |
commit | 3358797987483f861c46fdccc7f57869dabc26de (patch) | |
tree | 5dc4e3fca9a235346fd6f154d26e716aabbe53ab | |
parent | a38e741050cccae5c7ca3c015b0599c518ec3b67 (diff) | |
download | qarsh-3358797987483f861c46fdccc7f57869dabc26de.tar.gz qarsh-3358797987483f861c46fdccc7f57869dabc26de.tar.xz qarsh-3358797987483f861c46fdccc7f57869dabc26de.zip |
Try to reduce the number of times we look up a hostname by storing
the address in the hbeat struct instead of the name.
-rw-r--r-- | hbeat.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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; |