summaryrefslogtreecommitdiffstats
path: root/hbeat.c
diff options
context:
space:
mode:
Diffstat (limited to 'hbeat.c')
-rw-r--r--hbeat.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/hbeat.c b/hbeat.c
index 8f781e0..a6350fa 100644
--- a/hbeat.c
+++ b/hbeat.c
@@ -36,6 +36,7 @@
struct hbeat_s {
char *host;
+ int btime_sock;
int max_timeout;
hbeat_state_t rhost_state;
unsigned int last_rhost_btime;
@@ -56,33 +57,13 @@ hbeat_t
hbeat_init(const char *host, int max_timeout)
{
struct hbeat_s *hbeatp;
- struct addrinfo hints, *aip;
- void *addr;
- char ipstr[INET6_ADDRSTRLEN];
hbeatp = malloc(sizeof *hbeatp);
if (!hbeatp) {
return NULL;
}
- memset(&hints, 0, sizeof hints);
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_DGRAM;
-
- if (getaddrinfo(host, NULL, &hints, &aip) != 0) {
- return NULL;
- }
-
- if (aip->ai_family == AF_INET) {
- addr = &(((struct sockaddr_in *)aip->ai_addr)->sin_addr);
- } else {
- addr = &(((struct sockaddr_in6 *)aip->ai_addr)->sin6_addr);
- }
-
- inet_ntop(aip->ai_family, addr, ipstr, sizeof ipstr);
- freeaddrinfo(aip);
-
- hbeatp->host = strdup(ipstr);
+ hbeatp->btime_sock = btime_init(host);
hbeatp->max_timeout = max_timeout;
hbeatp->rhost_state = HOST_ALIVE;
hbeatp->last_rhost_btime = 0;
@@ -135,16 +116,16 @@ hbeat(hbeat_t hbh)
return 1;
}
- hbeat = btime(hbeatp->host);
+ hbeat = btime_do(hbeatp->btime_sock);
/* quickly sanity check that we're getting the same
* hbeat every time we ask for it
*/
if (hbeat && hbeatp->last_rhost_btime
&& hbeat != hbeatp->last_rhost_btime) {
- hbeat2 = btime(hbeatp->host);
+ hbeat2 = btime_do(hbeatp->btime_sock);
if (hbeat != hbeat2) {
fprintf(stderr, "Got conflicting hbeat times (%d and %d), discarding both\n", hbeat, hbeat2);
- hbeat = btime(hbeatp->host);
+ hbeat = btime_do(hbeatp->btime_sock);
}
}
current_time = time(NULL);