* Receive a control message. * * On error, this returns -1 and sets errno. * Otherwise, it returns the length of the received reply. */
| 294 | * Otherwise, it returns the length of the received reply. |
| 295 | */ |
| 296 | int |
| 297 | NgRecvMsg(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 | |
| 326 | errout: |
| 327 | errno = errnosv; |
| 328 | return (-1); |
| 329 | } |
| 330 | |
| 331 | /* |
| 332 | * Identical to NgRecvMsg() except buffer is dynamically allocated. |
no test coverage detected