--- libaitrpc/src/cli.c 2016/08/02 10:26:58 1.26.4.2 +++ libaitrpc/src/cli.c 2016/08/02 12:00:39 1.26.4.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.26.4.2 2016/08/02 10:26:58 misho Exp $ +* $Id: cli.c,v 1.26.4.3 2016/08/02 12:00:39 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -161,6 +161,7 @@ rpc_cli_openClient(u_char InstID, int netBuf, const ch int n = 1; rpc_cli_t *cli = NULL; sockaddr_t sa = E_SOCKADDR_INIT; + socklen_t salen; if (proto < 0 || proto > SOCK_RAW) { rpc_SetErr(EINVAL, "Invalid parameters can`t open RPC client"); @@ -171,7 +172,7 @@ rpc_cli_openClient(u_char InstID, int netBuf, const ch if (!Port && proto < SOCK_RAW) Port = RPC_DEFPORT; - if (!e_gethostbyname(csHost, Port, &sa)) + if (!(salen = e_gethostbyname(csHost, Port, &sa))) return NULL; if (!proto) proto = SOCK_STREAM; @@ -221,7 +222,7 @@ rpc_cli_openClient(u_char InstID, int netBuf, const ch } if (cli->cli_id == SOCK_STREAM) { setsockopt(cli->cli_sock, IPPROTO_TCP, TCP_NODELAY, &n, sizeof n); - if (connect(cli->cli_sock, &cli->cli_sa.sa, sizeof cli->cli_sa.sa) == -1) { + if (connect(cli->cli_sock, &cli->cli_sa.sa, salen) == -1) { LOGERR; goto err; } @@ -229,9 +230,9 @@ rpc_cli_openClient(u_char InstID, int netBuf, const ch if (cli->cli_id == SOCK_DGRAM) { sockaddr_t sa2; - if (!e_gethostbyname(csHost, 0, &sa2)) + if (!(salen = e_gethostbyname(csHost, 0, &sa2))) goto err; - if (bind(cli->cli_sock, &sa2.sa, sizeof sa2.sa) == -1) { + if (bind(cli->cli_sock, &sa2.sa, salen) == -1) { LOGERR; goto err; } @@ -298,7 +299,7 @@ rpc_cli_reconnectClient(rpc_cli_t * __restrict cli) return -1; } if (cli->cli_id == SOCK_STREAM) - if (connect(cli->cli_sock, &cli->cli_sa.sa, sizeof cli->cli_sa.sa) == -1) { + if (connect(cli->cli_sock, &cli->cli_sa.sa, e_addrlen(&cli->cli_sa)) == -1) { LOGERR; close(cli->cli_sock); return -1;