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