Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / facpri.c
blob2c2fcb2f5bfe80302b95910afe5cef584d84b5e7
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2000-2006 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: facpri.c,v 1.6.2.5 2006/06/16 17:20:58 darrenr Exp
9 */
11 #include <stdio.h>
12 #include <string.h>
13 #include <limits.h>
14 #include <sys/types.h>
15 #if !defined(__SVR4) && !defined(__svr4__)
16 #include <strings.h>
17 #endif
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <stddef.h>
21 #include <syslog.h>
22 #include "facpri.h"
24 #if !defined(lint)
25 static const char rcsid[] = "@(#)Id: facpri.c,v 1.6.2.5 2006/06/16 17:20:58 darrenr Exp";
26 #endif
29 typedef struct table {
30 char *name;
31 int value;
32 } table_t;
34 table_t facs[] = {
35 { "kern", LOG_KERN }, { "user", LOG_USER },
36 { "mail", LOG_MAIL }, { "daemon", LOG_DAEMON },
37 { "auth", LOG_AUTH }, { "syslog", LOG_SYSLOG },
38 { "lpr", LOG_LPR }, { "news", LOG_NEWS },
39 { "uucp", LOG_UUCP },
40 #if LOG_CRON == LOG_CRON2
41 { "cron2", LOG_CRON1 },
42 #else
43 { "cron", LOG_CRON1 },
44 #endif
45 #ifdef LOG_FTP
46 { "ftp", LOG_FTP },
47 #endif
48 #ifdef LOG_AUTHPRIV
49 { "authpriv", LOG_AUTHPRIV },
50 #endif
51 #ifdef LOG_AUDIT
52 { "audit", LOG_AUDIT },
53 #endif
54 #ifdef LOG_LFMT
55 { "logalert", LOG_LFMT },
56 #endif
57 #if LOG_CRON == LOG_CRON1
58 { "cron", LOG_CRON2 },
59 #else
60 { "cron2", LOG_CRON2 },
61 #endif
62 #ifdef LOG_SECURITY
63 { "security", LOG_SECURITY },
64 #endif
65 { "local0", LOG_LOCAL0 }, { "local1", LOG_LOCAL1 },
66 { "local2", LOG_LOCAL2 }, { "local3", LOG_LOCAL3 },
67 { "local4", LOG_LOCAL4 }, { "local5", LOG_LOCAL5 },
68 { "local6", LOG_LOCAL6 }, { "local7", LOG_LOCAL7 },
69 { NULL, 0 }
74 * map a facility number to its name
76 char *
77 fac_toname(facpri)
78 int facpri;
80 int i, j, fac;
82 fac = facpri & LOG_FACMASK;
83 j = fac >> 3;
84 if (j < (sizeof(facs)/sizeof(facs[0]))) {
85 if (facs[j].value == fac)
86 return facs[j].name;
88 for (i = 0; facs[i].name; i++)
89 if (fac == facs[i].value)
90 return facs[i].name;
92 return NULL;
97 * map a facility name to its number
99 int
100 fac_findname(name)
101 char *name;
103 int i;
105 for (i = 0; facs[i].name; i++)
106 if (!strcmp(facs[i].name, name))
107 return facs[i].value;
108 return -1;
112 table_t pris[] = {
113 { "emerg", LOG_EMERG }, { "alert", LOG_ALERT },
114 { "crit", LOG_CRIT }, { "err", LOG_ERR },
115 { "warn", LOG_WARNING }, { "notice", LOG_NOTICE },
116 { "info", LOG_INFO }, { "debug", LOG_DEBUG },
117 { NULL, 0 }
122 * map a priority number to its name
124 char *
125 pri_toname(facpri)
126 int facpri;
128 int i, pri;
130 pri = facpri & LOG_PRIMASK;
131 if (pris[pri].value == pri)
132 return pris[pri].name;
133 for (i = 0; pris[i].name; i++)
134 if (pri == pris[i].value)
135 return pris[i].name;
136 return NULL;