diff --git a/connector/c/tnt.c b/connector/c/tnt.c index ec7325d252698acae23617f005780de6442d200f..8ccafd79ac52afe0bc00b70a53d0fad72907d2c9 100644 --- a/connector/c/tnt.c +++ b/connector/c/tnt.c @@ -106,7 +106,6 @@ tnt_connect(struct tnt *t) t->error = tnt_io_connect(t, t->opt.hostname, t->opt.port); if (t->error != TNT_EOK) return -1; - t->connected = 1; return 0; } diff --git a/connector/c/tnt_io.c b/connector/c/tnt_io.c index 0d45b80754b5c0b60ddce99eb591cffcf74e81eb..49dffe70295e906bdf64fc6fb0eac21926de0f4a 100644 --- a/connector/c/tnt_io.c +++ b/connector/c/tnt_io.c @@ -59,13 +59,17 @@ tnt_io_resolve(struct sockaddr_in *addr, memset(addr, 0, sizeof(struct sockaddr_in)); addr->sin_family = AF_INET; addr->sin_port = htons(port); - struct hostent *host = gethostbyname(hostname); - if (host) + struct addrinfo *addr_info = NULL; + if (getaddrinfo(hostname, NULL, NULL, &addr_info) == 0) { memcpy(&addr->sin_addr, - (void*)(host->h_addr), host->h_length); - else - return TNT_ERESOLVE; - return TNT_EOK; + (void*)&((struct sockaddr_in *)addr_info->ai_addr)->sin_addr, + sizeof(addr->sin_addr)); + freeaddrinfo(addr_info); + return TNT_EOK; + } + if (addr_info) + freeaddrinfo(addr_info); + return TNT_ERESOLVE; } static enum tnt_error @@ -234,6 +238,7 @@ tnt_io_connect(struct tnt *t, char *host, int port) result = tnt_io_connect_do(t, host, port); if (result != TNT_EOK) goto out; + t->connected = 1; return TNT_EOK; out: tnt_io_close(t); @@ -243,9 +248,9 @@ tnt_io_connect(struct tnt *t, char *host, int port) void tnt_io_close(struct tnt *t) { - if (t->fd >= 0) { + if (t->fd > 0) { close(t->fd); - t->fd = -1; + t->fd = 0; } t->connected = 0; }