2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_RFC1035_H
10 #define SQUID_RFC1035_H
13 #include <sys/types.h>
16 #include <netinet/in.h>
19 #include <arpa/inet.h>
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
30 * Clarified by RFC 2181 Section 11. (RFC2181_MAXHOSTNAMELEN)
32 #define RFC1035_MAXHOSTNAMESZ RFC2181_MAXHOSTNAMELEN
34 #define RFC1035_DEFAULT_PACKET_SZ 512
39 char name
[RFC1035_MAXHOSTNAMESZ
];
41 unsigned short _class
;
43 unsigned short rdlength
;
47 typedef struct _rfc1035_query rfc1035_query
;
48 struct _rfc1035_query
{
49 char name
[RFC1035_MAXHOSTNAMESZ
];
51 unsigned short qclass
;
54 typedef struct _rfc1035_message rfc1035_message
;
55 struct _rfc1035_message
{
58 unsigned int opcode
:4;
64 unsigned short qdcount
;
65 unsigned short ancount
;
66 unsigned short nscount
;
67 unsigned short arcount
;
72 SQUIDCEXTERN ssize_t
rfc1035BuildAQuery(const char *hostname
,
76 rfc1035_query
* query
,
78 SQUIDCEXTERN ssize_t
rfc1035BuildPTRQuery(const struct in_addr
,
82 rfc1035_query
* query
,
84 SQUIDCEXTERN
void rfc1035SetQueryID(char *, unsigned short qid
);
85 SQUIDCEXTERN
int rfc1035MessageUnpack(const char *buf
,
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
);
93 #define RFC1035_TYPE_A 1
94 #define RFC1035_TYPE_CNAME 5
95 #define RFC1035_TYPE_PTR 12
96 #define RFC1035_CLASS_IN 1
98 /* Child Library RFC3596 Depends on some otherwise internal functions */
99 SQUIDCEXTERN
int rfc1035HeaderPack(char *buf
,
101 rfc1035_message
* hdr
);
102 SQUIDCEXTERN
int rfc1035HeaderUnpack(const char *buf
,
105 rfc1035_message
* h
);
106 SQUIDCEXTERN
int rfc1035QuestionPack(char *buf
,
109 const unsigned short type
,
110 const unsigned short _class
);
111 SQUIDCEXTERN
int rfc1035RRPack(char *buf
, size_t sz
, const rfc1035_rr
* RR
);
113 #endif /* SQUID_RFC1035_H */