xref: /netbsd-src/external/bsd/ipf/dist/lib/tcpflags.c (revision 13885a665959c62f13a82b3caedf986eaa17aa31)
1 /*	$NetBSD: tcpflags.c,v 1.2 2012/07/22 14:27:37 darrenr Exp $	*/
2 
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * Id: tcpflags.c,v 1.1.1.2 2012/07/22 13:44:43 darrenr Exp $
9  */
10 
11 #include "ipf.h"
12 
13 
14 /*
15  * ECN is a new addition to TCP - RFC 2481
16  */
17 #ifndef TH_ECN
18 # define	TH_ECN  0x40
19 #endif
20 #ifndef TH_CWR
21 # define	TH_CWR  0x80
22 #endif
23 
24 extern	char	flagset[];
25 extern	u_char	flags[];
26 
27 
tcpflags(flgs)28 u_char tcpflags(flgs)
29 	char *flgs;
30 {
31 	u_char tcpf = 0;
32 	char *s, *t;
33 
34 	for (s = flgs; *s; s++) {
35 		if (*s == 'W')
36 			tcpf |= TH_CWR;
37 		else {
38 			if (!(t = strchr(flagset, *s))) {
39 				return 0;
40 			}
41 			tcpf |= flags[t - flagset];
42 		}
43 	}
44 	return tcpf;
45 }
46