]> git.ipfire.org Git - thirdparty/squid.git/blob - src/dns/rfc1035.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / dns / rfc1035.h
1 /*
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_RFC1035_H
10 #define SQUID_RFC1035_H
11
12 #if HAVE_SYS_TYPES_H
13 #include <sys/types.h>
14 #endif
15 #if HAVE_NETINET_IN_H
16 #include <netinet/in.h>
17 #endif
18 #if HAVE_ARPA_INET_H
19 #include <arpa/inet.h>
20 #endif
21
22 #include "rfc2181.h"
23
24 /**
25 \par RFC 1035 Section 3.1:
26 * To simplify implementations, the total length of a domain name (i.e.,
27 * label octets and label length octets) is restricted to 255 octets or
28 * less.
29 *\par
30 * Clarified by RFC 2181 Section 11. (RFC2181_MAXHOSTNAMELEN)
31 */
32 #define RFC1035_MAXHOSTNAMESZ RFC2181_MAXHOSTNAMELEN
33
34 #define RFC1035_DEFAULT_PACKET_SZ 512
35
36 class rfc1035_rr
37 {
38 public:
39 char name[RFC1035_MAXHOSTNAMESZ];
40 unsigned short type;
41 unsigned short _class;
42 unsigned int ttl;
43 unsigned short rdlength;
44 char *rdata;
45 };
46
47 typedef struct _rfc1035_query rfc1035_query;
48 struct _rfc1035_query {
49 char name[RFC1035_MAXHOSTNAMESZ];
50 unsigned short qtype;
51 unsigned short qclass;
52 };
53
54 typedef struct _rfc1035_message rfc1035_message;
55 struct _rfc1035_message {
56 unsigned short id;
57 unsigned int qr:1;
58 unsigned int opcode:4;
59 unsigned int aa:1;
60 unsigned int tc:1;
61 unsigned int rd:1;
62 unsigned int ra:1;
63 unsigned int rcode:4;
64 unsigned short qdcount;
65 unsigned short ancount;
66 unsigned short nscount;
67 unsigned short arcount;
68 rfc1035_query *query;
69 rfc1035_rr *answer;
70 };
71
72 SQUIDCEXTERN ssize_t rfc1035BuildAQuery(const char *hostname,
73 char *buf,
74 size_t sz,
75 unsigned short qid,
76 rfc1035_query * query,
77 ssize_t edns_sz);
78 SQUIDCEXTERN ssize_t rfc1035BuildPTRQuery(const struct in_addr,
79 char *buf,
80 size_t sz,
81 unsigned short qid,
82 rfc1035_query * query,
83 ssize_t edns_sz);
84 SQUIDCEXTERN void rfc1035SetQueryID(char *, unsigned short qid);
85 SQUIDCEXTERN int rfc1035MessageUnpack(const char *buf,
86 size_t sz,
87 rfc1035_message ** answer);
88 SQUIDCEXTERN int rfc1035QueryCompare(const rfc1035_query *, const rfc1035_query *);
89 SQUIDCEXTERN void rfc1035RRDestroy(rfc1035_rr ** rr, int n);
90 SQUIDCEXTERN void rfc1035MessageDestroy(rfc1035_message ** message);
91 SQUIDCEXTERN const char * rfc1035ErrorMessage(int n);
92
93 #define RFC1035_TYPE_A 1
94 #define RFC1035_TYPE_CNAME 5
95 #define RFC1035_TYPE_PTR 12
96 #define RFC1035_CLASS_IN 1
97
98 /* Child Library RFC3596 Depends on some otherwise internal functions */
99 SQUIDCEXTERN int rfc1035HeaderPack(char *buf,
100 size_t sz,
101 rfc1035_message * hdr);
102 SQUIDCEXTERN int rfc1035HeaderUnpack(const char *buf,
103 size_t sz,
104 unsigned int *off,
105 rfc1035_message * h);
106 SQUIDCEXTERN int rfc1035QuestionPack(char *buf,
107 size_t sz,
108 const char *name,
109 const unsigned short type,
110 const unsigned short _class);
111 SQUIDCEXTERN int rfc1035RRPack(char *buf, size_t sz, const rfc1035_rr * RR);
112
113 #endif /* SQUID_RFC1035_H */
114