]>
Commit | Line | Data |
---|---|---|
1 | /* IPv6 helper prototypes */ | |
2 | ||
3 | #ifndef __irc_ipv6_H | |
4 | #define __irc_ipv6_H | |
5 | ||
6 | #include <limits.h> | |
7 | ||
8 | /* from res.h */ | |
9 | ||
10 | /** Structure to store an IP address. */ | |
11 | struct irc_in_addr | |
12 | { | |
13 | unsigned short in6_16[8]; /**< IPv6 encoded parts, little-endian. */ | |
14 | }; | |
15 | ||
16 | /** Structure to store an IP address and port number. */ | |
17 | struct irc_sockaddr | |
18 | { | |
19 | struct irc_in_addr addr; /**< IP address. */ | |
20 | unsigned short port; /**< Port number, host-endian. */ | |
21 | }; | |
22 | ||
23 | #define irc_bitlen(ADDR, BITS) (irc_in_addr_is_ipv4(ADDR) ? (BITS) - 96 : (BITS)) | |
24 | ||
25 | /** Evaluate to non-zero if \a ADDR is a valid address (not all 0s and not all 1s). */ | |
26 | #define irc_in_addr_valid(ADDR) (((ADDR)->in6_16[0] && ~(ADDR)->in6_16[0]) \ | |
27 | || (ADDR)->in6_16[1] != (ADDR)->in6_16[0] \ | |
28 | || (ADDR)->in6_16[2] != (ADDR)->in6_16[0] \ | |
29 | || (ADDR)->in6_16[3] != (ADDR)->in6_16[0] \ | |
30 | || (ADDR)->in6_16[4] != (ADDR)->in6_16[0] \ | |
31 | || (ADDR)->in6_16[5] != (ADDR)->in6_16[0] \ | |
32 | || (ADDR)->in6_16[6] != (ADDR)->in6_16[0] \ | |
33 | || (ADDR)->in6_16[7] != (ADDR)->in6_16[0]) | |
34 | /** Evaluate to non-zero if \a ADDR (of type struct irc_in_addr) is an IPv4 address. */ | |
35 | #define irc_in_addr_is_ipv4(ADDR) (!(ADDR)->in6_16[0] && !(ADDR)->in6_16[1] && !(ADDR)->in6_16[2] \ | |
36 | && !(ADDR)->in6_16[3] && !(ADDR)->in6_16[4] && (ADDR)->in6_16[6] \ | |
37 | && (!(ADDR)->in6_16[5] || (ADDR)->in6_16[5] == 65535)) | |
38 | /** Evaluate to non-zero if \a A is a different IP than \a B. */ | |
39 | #define irc_in_addr_cmp(A,B) (irc_in_addr_is_ipv4(A) ? ((A)->in6_16[6] != (B)->in6_16[6] \ | |
40 | || (A)->in6_16[7] != (B)->in6_16[7] || !irc_in_addr_is_ipv4(B)) \ | |
41 | : memcmp((A), (B), sizeof(struct irc_in_addr))) | |
42 | /** Evaluate to non-zero if \a ADDR is a loopback address. */ | |
43 | #define irc_in_addr_is_loopback(ADDR) (!(ADDR)->in6_16[0] && !(ADDR)->in6_16[1] && !(ADDR)->in6_16[2] \ | |
44 | && !(ADDR)->in6_16[3] && !(ADDR)->in6_16[4] \ | |
45 | && ((!(ADDR)->in6_16[5] \ | |
46 | && ((!(ADDR)->in6_16[6] && (ADDR)->in6_16[7] == htons(1)) \ | |
47 | || (ntohs((ADDR)->in6_16[6]) & 0xff00) == 0x7f00)) \ | |
48 | || (((ADDR)->in6_16[5] == 65535) \ | |
49 | && (ntohs((ADDR)->in6_16[6]) & 0xff00) == 0x7f00))) | |
50 | ||
51 | ||
52 | /* from ircd_defs.h */ | |
53 | ||
54 | /** Maximum length of a numeric IP (v4 or v6) address. | |
55 | * "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255" | |
56 | */ | |
57 | #define SOCKIPLEN 45 | |
58 | ||
59 | /* from ircd_string.h */ | |
60 | ||
61 | extern const char* ircd_ntoa(const struct irc_in_addr* addr); | |
62 | extern const char* ircd_ntoa_r(char* buf, const struct irc_in_addr* addr); | |
63 | #define ircd_aton(ADDR, STR) ipmask_parse((STR), (ADDR), NULL) | |
64 | extern int ipmask_parse(const char *in, struct irc_in_addr *mask, unsigned char *bits_ptr); | |
65 | ||
66 | #define IPtostr(ipaddr) ircd_ntoa(&(ipaddr)) | |
67 | #define irc_in_addr_v4_to_int(ADDR) ((ntohs((ADDR)->in6_16[6]) << 16) | ntohs((ADDR)->in6_16[7])) | |
68 | ||
69 | /* from numnicks.h */ | |
70 | ||
71 | extern const char* iptobase64(char* buf, const struct irc_in_addr* addr, unsigned int count, int v6_ok); | |
72 | extern void base64toip(const char* s, struct irc_in_addr* addr); | |
73 | ||
74 | /* from ircd_chattr.h */ | |
75 | ||
76 | /** Array mapping characters to attribute bitmasks. */ | |
77 | extern const unsigned int IRCD_CharAttrTab[]; | |
78 | ||
79 | #define NTL_DIGIT 0x0008 /**< 0123456789 */ | |
80 | ||
81 | /** Test whether a character is a digit. */ | |
82 | #define IsDigit(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_DIGIT) | |
83 | ||
84 | #endif /* __irc_ipv6_H */ |