Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / ipf_dotuning.c
blob5d4bb73c596991ab002975457cb7ae2e6d8f7340
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2003-2005 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: ipf_dotuning.c,v 1.2.4.3 2006/06/16 17:21:02 darrenr Exp
9 */
11 #include "ipf.h"
12 #include "netinet/ipl.h"
13 #include <sys/ioctl.h>
15 void ipf_dotuning(fd, tuneargs, iocfn)
16 int fd;
17 char *tuneargs;
18 ioctlfunc_t iocfn;
20 ipfobj_t obj;
21 ipftune_t tu;
22 char *s, *t;
24 bzero((char *)&tu, sizeof(tu));
25 obj.ipfo_rev = IPFILTER_VERSION;
26 obj.ipfo_size = sizeof(tu);;
27 obj.ipfo_ptr = (void *)&tu;
28 obj.ipfo_type = IPFOBJ_TUNEABLE;
30 for (s = strtok(tuneargs, ","); s != NULL; s = strtok(NULL, ",")) {
31 if (!strcmp(s, "list")) {
32 while (1) {
33 if ((*iocfn)(fd, SIOCIPFGETNEXT, &obj) == -1) {
34 perror("ioctl(SIOCIPFGETNEXT)");
35 break;
37 if (tu.ipft_cookie == NULL)
38 break;
40 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
41 printtunable(&tu);
43 } else if ((t = strchr(s, '=')) != NULL) {
44 tu.ipft_cookie = NULL;
45 *t++ = '\0';
46 strncpy(tu.ipft_name, s, sizeof(tu.ipft_name));
47 if (sscanf(t, "%lu", &tu.ipft_vlong) == 1) {
48 if ((*iocfn)(fd, SIOCIPFSET, &obj) == -1) {
49 perror("ioctl(SIOCIPFSET)");
50 return;
52 } else {
53 fprintf(stderr, "invalid value '%s'\n", s);
54 return;
56 } else {
57 tu.ipft_cookie = NULL;
58 strncpy(tu.ipft_name, s, sizeof(tu.ipft_name));
59 if ((*iocfn)(fd, SIOCIPFGET, &obj) == -1) {
60 perror("ioctl(SIOCIPFGET)");
61 return;
63 if (tu.ipft_cookie == NULL) {
64 fprintf(stderr, "Null cookie for %s\n", s);
65 return;
68 tu.ipft_name[sizeof(tu.ipft_name) - 1] = '\0';
69 printtunable(&tu);