| 
 |   
| version 1.16.8.1, 2013/08/21 22:34:18 | version 1.16.8.3, 2013/08/22 11:52:20 | 
|---|---|
| Line 172 rpc_cli_openClient(u_char InstID, int netBuf, const ch | Line 172 rpc_cli_openClient(u_char InstID, int netBuf, const ch | 
| else | else | 
| netBuf = E_ALIGN(netBuf, 2); /* align netBuf length */ | netBuf = E_ALIGN(netBuf, 2); /* align netBuf length */ | 
| #ifdef HAVE_SRANDOMDEV | |
| srandomdev(); | |
| #else | |
| time_t tim; | |
| srandom((time(&tim) ^ getpid())); | |
| #endif | |
| cli = e_malloc(sizeof(rpc_cli_t)); | cli = e_malloc(sizeof(rpc_cli_t)); | 
| if (!cli) { | if (!cli) { | 
| LOGERR; | LOGERR; | 
| Line 330 int | Line 322 int | 
| rpc_pkt_Receive(int sock, int type, sockaddr_t * __restrict sa, ait_val_t * __restrict pkt) | rpc_pkt_Receive(int sock, int type, sockaddr_t * __restrict sa, ait_val_t * __restrict pkt) | 
| { | { | 
| struct pollfd pfd; | struct pollfd pfd; | 
| int ret, len = 0; | int ret, estlen, blen = sizeof(struct tagRPCCall), len = 0; | 
| u_char *buf; | u_char *buf; | 
| sockaddr_t sa2; | sockaddr_t sa2; | 
| socklen_t salen; | socklen_t salen; | 
| struct tagRPCCall *rpc; | |
| if (!pkt) { | if (!pkt) { | 
| rpc_SetErr(EINVAL, "Invalid argument(s)!"); | rpc_SetErr(EINVAL, "Invalid argument(s)!"); | 
| Line 360 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res | Line 353 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res | 
| return -1; | return -1; | 
| } | } | 
| memset(buf, 0, AIT_LEN(pkt)); | if (type == SOCK_STREAM) { | 
| if (type == SOCK_STREAM) | memset(buf, 0, blen); | 
| ret = recv(sock, buf, AIT_LEN(pkt), 0); | ret = recv(sock, buf, blen, 0); | 
| else { | } else { | 
| blen = AIT_LEN(pkt); | |
| memset(buf, 0, blen); | |
| memset(&sa2, 0, sizeof sa2); | memset(&sa2, 0, sizeof sa2); | 
| salen = sa2.ss.ss_len = sizeof(sockaddr_t); | salen = sa2.ss.ss_len = sizeof(sockaddr_t); | 
| ret = recvfrom(sock, buf, AIT_LEN(pkt), 0, &sa2.sa, &salen); | ret = recvfrom(sock, buf, blen, 0, &sa2.sa, &salen); | 
| } | } | 
| if (ret < 1) { | if (ret < 1) { | 
| if (ret) { | if (ret) { | 
| Line 379 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res | Line 374 rpc_pkt_Receive(int sock, int type, sockaddr_t * __res | 
| } | } | 
| /* check for response from known address */ | /* check for response from known address */ | 
| if (type == SOCK_DGRAM) | if (type == SOCK_DGRAM) { | 
| if (e_addrcmp(sa, &sa2, 42)) { | if (e_addrcmp(sa, &sa2, 42)) { | 
| rpc_SetErr(ERPCMISMATCH, | rpc_SetErr(ERPCMISMATCH, | 
| "Received RPC response from unknown address"); | "Received RPC response from unknown address"); | 
| continue; | continue; | 
| } | } | 
| } else { | |
| /* 1st read for RPC header */ | |
| if (buf == AIT_GET_BUF(pkt)) { | |
| if (ret < sizeof(struct tagRPCCall)) { | |
| rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); | |
| return -1; | |
| } | |
| /* calc estimated length */ | |
| rpc = (struct tagRPCCall*) buf; | |
| estlen = ntohs(rpc->call_len) + blen; | |
| printf("ret = %d len=%d\n", ret, estlen); | |
| if (estlen > AIT_LEN(pkt)) | |
| AIT_RE_BUF(pkt, estlen); | |
| buf = AIT_GET_BUF(pkt) + blen; | |
| blen = AIT_LEN(pkt) - blen; | |
| } else | |
| ret += sizeof(struct tagRPCCall); | |
| } | |
| } while (0); | } while (0); | 
| if (ret < sizeof(struct tagRPCCall)) { | if (ret < sizeof(struct tagRPCCall)) { | 
| rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); | rpc_SetErr(ERPCMISMATCH, "Short RPC packet %d bytes", ret); | 
| return -1; | return -1; | 
| Line 410 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t | Line 425 rpc_pkt_Request(ait_val_t * __restrict pkt, rpc_sess_t | 
| array_t * __restrict vars, int noreply, int nocrc) | array_t * __restrict vars, int noreply, int nocrc) | 
| { | { | 
| struct tagRPCCall *rpc; | struct tagRPCCall *rpc; | 
| int ret = 0, len = sizeof(struct tagRPCCall); | int ret = 0, estlen, len = sizeof(struct tagRPCCall); | 
| u_char *buf; | u_char *buf; | 
| if (!pkt || !sess) { | if (!pkt || !sess) { | 
| rpc_SetErr(EINVAL, "Invalid argument(s)!"); | rpc_SetErr(EINVAL, "Invalid argument(s)!"); | 
| return -1; | return -1; | 
| } else | } | 
| buf = AIT_GET_BUF(pkt); | |
| /* calc estimated length */ | |
| estlen = ait_resideVars(vars) + len; | |
| if (estlen > AIT_LEN(pkt)) | |
| AIT_RE_BUF(pkt, estlen); | |
| buf = AIT_GET_BUF(pkt); | |
| /* prepare RPC call */ | /* prepare RPC call */ | 
| rpc = (struct tagRPCCall*) buf; | rpc = (struct tagRPCCall*) buf; |