msg.c (e551a1c3c28a1bbe9e994eb002f01dc0f2d75b99) | msg.c (b92367948a1777de80dd7ee31a15a90df0b727bf) |
---|---|
1/* 2 * msg.c 3 * 4 * Copyright (c) 1996-1999 Whistle Communications, Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 62 unchanged lines hidden (view full) --- 71 memset(&msg, 0, sizeof(msg)); 72 msg.header.version = NG_VERSION; 73 msg.header.typecookie = cookie; 74 if (++gMsgId < 0) 75 gMsgId = 1; 76 msg.header.token = gMsgId; 77 msg.header.flags = NGF_ORIG; 78 msg.header.cmd = cmd; | 1/* 2 * msg.c 3 * 4 * Copyright (c) 1996-1999 Whistle Communications, Inc. 5 * All rights reserved. 6 * 7 * Subject to the following obligations and disclaimer of warranty, use and 8 * redistribution of this software, in source or object code forms, with or --- 62 unchanged lines hidden (view full) --- 71 memset(&msg, 0, sizeof(msg)); 72 msg.header.version = NG_VERSION; 73 msg.header.typecookie = cookie; 74 if (++gMsgId < 0) 75 gMsgId = 1; 76 msg.header.token = gMsgId; 77 msg.header.flags = NGF_ORIG; 78 msg.header.cmd = cmd; |
79 snprintf(msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); | 79 snprintf((char *)msg.header.cmdstr, NG_CMDSTRSIZ, "cmd%d", cmd); |
80 81 /* Deliver message */ 82 if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0) 83 return (-1); 84 return (msg.header.token); 85} 86 87/* --- 29 unchanged lines hidden (view full) --- 117 if ((ascii = malloc(sizeof(struct ng_mesg) 118 + strlen(args) + 1)) == NULL) { 119 free(buf); 120 return (-1); 121 } 122 memset(ascii, 0, sizeof(*ascii)); 123 124 /* Build inner header (only need cmdstr, arglen, and data fields) */ | 80 81 /* Deliver message */ 82 if (NgDeliverMsg(cs, path, &msg, args, arglen) < 0) 83 return (-1); 84 return (msg.header.token); 85} 86 87/* --- 29 unchanged lines hidden (view full) --- 117 if ((ascii = malloc(sizeof(struct ng_mesg) 118 + strlen(args) + 1)) == NULL) { 119 free(buf); 120 return (-1); 121 } 122 memset(ascii, 0, sizeof(*ascii)); 123 124 /* Build inner header (only need cmdstr, arglen, and data fields) */ |
125 strncpy(ascii->header.cmdstr, cmd, sizeof(ascii->header.cmdstr) - 1); | 125 strncpy((char *)ascii->header.cmdstr, cmd, 126 sizeof(ascii->header.cmdstr) - 1); |
126 strcpy(ascii->data, args); 127 ascii->header.arglen = strlen(ascii->data) + 1; 128 free(buf); 129 130 /* Send node a request to convert ASCII to binary */ 131 if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, NGM_ASCII2BINARY, 132 (u_char *)ascii, sizeof(*ascii) + ascii->header.arglen) < 0) { 133 free(ascii); --- 110 unchanged lines hidden (view full) --- 244 * On error, this returns -1 and sets errno. 245 * Otherwise, it returns the length of the received reply. 246 */ 247int 248NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path) 249{ 250 u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD]; 251 struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf; | 127 strcpy(ascii->data, args); 128 ascii->header.arglen = strlen(ascii->data) + 1; 129 free(buf); 130 131 /* Send node a request to convert ASCII to binary */ 132 if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE, NGM_ASCII2BINARY, 133 (u_char *)ascii, sizeof(*ascii) + ascii->header.arglen) < 0) { 134 free(ascii); --- 110 unchanged lines hidden (view full) --- 245 * On error, this returns -1 and sets errno. 246 * Otherwise, it returns the length of the received reply. 247 */ 248int 249NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path) 250{ 251 u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD]; 252 struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf; |
252 int len, sglen = sizeof(sgbuf); 253 int errnosv; | 253 socklen_t sglen = sizeof(sgbuf); 254 int len, errnosv; |
254 255 /* Read reply */ 256 len = recvfrom(cs, rep, replen, 0, (struct sockaddr *) sg, &sglen); 257 if (len < 0) { 258 errnosv = errno; 259 if (_gNgDebugLevel >= 1) 260 NGLOG("recvfrom"); 261 goto errout; --- 100 unchanged lines hidden --- | 255 256 /* Read reply */ 257 len = recvfrom(cs, rep, replen, 0, (struct sockaddr *) sg, &sglen); 258 if (len < 0) { 259 errnosv = errno; 260 if (_gNgDebugLevel >= 1) 261 NGLOG("recvfrom"); 262 goto errout; --- 100 unchanged lines hidden --- |