]>
Commit | Line | Data |
---|---|---|
52e54c1c MT |
1 | |
2 | #ifndef NETUTIL_H | |
3 | #define NETUTIL_H 1 | |
4 | ||
5 | #include <stdlib.h> | |
6 | ||
7 | #define LETTERS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
8 | #define NUMBERS "0123456789" | |
9 | #define LETTERS_NUMBERS LETTERS NUMBERS | |
10 | #define IP_NUMBERS "./" NUMBERS | |
11 | #define PORT_NUMBERS ":-" NUMBERS | |
12 | #define VALID_FQDN LETTERS_NUMBERS ".-" | |
13 | ||
14 | #define VALID_IP(ip) (strlen(ip) > 6 \ | |
15 | && strlen(ip) < 16 \ | |
16 | && strspn(ip, NUMBERS ".") == strlen(ip)) | |
17 | ||
18 | #define VALID_IP_AND_MASK(ip) (strlen(ip) > 6 \ | |
19 | && strlen(ip) < 32 \ | |
20 | && strspn(ip, IP_NUMBERS) == strlen(ip)) | |
21 | ||
22 | #define VALID_PORT(port) (strlen(port) \ | |
23 | && strlen(port) < 6 \ | |
24 | && strspn(port, NUMBERS) == strlen(port)) | |
25 | ||
26 | #define VALID_PORT_RANGE(port) (strlen(port) \ | |
27 | && strlen(port) < 12 \ | |
28 | && strspn(port, PORT_NUMBERS) == strlen(port)) | |
29 | ||
30 | #define VALID_SHORT_MASK(ip) (strlen(ip) > 1 \ | |
31 | && strlen(ip) < 3 \ | |
32 | && strspn(ip, NUMBERS) == strlen(ip)) | |
33 | ||
34 | /* Can't find any info on valid characters/length hopefully these are | |
35 | * reasonable guesses */ | |
36 | #define VALID_DEVICE(dev) (strlen(dev) \ | |
37 | && strlen(dev) < 16 \ | |
38 | && strspn(dev, LETTERS_NUMBERS ":.") == strlen(dev)) | |
39 | ||
40 | /* Again, can't find any hard and fast rules for protocol names, these | |
41 | * restrictions are based on the keywords currently listed in | |
42 | * <http://www.iana.org/assignments/protocol-numbers> | |
43 | * though currently the ipcop cgis will only pass tcp, udp or gre anyway */ | |
44 | #define VALID_PROTOCOL(prot) (strlen(prot) \ | |
45 | && strlen(prot) <16 \ | |
46 | && strspn(prot, LETTERS_NUMBERS "-") == strlen(prot)) | |
47 | ||
48 | #endif |