MCPcopy Index your code
hub / github.com/F-Stack/f-stack / ngctl

Function ngctl

tools/libnetgraph/compat.c:38–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36#include "netgraph.h"
37
38static int
39ngctl(int cmd, void *data, size_t len)
40{
41 struct ff_msg *msg, *retmsg = NULL;
42
43 msg = ff_ipc_msg_alloc();
44 if (msg == NULL) {
45 errno = ENOMEM;
46 return -1;
47 }
48
49 if (len > msg->buf_len) {
50 errno = EINVAL;
51 ff_ipc_msg_free(msg);
52 return -1;
53 }
54
55 msg->msg_type = FF_NGCTL;
56 msg->ngctl.cmd = cmd;
57 msg->ngctl.data = msg->buf_addr;
58
59 switch (cmd) {
60 case NGCTL_SOCKET:
61 case NGCTL_CLOSE:
62 memcpy(msg->ngctl.data, data, len);
63 break;
64 case NGCTL_BIND:
65 case NGCTL_CONNECT:
66 {
67 struct bind_args *src = (struct bind_args *)data;
68 struct bind_args *dst = (struct bind_args *)(msg->ngctl.data);
69 dst->s = src->s;
70 dst->name = (char *)msg->buf_addr + sizeof(struct bind_args);
71 dst->namelen = src->namelen;
72 memcpy(dst->name, src->name, src->namelen);
73 break;
74 }
75 case NGCTL_SEND:
76 {
77 struct sendto_args *src = (struct sendto_args *)data;
78 struct sendto_args *dst = (struct sendto_args *)(msg->ngctl.data);
79 dst->s = src->s;
80 dst->buf = (char *)msg->buf_addr + sizeof(struct sendto_args);
81 dst->len = src->len;
82 dst->flags = src->flags;
83 dst->to = dst->buf + src->len;
84 dst->tolen = src->tolen;
85 memcpy(dst->buf, src->buf, src->len);
86 memcpy(dst->to, src->to, src->tolen);
87 break;
88 }
89 case NGCTL_RECV:
90 {
91 struct recvfrom_args *src = (struct recvfrom_args *)data;
92 struct recvfrom_args *dst = (struct recvfrom_args *)(msg->ngctl.data);
93 dst->s = src->s;
94 dst->buf = msg->buf_addr + sizeof(struct recvfrom_args);
95 dst->len = src->len;

Callers 6

ng_socketFunction · 0.85
ng_bindFunction · 0.85
ng_connectFunction · 0.85
ng_sendtoFunction · 0.85
ng_recvfromFunction · 0.85
ng_closeFunction · 0.85

Calls 5

ff_ipc_msg_allocFunction · 0.85
ff_ipc_msg_freeFunction · 0.85
ff_ipc_sendFunction · 0.85
ff_ipc_recvFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected