tcp_flags.c revision 145519
1/*	$FreeBSD: head/contrib/ipfilter/lib/tcp_flags.c 145519 2005-04-25 18:20:15Z darrenr $	*/
2
3/*
4 * Copyright (C) 1993-2001 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: tcp_flags.c,v 1.8 2004/02/07 18:15:54 darrenr Exp
9 */
10
11#include "ipf.h"
12
13extern	char	flagset[];
14extern	u_char	flags[];
15
16
17u_char tcp_flags(flgs, mask, linenum)
18char *flgs;
19u_char *mask;
20int    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}
51