From 5be528c2130a1281ba858296924dd619068bb0e3 Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Tue, 26 Jul 2011 11:03:10 -0700 Subject: [PATCH] Staging: hv: util: kvp: Cleanup kvp_get_domain_name() Cleanup kvp_get_domain_name(). If getaddrinfo() fails, deal with it properly (this can happen if no IP address has been assigned). Also, don't specify a specific service in the call to getaddrinfo() to make this code as generic as possible. Lastly, move the call to gethostname() after the local variables. Signed-off-by: K. Y. Srinivasan Signed-off-by: Haiyang Zhang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/hv/tools/hv_kvp_daemon.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/staging/hv/tools/hv_kvp_daemon.c b/drivers/staging/hv/tools/hv_kvp_daemon.c index c4cf988ad5cb..11224eddcdc2 100644 --- a/drivers/staging/hv/tools/hv_kvp_daemon.c +++ b/drivers/staging/hv/tools/hv_kvp_daemon.c @@ -273,22 +273,20 @@ static int kvp_get_domain_name(char *buffer, int length) { struct addrinfo hints, *info ; - gethostname(buffer, length); int error = 0; + gethostname(buffer, length); memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; /*Get only ipv4 addrinfo. */ hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_CANONNAME; - error = getaddrinfo(buffer, "http", &hints, &info); + error = getaddrinfo(buffer, NULL, &hints, &info); if (error != 0) { strcpy(buffer, "getaddrinfo failed\n"); - error = 1; - goto get_domain_done; + return error; } strcpy(buffer, info->ai_canonname); -get_domain_done: freeaddrinfo(info); return error; } -- 2.39.5