allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / include / linux / netfilter_helpers.h
blob903f37455d1984474ce61c5fe2a72ad8d1e2fb34
1 /*
2 * Helpers for netfiler modules. This file provides implementations for basic
3 * functions such as strncasecmp(), etc.
5 * gcc will warn for defined but unused functions, so we only include the
6 * functions requested. The following macros are used:
7 * NF_NEED_STRNCASECMP nf_strncasecmp()
8 * NF_NEED_STRTOU16 nf_strtou16()
9 * NF_NEED_STRTOU32 nf_strtou32()
11 #ifndef _NETFILTER_HELPERS_H
12 #define _NETFILTER_HELPERS_H
14 /* Only include these functions for kernel code. */
15 #ifdef __KERNEL__
17 #include <linux/ctype.h>
18 #define iseol(c) ( (c) == '\r' || (c) == '\n' )
21 * The standard strncasecmp()
23 #ifdef NF_NEED_STRNCASECMP
24 static int
25 nf_strncasecmp(const char* s1, const char* s2, u_int32_t len)
27 if (s1 == NULL || s2 == NULL)
29 if (s1 == NULL && s2 == NULL)
31 return 0;
33 return (s1 == NULL) ? -1 : 1;
35 while (len > 0 && tolower(*s1) == tolower(*s2))
37 len--;
38 s1++;
39 s2++;
41 return ( (len == 0) ? 0 : (tolower(*s1) - tolower(*s2)) );
43 #endif /* NF_NEED_STRNCASECMP */
46 * Parse a string containing a 16-bit unsigned integer.
47 * Returns the number of chars used, or zero if no number is found.
49 #ifdef NF_NEED_STRTOU16
50 static int
51 nf_strtou16(const char* pbuf, u_int16_t* pval)
53 int n = 0;
55 *pval = 0;
56 while (isdigit(pbuf[n]))
58 *pval = (*pval * 10) + (pbuf[n] - '0');
59 n++;
62 return n;
64 #endif /* NF_NEED_STRTOU16 */
67 * Parse a string containing a 32-bit unsigned integer.
68 * Returns the number of chars used, or zero if no number is found.
70 #ifdef NF_NEED_STRTOU32
71 static int
72 nf_strtou32(const char* pbuf, u_int32_t* pval)
74 int n = 0;
76 *pval = 0;
77 while (pbuf[n] >= '0' && pbuf[n] <= '9')
79 *pval = (*pval * 10) + (pbuf[n] - '0');
80 n++;
83 return n;
85 #endif /* NF_NEED_STRTOU32 */
88 * Given a buffer and length, advance to the next line and mark the current
89 * line.
91 #ifdef NF_NEED_NEXTLINE
92 static int
93 nf_nextline(char* p, uint len, uint* poff, uint* plineoff, uint* plinelen)
95 uint off = *poff;
96 uint physlen = 0;
98 if (off >= len)
100 return 0;
103 while (p[off] != '\n')
105 if (len-off <= 1)
107 return 0;
110 physlen++;
111 off++;
114 /* if we saw a crlf, physlen needs adjusted */
115 if (physlen > 0 && p[off] == '\n' && p[off-1] == '\r')
117 physlen--;
120 /* advance past the newline */
121 off++;
123 *plineoff = *poff;
124 *plinelen = physlen;
125 *poff = off;
127 return 1;
129 #endif /* NF_NEED_NEXTLINE */
131 #endif /* __KERNEL__ */
133 #endif /* _NETFILTER_HELPERS_H */