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

Function file

tools/arp/arp.c:260–293  ·  view source on GitHub ↗

* Process a file to set standard arp entries */

Source from the content-addressed store, hash-verified

258 * Process a file to set standard arp entries
259 */
260static int
261file(char *name)
262{
263 FILE *fp;
264 int i, retval;
265 char line[100], arg[5][50], *args[5], *p;
266
267 if ((fp = fopen(name, "r")) == NULL)
268 xo_err(1, "cannot open %s", name);
269 args[0] = &arg[0][0];
270 args[1] = &arg[1][0];
271 args[2] = &arg[2][0];
272 args[3] = &arg[3][0];
273 args[4] = &arg[4][0];
274 retval = 0;
275 while(fgets(line, sizeof(line), fp) != NULL) {
276 if ((p = strchr(line, '#')) != NULL)
277 *p = '\0';
278 for (p = line; isblank(*p); p++);
279 if (*p == '\n' || *p == '\0')
280 continue;
281 i = sscanf(p, "%49s %49s %49s %49s %49s", arg[0], arg[1],
282 arg[2], arg[3], arg[4]);
283 if (i < 2) {
284 xo_warnx("bad line: %s", line);
285 retval = 1;
286 continue;
287 }
288 if (set(i, args))
289 retval = 1;
290 }
291 fclose(fp);
292 return (retval);
293}
294
295/*
296 * Given a hostname, fills up a (static) struct sockaddr_in with

Callers 1

mainFunction · 0.70

Calls 6

xo_errFunction · 0.85
strchrFunction · 0.85
isblankFunction · 0.85
sscanfFunction · 0.85
xo_warnxFunction · 0.85
setFunction · 0.70

Tested by

no test coverage detected