]> git.armaanb.net Git - sic.git/blobdiff - util.c
util: dial: no need for a static struct hints
[sic.git] / util.c
diff --git a/util.c b/util.c
index 0869cca08401a08f53878653f3a37d5bf0d6a12f..cb966d43c89ae24bae1afcdf32e7136f8ef68367 100644 (file)
--- a/util.c
+++ b/util.c
@@ -18,9 +18,9 @@ eprint(const char *fmt, ...) {
 
 static int
 dial(char *host, char *port) {
-       static struct addrinfo hints;
-       int srv;
+       struct addrinfo hints;
        struct addrinfo *res, *r;
+       int fd;
 
        memset(&hints, 0, sizeof hints);
        hints.ai_family = AF_UNSPEC;
@@ -28,16 +28,16 @@ dial(char *host, char *port) {
        if(getaddrinfo(host, port, &hints, &res) != 0)
                eprint("error: cannot resolve hostname '%s':", host);
        for(r = res; r; r = r->ai_next) {
-               if((srv = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
+               if((fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol)) == -1)
                        continue;
-               if(connect(srv, r->ai_addr, r->ai_addrlen) == 0)
+               if(connect(fd, r->ai_addr, r->ai_addrlen) == 0)
                        break;
-               close(srv);
+               close(fd);
        }
        freeaddrinfo(res);
        if(!r)
                eprint("error: cannot connect to host '%s'\n", host);
-       return srv;
+       return fd;
 }
 
 static char *