Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / optname.c
blobb7ecc8e7d3b4dec6039be3f2d5a9ad14add75311
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2000-2001 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: optname.c,v 1.3.4.1 2006/06/16 17:21:07 darrenr Exp
9 */
11 #include "ipf.h"
14 u_32_t optname(cp, sp, linenum)
15 char ***cp;
16 u_short *sp;
17 int linenum;
19 struct ipopt_names *io, *so;
20 u_long msk = 0;
21 u_short smsk = 0;
22 char *s;
23 int sec = 0;
25 for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) {
26 for (io = ionames; io->on_name; io++)
27 if (!strcasecmp(s, io->on_name)) {
28 msk |= io->on_bit;
29 break;
31 if (!io->on_name) {
32 fprintf(stderr, "%d: unknown IP option name %s\n",
33 linenum, s);
34 return 0;
36 if (!strcasecmp(s, "sec-class"))
37 sec = 1;
40 if (sec && !*(*cp + 1)) {
41 fprintf(stderr, "%d: missing security level after sec-class\n",
42 linenum);
43 return 0;
46 if (sec) {
47 (*cp)++;
48 for (s = strtok(**cp, ","); s; s = strtok(NULL, ",")) {
49 for (so = secclass; so->on_name; so++)
50 if (!strcasecmp(s, so->on_name)) {
51 smsk |= so->on_bit;
52 break;
54 if (!so->on_name) {
55 fprintf(stderr,
56 "%d: no such security level: %s\n",
57 linenum, s);
58 return 0;
61 if (smsk)
62 *sp = smsk;
64 return msk;