forked from aarond10/https_dns_proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
52 lines (41 loc) · 2.12 KB
/
utils.h
File metadata and controls
52 lines (41 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef _UTILS_H_
#define _UTILS_H_
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
// Write null-terminated 'name' to 'out' buffer of at least 'outlen' length.
// dnptrs[0] should point to the start of the packet. dnptrs[1-n] point at$
// previous domain names. dnptrs[n] should be NULL. lastdnptr should be$
// &dnptrs[m] where m > n.
ssize_t dn_name_compress(const char *name, uint8_t *out, size_t outlen,
const uint8_t **dnptrs, const uint8_t **lastdnptr);
// Encode null-terminated 'name' to 'out' buffer of at least 'outlen' length.
// Does NOT use domain-name compression (back referencing). For use with
// DNSSEC RRType only.
// Returns length of encoded name.
ssize_t dn_name_nocompress(char *name, uint8_t *out, size_t outlen);
// Either does a strcpy (in the case of an unquoted string) or lightly
// unescapes ('\' and '"' only) a quoted string.
// Returns a pointer to the character immediately after the quoted string.
// olen should contain the output buffer size and will be replaced with the
// length of the unescaped string stored in 'out'.
const char* unescape(const char *in, char *out, size_t *olen);
// Takes the string version of an RRTYPE and returns it's integer ID.
// Returns -1 if string does not correspond to a known type.
int str_to_rrtype(const char* str);
// Decodes YYYYmmddHHMMSS to a unix timestamp.
uint32_t parse_time(const char *timestr);
// In-place base32hex (RFC4648) decoder. Padding optional.
// returns the length of the decoded string.
ssize_t b32hexdec(const char *buf, uint8_t *out, ssize_t outlen);
// In-place base64 decoder.
// returns the length of the decoded string.
ssize_t b64dec(const char *buf, uint8_t *out, ssize_t outlen);
// in-place decode of hex string to raw values.
// returns length of decoded string.
ssize_t hexdec(const char *buf, uint8_t *out, ssize_t outlen);
// Type bitmaps are defined in https://www.ietf.org/rfc/rfc4034.txt
// This function parses presentation format from 'buf' and writes
// out wire format to 'out'. Returns the number of bytes written.
ssize_t type_bitmap_dec(char *buf, uint8_t *out, ssize_t outlen);
#endif // _UTILS_H_