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

Function NgRecvMsg

tools/libnetgraph/msg.c:296–329  ·  view source on GitHub ↗

* Receive a control message. * * On error, this returns -1 and sets errno. * Otherwise, it returns the length of the received reply. */

Source from the content-addressed store, hash-verified

294 * Otherwise, it returns the length of the received reply.
295 */
296int
297NgRecvMsg(int cs, struct ng_mesg *rep, size_t replen, char *path)
298{
299 u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD];
300 struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
301 socklen_t sglen = sizeof(sgbuf);
302 int len, errnosv;
303
304 /* Read reply */
305 len = recvfrom(cs, rep, replen, 0, (struct sockaddr *) sg, &sglen);
306 if (len < 0) {
307 errnosv = errno;
308 if (_gNgDebugLevel >= 1)
309 NGLOG("recvfrom");
310 goto errout;
311 }
312 if (path != NULL)
313 strlcpy(path, sg->sg_data, NG_PATHSIZ);
314
315 /* Debugging */
316 if (_gNgDebugLevel >= 2) {
317 NGLOGX("RECEIVED %s:",
318 (rep->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE");
319 _NgDebugSockaddr(sg);
320 _NgDebugMsg(rep, sg->sg_data);
321 }
322
323 /* Done */
324 return (len);
325
326errout:
327 errno = errnosv;
328 return (-1);
329}
330
331/*
332 * Identical to NgRecvMsg() except buffer is dynamically allocated.

Callers 7

NgAllocRecvMsgFunction · 0.85
NgRecvAsciiMsgFunction · 0.85
NgMkSockNodeFunction · 0.85
_NgDebugMsgFunction · 0.85
netgraphprotoprFunction · 0.85
ConfigCmdFunction · 0.85
StatusCmdFunction · 0.85

Calls 4

recvfromFunction · 0.85
_NgDebugSockaddrFunction · 0.85
_NgDebugMsgFunction · 0.85
strlcpyFunction · 0.50

Tested by

no test coverage detected