summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate Straz <nstraz@redhat.com>2008-04-07 15:57:00 +0000
committerNathan Straz <nstraz@redhat.com>2008-09-23 09:37:47 -0400
commit3358797987483f861c46fdccc7f57869dabc26de (patch)
tree5dc4e3fca9a235346fd6f154d26e716aabbe53ab
parenta38e741050cccae5c7ca3c015b0599c518ec3b67 (diff)
downloadqarsh-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.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;