prevent CNAME/PTR parsing from reading data past the response end
[musl] / src / network / lookup.h
1 #ifndef LOOKUP_H
2 #define LOOKUP_H
3
4 #include <stdint.h>
5 #include <stddef.h>
6 #include <features.h>
7 #include <netinet/in.h>
8 #include <netdb.h>
9
10 struct aibuf {
11         struct addrinfo ai;
12         union sa {
13                 struct sockaddr_in sin;
14                 struct sockaddr_in6 sin6;
15         } sa;
16         volatile int lock[1];
17         short slot, ref;
18 };
19
20 struct address {
21         int family;
22         unsigned scopeid;
23         uint8_t addr[16];
24         int sortkey;
25 };
26
27 struct service {
28         uint16_t port;
29         unsigned char proto, socktype;
30 };
31
32 #define MAXNS 3
33
34 struct resolvconf {
35         struct address ns[MAXNS];
36         unsigned nns, attempts, ndots;
37         unsigned timeout;
38 };
39
40 /* The limit of 48 results is a non-sharp bound on the number of addresses
41  * that can fit in one 512-byte DNS packet full of v4 results and a second
42  * packet full of v6 results. Due to headers, the actual limit is lower. */
43 #define MAXADDRS 48
44 #define MAXSERVS 2
45
46 hidden int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags);
47 hidden int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags);
48 hidden int __lookup_ipliteral(struct address buf[static 1], const char *name, int family);
49
50 hidden int __get_resolv_conf(struct resolvconf *, char *, size_t);
51 hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *);
52
53 hidden int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *, int), void *);
54
55 #endif