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