2 #ifndef dns_transp_common_h
3 #define dns_transp_common_h
5 #define MAX_DOMAIN_BYTES 255
8 #define RCODE_NOERROR 0
9 #define RCODE_FORMERR 1
10 #define RCODE_SERVFAIL 2
11 #define RCODE_NXDOMAIN 3
12 #define RCODE_REFUSED 5
14 #define FAKERCODE_NOTAUTH -1
15 #define FAKERCODE_MYDOMAINTOOLONG -2
16 #define FAKERCODE_MYDOMAINLABELTOOLONG -3
28 void dnsdomaindec_globalinit(void);
32 /* private for dnsdomainenc_... functions; do not access direcctly */
34 int npending; /* never more than 4 unless we're in the middle */
35 uint8_t *out, *bufstop; /* counts backwards */
40 * The only legal calling sequence is this:
47 int dnsdomainenc_start(struct dnsdomainenc *be, uint8_t *buf, int buflen,
48 int mydompathlen, const char *const mydompath[]);
49 /* returns -1 if mydompath is too long somehow */
51 void dnsdomainenc_addbits(struct dnsdomainenc *be, uint32_t val, int nbits);
52 /* adds the bottom nbits bits of val; must be enough space; nbits<=28 */
53 void dnsdomainenc_addu32(struct dnsdomainenc *be, uint32_t val);
54 /* must be enough space */
56 int dnsdomainenc_restbytes(struct dnsdomainenc *be,
57 const uint8_t *bytes, int avail);
58 /* returns number of bytes which did not fit */
60 uint8_t *dnsdomainenc_getresult(struct dnsdomainenc *be);
61 /* returns pointer into caller-supplied buffer; we have used
62 * bytes from the result to the end (so the caller needs to remember
63 * the buffer len to know what the encoded length is */
67 /* private for dnsbitdec_... functions; do not access direcctly */
68 uint8_t databuf[MAX_DOMAIN_BYTES];
74 int dnsdomaindec_start(struct dnsdomaindec *bd, const uint8_t *packet,
75 const uint8_t *endpacket, const uint8_t *domain,
76 int mydompathlen, const char *const mydompath[],
77 const uint8_t **domain_end_r);
79 uint32_t dnsdomaindec_getbits(struct dnsdomaindec *bd, int nbits);
81 uint32_t dnsdomaindec_getu32(struct dnsdomaindec *bd);
83 int dnsdomaindec_restbytes(struct dnsdomaindec *bd,
84 uint8_t outbuf[MAX_DOMAIN_BYTES]);
87 #endif /* dns_transp_common_h */