]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/tcp_flags.c
Import IP Filter 4.1.10
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / tcp_flags.c
1 /*
2  * Copyright (C) 1993-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: tcp_flags.c,v 1.8 2004/02/07 18:15:54 darrenr Exp $
7  */
8
9 #include "ipf.h"
10
11 extern  char    flagset[];
12 extern  u_char  flags[];
13
14
15 u_char tcp_flags(flgs, mask, linenum)
16 char *flgs;
17 u_char *mask;
18 int    linenum;
19 {
20         u_char tcpf = 0, tcpfm = 0;
21         char *s;
22
23         s = strchr(flgs, '/');
24         if (s)
25                 *s++ = '\0';
26
27         if (*flgs == '0') {
28                 tcpf = strtol(flgs, NULL, 0);
29         } else {
30                 tcpf = tcpflags(flgs);
31         }
32
33         if (s != NULL) {
34                 if (*s == '0')
35                         tcpfm = strtol(s, NULL, 0);
36                 else
37                         tcpfm = tcpflags(s);
38         }
39
40         if (!tcpfm) {
41                 if (tcpf == TH_SYN)
42                         tcpfm = 0xff & ~(TH_ECN|TH_CWR);
43                 else
44                         tcpfm = 0xff & ~(TH_ECN);
45         }
46         *mask = tcpfm;
47         return tcpf;
48 }