summaryrefslogtreecommitdiff
path: root/src/packet/record.h
blob: 479ce40a429bc2f3bd52c31360255fe1a114c470 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once

#include "buffer.h"

#include <string.h>

typedef enum {
    UNKOWN,
    A,      // 1
    NS,     // 2
    CNAME,  // 5
    SOA,    // 6
    PTR,    // 12
    MX,     // 15
    TXT,    // 16
    AAAA,   // 28
    SRV,    // 33
    CAA     // 257
} RecordType;

uint16_t record_to_id(RecordType type);
void record_from_id(uint16_t i, RecordType* type);

typedef struct {
    uint8_t addr[4];
} ARecord;

typedef struct {
    uint8_t* host;
} NSRecord;

typedef struct {
    uint8_t* host;
} CNAMERecord;

typedef struct {
    uint8_t* mname;
    uint8_t* nname;
    uint32_t serial;
    uint32_t refresh;
    uint32_t retry;
    uint32_t expire;
    uint32_t minimum;
} SOARecord;

typedef struct {
    uint8_t* pointer;
} PTRRecord;

typedef struct {
    uint16_t priority;
    uint8_t* host;
} MXRecord;

typedef struct TXTRecord {
    uint8_t** text;
    uint8_t len;
} TXTRecord;

typedef struct {
    uint8_t addr[16];
} AAAARecord;

typedef struct {
    uint16_t priority;
    uint16_t weight;
    uint16_t port;
    uint8_t* target;
} SRVRecord;

typedef struct {
    uint8_t flags;
    uint8_t length;
    uint8_t* tag;
    uint8_t* value;
} CAARecord;

typedef struct {
    uint32_t ttl;
    uint16_t cls;
    uint16_t len;
    uint8_t* domain;
    RecordType type;
    union data {
        ARecord a;
        NSRecord ns;
        CNAMERecord cname;
        SOARecord soa;
        PTRRecord ptr;
        MXRecord mx;
        TXTRecord txt;
        AAAARecord aaaa;
        SRVRecord srv;
        CAARecord caa;
    } data;
} Record;

void read_record(PacketBuffer* buffer, Record* record);
void write_record(PacketBuffer* buffer, Record* record);
void free_record(Record* record);
void print_record(Record* record, char* buffer);