--- libaitrpc/src/cli.c 2015/07/02 22:28:15 1.26 +++ libaitrpc/src/cli.c 2016/08/08 13:21:13 1.27 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.26 2015/07/02 22:28:15 misho Exp $ +* $Id: cli.c,v 1.27 2016/08/08 13:21:13 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2015 +Copyright 2004 - 2016 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -71,7 +71,7 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, } else memcpy(cli, rpccli, sizeof(rpc_cli_t)); - memcpy(&cli->cli_sa, &rpccli->cli_sa, sizeof(sockaddr_t)); + memcpy(&cli->cli_sa, &rpccli->cli_sa, sizeof cli->cli_sa); switch (cli->cli_sa.sa.sa_family) { case AF_INET: cli->cli_sa.sin.sin_port = @@ -111,7 +111,7 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, e_free(cli); return NULL; } - if (connect(cli->cli_sock, &cli->cli_sa.sa, cli->cli_sa.sa.sa_len) == -1) { + if (connect(cli->cli_sock, &cli->cli_sa.sa, e_addrlen(&cli->cli_sa)) == -1) { LOGERR; close(cli->cli_sock); e_free(cli); @@ -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, cli->cli_sa.sa.sa_len) == -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, sa2.sa.sa_len) == -1) { + if (bind(cli->cli_sock, &sa2.sa, salen) == -1) { LOGERR; goto err; } @@ -268,9 +269,11 @@ rpc_cli_reconnectClient(rpc_cli_t * __restrict cli) shutdown(cli->cli_sock, SHUT_RDWR); if (cli->cli_id == SOCK_DGRAM && cli->cli_sa.sa.sa_family == AF_LOCAL) { sockaddr_t sa2 = E_SOCKADDR_INIT; - socklen_t salen; + socklen_t salen = sizeof sa2; - sa2.sa.sa_len = salen = sizeof sa2; +#ifndef __linux__ + sa2.sa.sa_len = salen; +#endif if (!getsockname(cli->cli_sock, &sa2.sa, &salen)) unlink(sa2.sun.sun_path); } @@ -296,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, cli->cli_sa.sa.sa_len) == -1) { + if (connect(cli->cli_sock, &cli->cli_sa.sa, e_addrlen(&cli->cli_sa)) == -1) { LOGERR; close(cli->cli_sock); return -1; @@ -322,9 +325,11 @@ rpc_cli_closeClient(rpc_cli_t ** __restrict cli) shutdown((*cli)->cli_sock, SHUT_RDWR); if ((*cli)->cli_id == SOCK_DGRAM && (*cli)->cli_sa.sa.sa_family == AF_LOCAL) { sockaddr_t sa2 = E_SOCKADDR_INIT; - socklen_t salen; + socklen_t salen = sizeof sa2; - sa2.sa.sa_len = salen = sizeof sa2; +#ifndef __linux__ + sa2.sa.sa_len = salen; +#endif if (!getsockname((*cli)->cli_sock, &sa2.sa, &salen)) unlink(sa2.sun.sun_path); } @@ -570,7 +575,6 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short array_t * __restrict in_vars, array_t ** __restrict out_vars) { int type = 0, wlen; - u_char *buf; u_int seq = 0; if (!cli) { @@ -581,7 +585,6 @@ rpc_cli_execCall(rpc_cli_t *cli, int noreply, u_short type = cli->cli_id; else seq = random(); /* sign package */ - buf = AIT_GET_BUF(&cli->cli_buf); } if (out_vars) *out_vars = NULL; @@ -665,6 +668,7 @@ rpc_cli_ping(rpc_cli_t *cli) rpc_cli_t * rpc_cli_openClient2(u_char InstID, int netBuf, const char *csIface, const char *csHost) { +#ifndef __linux__ rpc_cli_t *cli = NULL; sockaddr_t sa = E_SOCKADDR_INIT, sal = E_SOCKADDR_INIT; char szIface[64], szStr[STRSIZ]; @@ -759,6 +763,9 @@ err: close(cli->cli_sock); e_free(cli->cli_parent); e_free(cli); +#else + rpc_SetErr(ENOTSUP, "Feature isn't supported on Linux!"); +#endif return NULL; }