--- libaitrpc/src/cli.c 2013/09/05 00:43:05 1.19 +++ libaitrpc/src/cli.c 2013/11/15 09:55:53 1.20 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.19 2013/09/05 00:43:05 misho Exp $ +* $Id: cli.c,v 1.20 2013/11/15 09:55:53 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -295,22 +295,22 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res if (!pkt) { rpc_SetErr(EINVAL, "Invalid argument(s)!"); return -1; - } else + } else { buf = AIT_GET_BUF(pkt); + rpc = (struct tagRPCCall*) buf; + } /* reply from RPC server */ do { if (type == SOCK_STREAM) ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, NULL, buf, blen); else - ret = rpc_Read(sock, type, 0, sa, buf, AIT_LEN(pkt)); - if (ret < 1) { - LOGERR; + ret = rpc_Read(sock, type, !estlen ? MSG_PEEK : 0, sa, buf, blen); + if (ret < 1) return -1; - } /* check for response from known address */ - if (type == SOCK_STREAM && !estlen) { + if (!estlen) { /* 1st read for RPC header */ if (ret < sizeof(struct tagRPCCall)) { rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); @@ -318,13 +318,12 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res } /* calc estimated length */ - rpc = (struct tagRPCCall*) buf; estlen = ntohl(rpc->call_len); if (estlen > AIT_LEN(pkt)) AIT_RE_BUF(pkt, estlen); buf = AIT_GET_BUF(pkt); - blen = estlen; rpc = (struct tagRPCCall*) buf; + blen = estlen; continue; } @@ -332,8 +331,9 @@ rpc_pkt_Receive(int sock, int type, sockaddr_t * __res break; } while (42); - if (ret < sizeof(struct tagRPCCall)) { - rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); + if (ret < sizeof(struct tagRPCCall) || estlen != ret) { + rpc_SetErr(ERPCMISMATCH, "RPC packet mismatch estimate %d bytes, but received %d\n", + estlen, ret); return -1; }