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

Function NgDeliverMsg

tools/libnetgraph/msg.c:203–288  ·  view source on GitHub ↗

* Send a message to a node using control socket node "cs". * Returns -1 if error and sets errno appropriately, otherwise zero. */

Source from the content-addressed store, hash-verified

201 * Returns -1 if error and sets errno appropriately, otherwise zero.
202 */
203static int
204NgDeliverMsg(int cs, const char *path,
205 const struct ng_mesg *hdr, const void *args, size_t arglen)
206{
207 u_char sgbuf[NG_PATHSIZ + NGSA_OVERHEAD];
208 struct sockaddr_ng *const sg = (struct sockaddr_ng *) sgbuf;
209 u_char *buf = NULL;
210 struct ng_mesg *msg;
211 int errnosv = 0;
212 int rtn = 0;
213
214 /* Sanity check */
215 if (args == NULL)
216 arglen = 0;
217
218 /* Get buffer */
219 if ((buf = malloc(sizeof(*msg) + arglen)) == NULL) {
220 errnosv = errno;
221 if (_gNgDebugLevel >= 1)
222 NGLOG("malloc");
223 rtn = -1;
224 goto done;
225 }
226 msg = (struct ng_mesg *) buf;
227
228 /* Finalize message */
229 *msg = *hdr;
230 msg->header.arglen = arglen;
231 memcpy(msg->data, args, arglen);
232
233 /* Prepare socket address */
234 sg->sg_family = AF_NETGRAPH;
235 /* XXX handle overflow */
236#if __GNUC__ >= 13
237#pragma GCC diagnostic push
238#pragma GCC diagnostic ignored "-Wstringop-overflow"
239#endif
240 strncpy(sg->sg_data, path, NG_PATHSIZ);
241#if __GNUC__ >= 13
242#pragma GCC diagnostic pop
243#endif
244 sg->sg_len = strlen(sg->sg_data) + 1 + NGSA_OVERHEAD;
245
246 /* Debugging */
247 if (_gNgDebugLevel >= 2) {
248 NGLOGX("SENDING %s:",
249 (msg->header.flags & NGF_RESP) ? "RESPONSE" : "MESSAGE");
250 _NgDebugSockaddr(sg);
251 _NgDebugMsg(msg, sg->sg_data);
252 }
253
254 /* Send it */
255 if (sendto(cs, msg, sizeof(*msg) + arglen,
256 0, (struct sockaddr *) sg, sg->sg_len) < 0) {
257 errnosv = errno;
258 if (_gNgDebugLevel >= 1)
259 NGLOG("sendto(%s)", sg->sg_data);
260 rtn = -1;

Callers 3

NgSendMsgFunction · 0.85
NgSendAsciiMsgFunction · 0.85
NgSendReplyMsgFunction · 0.85

Calls 7

mallocFunction · 0.85
strncpyFunction · 0.85
_NgDebugSockaddrFunction · 0.85
_NgDebugMsgFunction · 0.85
memcpyFunction · 0.50
sendtoFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected