kernel - Fix issue w/ buffer ortation when doing non-blocking read from bpf
[dragonfly.git] / contrib / ipfilter / facpri.c
blob79afdd214729be22024b4980e19675a2ba6ccfe5
1 /*
2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
6 #include <stdio.h>
7 #include <string.h>
8 #include <limits.h>
9 #include <sys/types.h>
10 #if !defined(__SVR4) && !defined(__svr4__)
11 #include <strings.h>
12 #endif
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <stddef.h>
16 #include <syslog.h>
17 #include "facpri.h"
19 #ifndef __STDC__
20 # define const
21 #endif
23 #if !defined(lint)
24 static const char rcsid[] = "@(#)$Id: facpri.c,v 1.3.2.4 2001/07/15 22:06:12 darrenr Exp $";
25 #endif
27 typedef struct table {
28 char *name;
29 int value;
30 } table_t;
32 table_t facs[] = {
33 { "kern", LOG_KERN }, { "user", LOG_USER },
34 { "mail", LOG_MAIL }, { "daemon", LOG_DAEMON },
35 { "auth", LOG_AUTH }, { "syslog", LOG_SYSLOG },
36 { "lpr", LOG_LPR }, { "news", LOG_NEWS },
37 { "uucp", LOG_UUCP },
38 #if LOG_CRON == LOG_CRON2
39 { "cron2", LOG_CRON1 },
40 #else
41 { "cron", LOG_CRON1 },
42 #endif
43 #ifdef LOG_FTP
44 { "ftp", LOG_FTP },
45 #endif
46 #ifdef LOG_AUTHPRIV
47 { "authpriv", LOG_AUTHPRIV },
48 #endif
49 #ifdef LOG_AUDIT
50 { "audit", LOG_AUDIT },
51 #endif
52 #ifdef LOG_LFMT
53 { "logalert", LOG_LFMT },
54 #endif
55 #if LOG_CRON == LOG_CRON1
56 { "cron", LOG_CRON2 },
57 #else
58 { "cron2", LOG_CRON2 },
59 #endif
60 #ifdef LOG_SECURITY
61 { "security", LOG_SECURITY },
62 #endif
63 { "local0", LOG_LOCAL0 }, { "local1", LOG_LOCAL1 },
64 { "local2", LOG_LOCAL2 }, { "local3", LOG_LOCAL3 },
65 { "local4", LOG_LOCAL4 }, { "local5", LOG_LOCAL5 },
66 { "local6", LOG_LOCAL6 }, { "local7", LOG_LOCAL7 },
67 { NULL, 0 }
72 * map a facility number to its name
74 char *
75 fac_toname(facpri)
76 int facpri;
78 int i, j, fac;
80 fac = facpri & LOG_FACMASK;
81 j = fac >> 3;
82 if (j < 24) {
83 if (facs[j].value == fac)
84 return facs[j].name;
85 for (i = 0; facs[i].name; i++)
86 if (fac == facs[i].value)
87 return facs[i].name;
90 return NULL;
95 * map a facility name to its number
97 int
98 fac_findname(name)
99 char *name;
101 int i;
103 for (i = 0; facs[i].name; i++)
104 if (!strcmp(facs[i].name, name))
105 return facs[i].value;
106 return -1;
110 table_t pris[] = {
111 { "emerg", LOG_EMERG }, { "alert", LOG_ALERT },
112 { "crit", LOG_CRIT }, { "err", LOG_ERR },
113 { "warn", LOG_WARNING }, { "notice", LOG_NOTICE },
114 { "info", LOG_INFO }, { "debug", LOG_DEBUG },
115 { NULL, 0 }
120 * map a priority name to its number
123 pri_findname(name)
124 char *name;
126 int i;
128 for (i = 0; pris[i].name; i++)
129 if (!strcmp(pris[i].name, name))
130 return pris[i].value;
131 return -1;
136 * map a priority number to its name
138 char *
139 pri_toname(facpri)
140 int facpri;
142 int i, pri;
144 pri = facpri & LOG_PRIMASK;
145 if (pris[pri].value == pri)
146 return pris[pri].name;
147 for (i = 0; pris[i].name; i++)
148 if (pri == pris[i].value)
149 return pris[i].name;
150 return NULL;