2
* Copyright (C) 2006 Justin Karneges
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the
6
* "Software"), to deal in the Software without restriction, including
7
* without limitation the rights to use, copy, modify, merge, publish,
8
* distribute, sublicense, and/or sell copies of the Software, and to
9
* permit persons to whom the Software is furnished to do so, subject to
10
* the following conditions:
12
* The above copyright notice and this permission notice shall be included
13
* in all copies or substantial portions of the Software.
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
// 1) call jdns_packet_new()
33
// 2) populate the jdns_packet_t structure, using the functions
35
// 3) call jdns_packet_export() to populate the raw data of the packet
38
// 1) call jdns_packet_new()
39
// 2) call jdns_packet_import() with the raw data
40
// 3) the jdns_packet_t structure is now populated
42
// IMPORTANT: all names must be valid. that is, ending in a dot character
44
int jdns_packet_name_isvalid(const unsigned char *name, int size); // 0 if not valid
46
typedef struct jdns_packet_question
50
unsigned short int qtype, qclass;
51
} jdns_packet_question_t;
53
jdns_packet_question_t *jdns_packet_question_new();
54
jdns_packet_question_t *jdns_packet_question_copy(const jdns_packet_question_t *a);
55
void jdns_packet_question_delete(jdns_packet_question_t *a);
57
typedef struct jdns_packet_write jdns_packet_write_t;
58
typedef struct jdns_packet jdns_packet_t;
60
typedef struct jdns_packet_resource
64
unsigned short int qtype, qclass;
65
unsigned long int ttl;
66
unsigned short int rdlength;
70
jdns_list_t *writelog; // jdns_packet_write_t
71
} jdns_packet_resource_t;
73
jdns_packet_resource_t *jdns_packet_resource_new();
74
jdns_packet_resource_t *jdns_packet_resource_copy(const jdns_packet_resource_t *a);
75
void jdns_packet_resource_delete(jdns_packet_resource_t *a);
76
void jdns_packet_resource_add_bytes(jdns_packet_resource_t *a, const unsigned char *data, int size);
77
void jdns_packet_resource_add_name(jdns_packet_resource_t *a, const jdns_string_t *name);
78
int jdns_packet_resource_read_name(const jdns_packet_resource_t *a, const jdns_packet_t *p, int *at, jdns_string_t **name);
83
unsigned short int id;
86
unsigned short qr, opcode, aa, tc, rd, ra, z, rcode;
89
// item counts as specified by the packet. do not use these
90
// for iteration over the item lists, since they can be wrong
91
// if the packet is truncated.
92
int qdcount, ancount, nscount, arcount;
95
jdns_list_t *questions; // jdns_packet_question_t
96
jdns_list_t *answerRecords; // jdns_packet_resource_t
97
jdns_list_t *authorityRecords; // jdns_packet_resource_t
98
jdns_list_t *additionalRecords; // jdns_packet_resource_t
100
// since dns packets are allowed to be truncated, it is possible
101
// for a packet to not get fully parsed yet still be considered
102
// successfully parsed. this flag means the packet was fully
107
unsigned char *raw_data;
110
jdns_packet_t *jdns_packet_new();
111
jdns_packet_t *jdns_packet_copy(const jdns_packet_t *a);
112
void jdns_packet_delete(jdns_packet_t *a);
113
int jdns_packet_import(jdns_packet_t **a, const unsigned char *data, int size); // 0 on fail
114
int jdns_packet_export(jdns_packet_t *a, int maxsize); // 0 on fail