diff options
Diffstat (limited to 'libglusterfs/src/events.c')
-rw-r--r-- | libglusterfs/src/events.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c index 6b3a73d8ae4..27c421a7c74 100644 --- a/libglusterfs/src/events.c +++ b/libglusterfs/src/events.c @@ -17,7 +17,6 @@ #include <stdarg.h> #include <string.h> #include <netinet/in.h> -#include <arpa/inet.h> #include <netdb.h> #include "syscall.h" @@ -41,8 +40,9 @@ _gf_event (eventtypes_t event, char *fmt, ...) va_list arguments; char *msg = NULL; glusterfs_ctx_t *ctx = NULL; - struct hostent *host_data; char *host = NULL; + struct addrinfo hints; + struct addrinfo *result = NULL; /* Global context */ ctx = THIS->ctx; @@ -59,19 +59,26 @@ _gf_event (eventtypes_t event, char *fmt, ...) goto out; } + memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_UNSPEC; + /* Get Host name to send message */ if (ctx && ctx->cmd_args.volfile_server) { /* If it is client code then volfile_server is set use that information to push the events. */ - host_data = gethostbyname (ctx->cmd_args.volfile_server); - if (host_data == NULL) { + if ((getaddrinfo (ctx->cmd_args.volfile_server, + NULL, &hints, &result)) != 0) { + ret = EVENT_ERROR_RESOLVE; + goto out; + } + + if (get_ip_from_addrinfo (result, &host) == NULL) { ret = EVENT_ERROR_RESOLVE; goto out; } - host = inet_ntoa (*(struct in_addr *)(host_data->h_addr)); } else { /* Localhost, Use the defined IP for localhost */ - host = EVENT_HOST; + host = gf_strdup (EVENT_HOST); } /* Socket Configurations */ @@ -118,5 +125,11 @@ _gf_event (eventtypes_t event, char *fmt, ...) if (eventstr) GF_FREE (eventstr); + if (host) + GF_FREE (host); + + if (result) + freeaddrinfo (result); + return ret; } |