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

Function ipfw_ctl

tools/ipfw/compat.c:35–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33#include "ff_ipc.h"
34
35static int
36ipfw_ctl(int cmd, int level, int optname, void *optval, socklen_t *optlen)
37{
38 struct ff_msg *msg, *retmsg = NULL;
39 int len;
40
41 switch (cmd) {
42 case FF_IPFW_GET:
43 if (optval == NULL || optlen == NULL) {
44 return EINVAL;
45 }
46 break;
47 case FF_IPFW_SET:
48 break;
49 default:
50 return EINVAL;
51 }
52
53 msg = ff_ipc_msg_alloc();
54 if (msg == NULL) {
55 errno = ENOMEM;
56 return -1;
57 }
58
59 len = sizeof(struct ff_ipfw_args) + *optlen + sizeof(socklen_t);
60 if (len > msg->buf_len) {
61 errno = EINVAL;
62 ff_ipc_msg_free(msg);
63 return -1;
64 }
65
66 msg->msg_type = FF_IPFW_CTL;
67 msg->ipfw.cmd = cmd;
68 msg->ipfw.level = level;
69 msg->ipfw.optname = optname;
70 msg->ipfw.optval = (void *)msg->buf_addr;
71 msg->ipfw.optlen = (socklen_t *)(msg->buf_addr + (*optlen));
72
73 memcpy(msg->ipfw.optval, optval, *optlen);
74 memcpy(msg->ipfw.optlen, optlen, sizeof(socklen_t));
75
76 int ret = ff_ipc_send(msg);
77 if (ret < 0) {
78 errno = EPIPE;
79 ff_ipc_msg_free(msg);
80 return -1;
81 }
82
83 do {
84 if (retmsg != NULL) {
85 ff_ipc_msg_free(retmsg);
86 }
87 ret = ff_ipc_recv(&retmsg, msg->msg_type);
88 if (ret < 0) {
89 errno = EPIPE;
90 return -1;
91 }
92 } while (msg != retmsg);

Callers 2

ff_getsockoptFunction · 0.70
ff_setsockoptFunction · 0.70

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