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