--- libaitrpc/src/cli.c 2012/05/14 08:39:05 1.9 +++ libaitrpc/src/cli.c 2012/05/15 16:06:13 1.9.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.9 2012/05/14 08:39:05 misho Exp $ +* $Id: cli.c,v 1.9.2.3 2012/05/15 16:06:13 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -60,9 +60,7 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, io_sockaddr_t sa; int n; - if (!rpccli || - (rpccli->cli_sa.sa.sa_family != AF_INET && rpccli->cli_sa.sa.sa_family != AF_INET6 && - rpccli->cli_sa.sa.sa_family != AF_LOCAL)) { + if (!rpccli) { rpc_SetErr(EINVAL, "Invalid parameters can`t connect to BLOB server"); return NULL; } @@ -85,6 +83,9 @@ rpc_cli_openBLOBClient(rpc_cli_t * __restrict rpccli, case AF_LOCAL: strlcat(sa.sun.sun_path, ".blob", sizeof sa.sun.sun_path); break; + default: + rpc_SetErr(EINVAL, "Invalid socket type %d", sa.sa.sa_family); + return NULL; } memcpy(&cli->cli_sa, &sa, sizeof sa); @@ -158,51 +159,17 @@ rpc_cli_openClient(u_int ProgID, u_int ProcID, int net u_short family, const char *csHost, u_short Port) { rpc_cli_t *cli = NULL; - struct hostent *host = NULL; io_sockaddr_t sa; int n; - if (!csHost || (family != AF_INET && family != AF_INET6 && family != AF_LOCAL)) { - rpc_SetErr(EINVAL, "Invalid parameters can`t connect to RPC server ..."); + if (!io_gethostbyname(csHost, Port, &sa)) return NULL; - } if (!Port) Port = RPC_DEFPORT; if (!netBuf) netBuf = BUFSIZ; if (!Timeout) Timeout = DEF_RPC_TIMEOUT; - if (csHost && family != AF_LOCAL) { - host = gethostbyname2(csHost, family); - if (!host) { - rpc_SetErr(h_errno, "%s", hstrerror(h_errno)); - return NULL; - } - } - memset(&sa, 0, sizeof sa); - sa.sa.sa_family = family; - switch (family) { - case AF_INET: - sa.sin.sin_len = sizeof(struct sockaddr_in); - sa.sin.sin_port = htons(Port); - if (csHost) - memcpy(&sa.sin.sin_addr, host->h_addr, host->h_length); - break; - case AF_INET6: - sa.sin6.sin6_len = sizeof(struct sockaddr_in6); - sa.sin6.sin6_port = htons(Port); - if (csHost) - memcpy(&sa.sin6.sin6_addr, host->h_addr, host->h_length); - break; - case AF_LOCAL: - sa.sun.sun_len = sizeof(struct sockaddr_un); - if (csHost) - strlcpy(sa.sun.sun_path, csHost, sizeof sa.sun.sun_path); - break; - default: - rpc_SetErr(EINVAL, "Invalid parameters can`t connect to RPC server ..."); - return NULL; - } cli = malloc(sizeof(rpc_cli_t)); if (!cli) { @@ -227,7 +194,7 @@ rpc_cli_openClient(u_int ProgID, u_int ProcID, int net memcpy(&cli->cli_sa, &sa, sizeof cli->cli_sa); /* connect to RPC server */ - cli->cli_sock = socket(family, SOCK_STREAM, 0); + cli->cli_sock = socket(cli->cli_sa.sa.sa_family, SOCK_STREAM, 0); if (cli->cli_sock == -1) { LOGERR; free(cli->cli_parent);