32 #include "ip64/ip64.h" 33 #include "ipv6/ip64-addr.h" 34 #include "ip64/ip64-dns64.h" 42 #define PRINTF(...) printf(__VA_ARGS__) 49 uint8_t flags1, flags2;
50 #define DNS_FLAG1_RESPONSE 0x80 51 #define DNS_FLAG1_OPCODE_STATUS 0x10 52 #define DNS_FLAG1_OPCODE_INVERSE 0x08 53 #define DNS_FLAG1_OPCODE_STANDARD 0x00 54 #define DNS_FLAG1_AUTHORATIVE 0x04 55 #define DNS_FLAG1_TRUNC 0x02 56 #define DNS_FLAG1_RD 0x01 57 #define DNS_FLAG2_RA 0x80 58 #define DNS_FLAG2_ERR_MASK 0x0f 59 #define DNS_FLAG2_ERR_NONE 0x00 60 #define DNS_FLAG2_ERR_NAME 0x03 61 uint8_t numquestions[2];
62 uint8_t numanswers[2];
64 uint8_t numextrarr[2];
67 #define DNS_QUESTION_TYPE0 0 68 #define DNS_QUESTION_TYPE1 1 69 #define DNS_QUESTION_CLASS0 2 70 #define DNS_QUESTION_CLASS1 3 71 #define DNS_QUESTION_SIZE 4 87 #define DNS_TYPE_AAAA 28 89 #define DNS_CLASS_IN 1 90 #define DNS_CLASS_ANY 255 94 ip64_dns64_6to4(
const uint8_t *ipv6data,
int ipv6datalen,
95 uint8_t *ipv4data,
int ipv4datalen)
103 hdr = (
struct dns_hdr *)ipv4data;
104 PRINTF(
"ip64_dns64_6to4 id: %02x%02x\n", hdr->id[0], hdr->id[1]);
105 PRINTF(
"ip64_dns64_6to4 flags1: 0x%02x\n", hdr->flags1);
106 PRINTF(
"ip64_dns64_6to4 flags2: 0x%02x\n", hdr->flags2);
107 PRINTF(
"ip64_dns64_6to4 numquestions: 0x%02x\n", ((hdr->numquestions[0] << 8) + hdr->numquestions[1]));
108 PRINTF(
"ip64_dns64_6to4 numanswers: 0x%02x\n", ((hdr->numanswers[0] << 8) + hdr->numanswers[1]));
109 PRINTF(
"ip64_dns64_6to4 numauthrr: 0x%02x\n", ((hdr->numauthrr[0] << 8) + hdr->numauthrr[1]));
110 PRINTF(
"ip64_dns64_6to4 numextrarr: 0x%02x\n", ((hdr->numextrarr[0] << 8) + hdr->numextrarr[1]));
114 qdata = ipv4data +
sizeof(
struct dns_hdr);
115 for(i = 0; i < ((hdr->numquestions[0] << 8) + hdr->numquestions[1]); i++) {
119 for(j = 0; j < qlen; j++) {
121 if(qdata > ipv4data + ipv4datalen) {
122 PRINTF(
"ip64_dns64_6to4: packet ended while parsing\n");
128 if(q[DNS_QUESTION_CLASS0] == 0 && q[DNS_QUESTION_CLASS1] == DNS_CLASS_IN &&
129 q[DNS_QUESTION_TYPE0] == 0 && q[DNS_QUESTION_TYPE1] == DNS_TYPE_AAAA) {
130 q[DNS_QUESTION_TYPE1] = DNS_TYPE_A;
133 qdata += DNS_QUESTION_SIZE;
138 ip64_dns64_4to6(
const uint8_t *ipv4data,
int ipv4datalen,
139 uint8_t *ipv6data,
int ipv6datalen)
144 const uint8_t *qdata, *adata;
145 uint8_t *qcopy, *acopy, *lenptr;
149 hdr = (
struct dns_hdr *)ipv4data;
150 PRINTF(
"ip64_dns64_4to6 id: %02x%02x\n", hdr->id[0], hdr->id[1]);
151 PRINTF(
"ip64_dns64_4to6 flags1: 0x%02x\n", hdr->flags1);
152 PRINTF(
"ip64_dns64_4to6 flags2: 0x%02x\n", hdr->flags2);
153 PRINTF(
"ip64_dns64_4to6 numquestions: 0x%02x\n", ((hdr->numquestions[0] << 8) + hdr->numquestions[1]));
154 PRINTF(
"ip64_dns64_4to6 numanswers: 0x%02x\n", ((hdr->numanswers[0] << 8) + hdr->numanswers[1]));
155 PRINTF(
"ip64_dns64_4to6 numauthrr: 0x%02x\n", ((hdr->numauthrr[0] << 8) + hdr->numauthrr[1]));
156 PRINTF(
"ip64_dns64_4to6 numextrarr: 0x%02x\n", ((hdr->numextrarr[0] << 8) + hdr->numextrarr[1]));
160 qdata = ipv4data +
sizeof(
struct dns_hdr);
161 qcopy = ipv6data +
sizeof(
struct dns_hdr);
162 for(i = 0; i < ((hdr->numquestions[0] << 8) + hdr->numquestions[1]); i++) {
167 for(j = 0; j < qlen; j++) {
170 if(qdata > ipv4data + ipv4datalen) {
171 PRINTF(
"ip64_dns64_4to6: packet ended while parsing\n");
177 if(q[DNS_QUESTION_CLASS0] == 0 && q[DNS_QUESTION_CLASS1] == DNS_CLASS_IN &&
178 q[DNS_QUESTION_TYPE0] == 0 && q[DNS_QUESTION_TYPE1] == DNS_TYPE_AAAA) {
179 q[DNS_QUESTION_TYPE1] = DNS_TYPE_AAAA;
182 qdata += DNS_QUESTION_SIZE;
183 qcopy += DNS_QUESTION_SIZE;
190 for(i = 0; i < ((hdr->numanswers[0] << 8) + hdr->numanswers[1]); i++) {
203 for(j = 0; j < n; j++) {
209 if(adata[0] == 0 && adata[1] == DNS_TYPE_A) {
214 *acopy = DNS_TYPE_AAAA;
220 len = (adata[6] << 8) + adata[7];
223 memcpy(acopy, adata, 2 + 4 + 2);
229 uip_ipaddr(&addr, adata[0], adata[1], adata[2], adata[3]);
230 ip64_addr_4to6(&addr, (uip_ip6addr_t *)acopy);
239 memcpy(acopy, adata, len);
244 len = (adata[8] << 8) + adata[9];
247 memcpy(acopy, adata, 2 + 2 + 4 + 2);
252 memcpy(acopy, adata, len);
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Representation of an IP address.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.