chiark / gitweb /
WIP dns packet en/decoding
[secnet.git] / dns-transp-common.h
1
2 struct dnsbitenc {
3     /* private for dnsbitenc_... functions; do not access direcctly */
4     uint32_t pending;
5     int npending; /* never more than 4 unless we're in the middle */
6     uint8_t *out, *bufstop; /* counts backwards */
7     int labremain;
8 };
9
10 /*
11  * The only legal calling sequence is this:
12  *   start
13  *   (addbits | addu32)*
14  *   restbytes
15  *   getresult
16  */
17
18 void dnsbitenc_start(struct dnsbitenc *be, uint8_t *buf, int buflen);
19
20 void dnsbitenc_addbits(struct dnsbitenc *be, uint32_t val, int nbits);
21     /* adds the bottom nbits bits of val; must be enough space; nbits<=28 */
22 void dnsbitenc_addu32(struct dnsbitenc *be, uint32_t val);
23     /* must be enough space */
24
25 int dnsbitenc_restbytes(struct dnsbitenc *be, uint8_t *bytes, int qty);
26     /* returns number of bytes which did not fit */
27
28 uint8_t *dnsbitenc_getresult(struct dnsbitenc *be);
29     /* returns pointer into caller-supplied buffer; we have used
30      * bytes from the result to the end (so the caller needs to remember
31      * the buffer len to know what the encoded length is */