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

Function printgroup

tools/ifconfig/ifgroup.c:137–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137static void
138printgroup(const char *groupname)
139{
140 struct ifgroupreq ifgr;
141 struct ifg_req *ifg;
142 int len, cnt = 0;
143 int s;
144
145 s = socket(AF_LOCAL, SOCK_DGRAM, 0);
146 if (s == -1)
147 err(1, "socket(AF_LOCAL,SOCK_DGRAM)");
148 bzero(&ifgr, sizeof(ifgr));
149 strlcpy(ifgr.ifgr_name, groupname, sizeof(ifgr.ifgr_name));
150 if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
151 if (errno == EINVAL || errno == ENOTTY ||
152 errno == ENOENT)
153#ifdef FSTACK
154 {
155 ff_ipc_exit();
156 exit(exit_code);
157 }
158#else
159 exit(exit_code);
160#endif
161 else
162 err(1, "SIOCGIFGMEMB");
163 }
164
165 len = ifgr.ifgr_len;
166 if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
167 err(1, "printgroup");
168
169#ifndef FSTACK
170 if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
171#else
172 size_t offset = (char *)&(ifgr.ifgr_groups) - (char *)&(ifgr);
173 size_t clen = len;
174 if (ioctl_va(s, SIOCGIFGMEMB, (caddr_t)&ifgr, 3, offset, ifgr.ifgr_groups, clen) == -1)
175#endif
176 err(1, "SIOCGIFGMEMB");
177
178 for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(struct ifg_req);
179 ifg++) {
180 len -= sizeof(struct ifg_req);
181 printf("%s\n", ifg->ifgrq_member);
182 cnt++;
183 }
184 free(ifgr.ifgr_groups);
185
186#ifdef FSTACK
187 ff_ipc_exit();
188#endif
189 exit(exit_code);
190}
191
192static struct cmd group_cmds[] = {
193 DEF_CMD_ARG("group", setifgroup),

Callers

nothing calls this directly

Calls 9

bzeroFunction · 0.85
ff_ipc_exitFunction · 0.85
callocFunction · 0.85
ioctl_vaFunction · 0.85
socketClass · 0.50
strlcpyFunction · 0.50
ioctlFunction · 0.50
printfFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected