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

Function NgSendData

tools/libnetgraph/sock.c:281–312  ·  view source on GitHub ↗

* Write a packet to a data socket. The packet will be sent * out the corresponding node on the specified hook. * Returns -1 if error and sets errno. */

Source from the content-addressed store, hash-verified

279 * Returns -1 if error and sets errno.
280 */
281int
282NgSendData(int ds, const char *hook, const u_char * buf, size_t len)
283{
284 u_char sgbuf[NG_HOOKSIZ + NGSA_OVERHEAD];
285 struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
286 int errnosv;
287
288 /* Set up destination hook */
289 sg->sg_family = AF_NETGRAPH;
290 strlcpy(sg->sg_data, hook, NG_HOOKSIZ);
291 sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
292
293 /* Debugging */
294 if (_gNgDebugLevel >= 2) {
295 NGLOGX("WRITE PACKET to hook \"%s\" (%d bytes)", hook, len);
296 _NgDebugSockaddr(sg);
297 if (_gNgDebugLevel >= 3)
298 _NgDebugBytes(buf, len);
299 }
300
301 /* Send packet */
302 if (sendto(ds, buf, len, 0, (struct sockaddr *) sg, sg->sg_len) < 0) {
303 errnosv = errno;
304 if (_gNgDebugLevel >= 1)
305 NGLOG("sendto(%s)", sg->sg_data);
306 errno = errnosv;
307 return (-1);
308 }
309
310 /* Done */
311 return (0);
312}
313

Callers

nothing calls this directly

Calls 4

_NgDebugSockaddrFunction · 0.85
_NgDebugBytesFunction · 0.85
strlcpyFunction · 0.50
sendtoFunction · 0.50

Tested by

no test coverage detected