MCPcopy Create free account
hub / github.com/F-Stack/f-stack / NgRecvAsciiMsg

Function NgRecvAsciiMsg

tools/libnetgraph/msg.c:357–397  ·  view source on GitHub ↗

* Receive a control message and convert the arguments to ASCII */

Source from the content-addressed store, hash-verified

355 * Receive a control message and convert the arguments to ASCII
356 */
357int
358NgRecvAsciiMsg(int cs, struct ng_mesg *reply, size_t replen, char *path)
359{
360 struct ng_mesg *msg, *ascii;
361 int bufSize, errnosv;
362 u_char *buf;
363
364 /* Allocate buffer */
365 bufSize = 2 * sizeof(*reply) + replen;
366 if ((buf = malloc(bufSize)) == NULL)
367 return (-1);
368 msg = (struct ng_mesg *)buf;
369 ascii = (struct ng_mesg *)msg->data;
370
371 /* Get binary message */
372 if (NgRecvMsg(cs, msg, bufSize, path) < 0)
373 goto fail;
374 memcpy(reply, msg, sizeof(*msg));
375
376 /* Ask originating node to convert the arguments to ASCII */
377 if (NgSendMsg(cs, path, NGM_GENERIC_COOKIE,
378 NGM_BINARY2ASCII, msg, sizeof(*msg) + msg->header.arglen) < 0)
379 goto fail;
380 if (NgRecvMsg(cs, msg, bufSize, NULL) < 0)
381 goto fail;
382
383 /* Copy result to client buffer */
384 if (sizeof(*ascii) + ascii->header.arglen > replen) {
385 errno = ERANGE;
386fail:
387 errnosv = errno;
388 free(buf);
389 errno = errnosv;
390 return (-1);
391 }
392 strncpy(reply->data, ascii->data, ascii->header.arglen);
393
394 /* Done */
395 free(buf);
396 return (0);
397}
398
399/*
400 * Identical to NgRecvAsciiMsg() except buffer is dynamically allocated.

Callers 1

NgAllocRecvAsciiMsgFunction · 0.85

Calls 6

mallocFunction · 0.85
NgRecvMsgFunction · 0.85
NgSendMsgFunction · 0.85
strncpyFunction · 0.85
memcpyFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected