summaryrefslogtreecommitdiffstats
path: root/hbeat.c
diff options
context:
space:
mode:
authorDean Jansa <djansa@redhat.com>2010-09-03 12:57:38 -0500
committerDean Jansa <djansa@redhat.com>2010-09-03 12:57:38 -0500
commit158d69d419595ba2c79e85b9d6d0d9b324654433 (patch)
treeeec97af3398ad7711ebab468f2f0b968d5401a0a /hbeat.c
parent0b8f4c9e6a7438d9829d526ab1879149818312d8 (diff)
downloadqarsh-158d69d419595ba2c79e85b9d6d0d9b324654433.tar.gz
qarsh-158d69d419595ba2c79e85b9d6d0d9b324654433.tar.xz
qarsh-158d69d419595ba2c79e85b9d6d0d9b324654433.zip
update btime and hbeat libs to understand ipv6 as well as ipv4.
Diffstat (limited to 'hbeat.c')
-rw-r--r--hbeat.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/hbeat.c b/hbeat.c
index 46b8ac1..8f781e0 100644
--- a/hbeat.c
+++ b/hbeat.c
@@ -56,25 +56,33 @@ hbeat_t
hbeat_init(const char *host, int max_timeout)
{
struct hbeat_s *hbeatp;
- struct hostent *hostent;
- struct in_addr tmpaddr;
+ struct addrinfo hints, *aip;
+ void *addr;
+ char ipstr[INET6_ADDRSTRLEN];
hbeatp = malloc(sizeof *hbeatp);
if (!hbeatp) {
return NULL;
}
- /* 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));
+ 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 {
- hbeatp->host = strdup(host);
+ 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->max_timeout = max_timeout;
hbeatp->rhost_state = HOST_ALIVE;
hbeatp->last_rhost_btime = 0;