]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Staging: hv: util: kvp: Cleanup kvp_get_domain_name()
authorK. Y. Srinivasan <kys@microsoft.com>
Tue, 26 Jul 2011 18:03:10 +0000 (11:03 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 23 Aug 2011 23:19:37 +0000 (16:19 -0700)
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 <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/tools/hv_kvp_daemon.c

index c4cf988ad5cb3f3e3a5d95db8e65bd62e6057b0c..11224eddcdc22ebcb40e20d77774e2a1834cb8fb 100644 (file)
@@ -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;
 }