mDNS

Dependents:   OS

This is a mDNS server.

Committer:
JBRYU
Date:
Tue Aug 11 17:05:41 2015 +0000
Revision:
0:0df3300689d2
Child:
1:163dc87e95c3
2015; JB Ryu - KOR; mdns-SD

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JBRYU 0:0df3300689d2 1 /*
JBRYU 0:0df3300689d2 2 ----------------------------------------------------
JBRYU 0:0df3300689d2 3 Made by JB RYU, KOR - 2015
JBRYU 0:0df3300689d2 4
JBRYU 0:0df3300689d2 5 origin - C / mdns-sd on CONTIKI-ipv6(uIP) I'd made
JBRYU 0:0df3300689d2 6
JBRYU 0:0df3300689d2 7 now - C++ (actually singleton C-style process)/
JBRYU 0:0df3300689d2 8 mdns-sd on MBED-ipv4(LWIP)
JBRYU 0:0df3300689d2 9 ----------------------------------------------------
JBRYU 0:0df3300689d2 10 More progressed things than others :
JBRYU 0:0df3300689d2 11 {
JBRYU 0:0df3300689d2 12 Parsing multi-Query (OK),
JBRYU 0:0df3300689d2 13 Check duplicated host and avoid (OK)
JBRYU 0:0df3300689d2 14 }
JBRYU 0:0df3300689d2 15
JBRYU 0:0df3300689d2 16 TODO : (Actully these are not necessary for my prj)
JBRYU 0:0df3300689d2 17 {
JBRYU 0:0df3300689d2 18 register multiple service,
JBRYU 0:0df3300689d2 19 managing records-caches
JBRYU 0:0df3300689d2 20 }
JBRYU 0:0df3300689d2 21 ----------------------------------------------------
JBRYU 0:0df3300689d2 22 Notes :
JBRYU 0:0df3300689d2 23 srv-instance-name = host-name
JBRYU 0:0df3300689d2 24 SEP-<rand 2byte><IP-hex 2byte>
JBRYU 0:0df3300689d2 25 There are some problems about lose-connection because
JBRYU 0:0df3300689d2 26 MBED-netsocketIFs are unstable (I think).
JBRYU 0:0df3300689d2 27 ----------------------------------------------------
JBRYU 0:0df3300689d2 28 */
JBRYU 0:0df3300689d2 29
JBRYU 0:0df3300689d2 30
JBRYU 0:0df3300689d2 31 #include "lwip/opt.h"
JBRYU 0:0df3300689d2 32 #include "mbed.h"
JBRYU 0:0df3300689d2 33 #include "EthernetInterface.h"
JBRYU 0:0df3300689d2 34 #include <cstring>
JBRYU 0:0df3300689d2 35 #if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
JBRYU 0:0df3300689d2 36
JBRYU 0:0df3300689d2 37 #include "mDNSResponder.h"
JBRYU 0:0df3300689d2 38 #include "dns-sd.h"
JBRYU 0:0df3300689d2 39
JBRYU 0:0df3300689d2 40 #ifndef DNS_RRTYPE_SRV
JBRYU 0:0df3300689d2 41 #define DNS_RRTYPE_SRV (33)
JBRYU 0:0df3300689d2 42 #endif
JBRYU 0:0df3300689d2 43
JBRYU 0:0df3300689d2 44 #ifndef DNS_LOCAL
JBRYU 0:0df3300689d2 45 #define DNS_LOCAL "local"
JBRYU 0:0df3300689d2 46 #endif
JBRYU 0:0df3300689d2 47
JBRYU 0:0df3300689d2 48 #define MDNS_DBG 1
JBRYU 0:0df3300689d2 49 #if (MDNS_DBG > 0)
JBRYU 0:0df3300689d2 50 #define MDBG(x...) printf(x)
JBRYU 0:0df3300689d2 51 #else
JBRYU 0:0df3300689d2 52 #define MDBG(x...)
JBRYU 0:0df3300689d2 53 #endif
JBRYU 0:0df3300689d2 54
JBRYU 0:0df3300689d2 55 mDNSResponder::mDNSResponder() : IP_str(NULL)
JBRYU 0:0df3300689d2 56 {}
JBRYU 0:0df3300689d2 57
JBRYU 0:0df3300689d2 58 /* initialize static instance */
JBRYU 0:0df3300689d2 59 char mDNSResponder::query_buf[1500] =
JBRYU 0:0df3300689d2 60 {
JBRYU 0:0df3300689d2 61 0,
JBRYU 0:0df3300689d2 62 };
JBRYU 0:0df3300689d2 63
JBRYU 0:0df3300689d2 64 MY_SD_DOMAINS mDNSResponder::SD_domains =
JBRYU 0:0df3300689d2 65 {
JBRYU 0:0df3300689d2 66 .numbers = N_CONTIKI_SERVICES,
JBRYU 0:0df3300689d2 67 .elements =
JBRYU 0:0df3300689d2 68 {
JBRYU 0:0df3300689d2 69 {
JBRYU 0:0df3300689d2 70 .inst_len = 8,
JBRYU 0:0df3300689d2 71 .instance = {'S','E','P','-','0','0','0','0'},
JBRYU 0:0df3300689d2 72 .serv_len = 12,
JBRYU 0:0df3300689d2 73 .service = {'_','s','m','a','r','t','e','n','e','r','g','y',},
JBRYU 0:0df3300689d2 74 .trl_len = 4,
JBRYU 0:0df3300689d2 75 .trl = {'_','t','c','p'},
JBRYU 0:0df3300689d2 76 .domain_len = 5,
JBRYU 0:0df3300689d2 77 .domain = {'l','o','c','a','l'},
JBRYU 0:0df3300689d2 78 .txt =
JBRYU 0:0df3300689d2 79 {
JBRYU 0:0df3300689d2 80 .len_txtvers = 9,
JBRYU 0:0df3300689d2 81 .txtvers = {'t','x','t','v','e','r','s','=','1'},
JBRYU 0:0df3300689d2 82 .len_dcap = 10,
JBRYU 0:0df3300689d2 83 .dcap = {'d','c','a','p','=','/','d','c','a','p'},
JBRYU 0:0df3300689d2 84 .len_path = 9,
JBRYU 0:0df3300689d2 85 .path = {'p','a','t','h','=','/','u','p','t'},
JBRYU 0:0df3300689d2 86 .len_https = 9,
JBRYU 0:0df3300689d2 87 .https = {'h','t','t','p','s','=','4','4','3'},
JBRYU 0:0df3300689d2 88 .len_level = 9,
JBRYU 0:0df3300689d2 89 .level = {'l','e','v','e','l','=','-','S','0'},
JBRYU 0:0df3300689d2 90 }
JBRYU 0:0df3300689d2 91 },
JBRYU 0:0df3300689d2 92 },
JBRYU 0:0df3300689d2 93 };
JBRYU 0:0df3300689d2 94
JBRYU 0:0df3300689d2 95 char mDNSResponder::
JBRYU 0:0df3300689d2 96 PTR_query_name[PTR_QUERY_NAME_LEN] =
JBRYU 0:0df3300689d2 97 {
JBRYU 0:0df3300689d2 98 0x05, 0x5f,
JBRYU 0:0df3300689d2 99 0x68, 0x74, 0x74, 0x70, 0x04, 0x5f, 0x74, 0x63,
JBRYU 0:0df3300689d2 100 0x70, 0x05, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x00,
JBRYU 0:0df3300689d2 101 };
JBRYU 0:0df3300689d2 102
JBRYU 0:0df3300689d2 103 struct dns_hdr mDNSResponder::SD_res_hdr =
JBRYU 0:0df3300689d2 104 {
JBRYU 0:0df3300689d2 105 .id = 0x0000,
JBRYU 0:0df3300689d2 106 .flags1 = DNS_FLAG1_RESPONSE | DNS_FLAG1_AUTHORATIVE,
JBRYU 0:0df3300689d2 107 .flags2 = 0,
JBRYU 0:0df3300689d2 108 .numquestions = 0,
JBRYU 0:0df3300689d2 109 .numanswers = htons(1),
JBRYU 0:0df3300689d2 110 .numauthrr = 0,
JBRYU 0:0df3300689d2 111 .numextrarr = 0,
JBRYU 0:0df3300689d2 112 };
JBRYU 0:0df3300689d2 113
JBRYU 0:0df3300689d2 114 QR_MAP mDNSResponder::g_queries = {0,};
JBRYU 0:0df3300689d2 115
JBRYU 0:0df3300689d2 116 /* end of initialize static instance */
JBRYU 0:0df3300689d2 117
JBRYU 0:0df3300689d2 118 mDNSResponder::~mDNSResponder()
JBRYU 0:0df3300689d2 119 {
JBRYU 0:0df3300689d2 120 close();
JBRYU 0:0df3300689d2 121 }
JBRYU 0:0df3300689d2 122
JBRYU 0:0df3300689d2 123 void mDNSResponder::
JBRYU 0:0df3300689d2 124 register_service(char* number)
JBRYU 0:0df3300689d2 125 {
JBRYU 0:0df3300689d2 126 memcpy(&SD_domains.elements[0].instance[4], number, 4);
JBRYU 0:0df3300689d2 127 }
JBRYU 0:0df3300689d2 128
JBRYU 0:0df3300689d2 129 void mDNSResponder::
JBRYU 0:0df3300689d2 130 query_domain(void)
JBRYU 0:0df3300689d2 131 {
JBRYU 0:0df3300689d2 132 volatile uint8_t i;
JBRYU 0:0df3300689d2 133 struct dns_hdr* hdr;
JBRYU 0:0df3300689d2 134 struct dns_question* question;
JBRYU 0:0df3300689d2 135 uint8_t *query;
JBRYU 0:0df3300689d2 136
JBRYU 0:0df3300689d2 137 MDBG("start probe duplicate domain\n");
JBRYU 0:0df3300689d2 138
JBRYU 0:0df3300689d2 139 hdr = (struct dns_hdr *)query_buf;
JBRYU 0:0df3300689d2 140
JBRYU 0:0df3300689d2 141 memset(hdr, 0, sizeof(struct dns_hdr));
JBRYU 0:0df3300689d2 142
JBRYU 0:0df3300689d2 143 hdr->id = 0;
JBRYU 0:0df3300689d2 144 hdr->flags1 = DNS_FLAG1_RD;
JBRYU 0:0df3300689d2 145 hdr->numquestions = htons(1);
JBRYU 0:0df3300689d2 146
JBRYU 0:0df3300689d2 147 query = (unsigned char *)query_buf + sizeof(*hdr);
JBRYU 0:0df3300689d2 148
JBRYU 0:0df3300689d2 149 memcpy(query, &SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 150 SD_domains.elements[0].inst_len+1);
JBRYU 0:0df3300689d2 151 query += SD_domains.elements[0].inst_len+1;
JBRYU 0:0df3300689d2 152
JBRYU 0:0df3300689d2 153 memcpy(query, &SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 154 SD_domains.elements[0].domain_len+1);
JBRYU 0:0df3300689d2 155 query += SD_domains.elements[0].domain_len+1;
JBRYU 0:0df3300689d2 156
JBRYU 0:0df3300689d2 157 *query = 0x00;
JBRYU 0:0df3300689d2 158 query++;
JBRYU 0:0df3300689d2 159
JBRYU 0:0df3300689d2 160 question = (struct dns_question*)query;
JBRYU 0:0df3300689d2 161 question->type = htons(DNS_TYPE_ANY);
JBRYU 0:0df3300689d2 162 question->obj = htons(DNS_CLASS_IN);
JBRYU 0:0df3300689d2 163
JBRYU 0:0df3300689d2 164 query += 4;
JBRYU 0:0df3300689d2 165
JBRYU 0:0df3300689d2 166 MDBG("send probe query(%d)\n",
JBRYU 0:0df3300689d2 167 (uint16_t)((uint32_t)query - (uint32_t)query_buf));
JBRYU 0:0df3300689d2 168
JBRYU 0:0df3300689d2 169 mdns_sock.sendTo(send_endpt, query_buf,
JBRYU 0:0df3300689d2 170 (query - (uint8_t *) query_buf));
JBRYU 0:0df3300689d2 171 }
JBRYU 0:0df3300689d2 172
JBRYU 0:0df3300689d2 173 void mDNSResponder::announce(char* ip)
JBRYU 0:0df3300689d2 174 {
JBRYU 0:0df3300689d2 175 send_endpt.set_address(MCAST, MDNS_PORT);
JBRYU 0:0df3300689d2 176
JBRYU 0:0df3300689d2 177 mdns_sock.bind(MDNS_PORT);
JBRYU 0:0df3300689d2 178 if (mdns_sock.join_multicast_group(MCAST) != 0)
JBRYU 0:0df3300689d2 179 {
JBRYU 0:0df3300689d2 180 printf("Error joining the multicast group\n");
JBRYU 0:0df3300689d2 181 while (true) {}
JBRYU 0:0df3300689d2 182 }
JBRYU 0:0df3300689d2 183
JBRYU 0:0df3300689d2 184 IP_str = ip;
JBRYU 0:0df3300689d2 185
JBRYU 0:0df3300689d2 186 IPstringToByte(IP_str);
JBRYU 0:0df3300689d2 187
JBRYU 0:0df3300689d2 188 char instance_number[4];
JBRYU 0:0df3300689d2 189 sprintf(instance_number, "%.2d%.2X",
JBRYU 0:0df3300689d2 190 0, IP_byte[3]);
JBRYU 0:0df3300689d2 191 register_service(instance_number);
JBRYU 0:0df3300689d2 192
JBRYU 0:0df3300689d2 193 query_domain();
JBRYU 0:0df3300689d2 194 }
JBRYU 0:0df3300689d2 195
JBRYU 0:0df3300689d2 196 void mDNSResponder::close()
JBRYU 0:0df3300689d2 197 {
JBRYU 0:0df3300689d2 198 mdns_sock.close();
JBRYU 0:0df3300689d2 199 }
JBRYU 0:0df3300689d2 200
JBRYU 0:0df3300689d2 201 void mDNSResponder::IPstringToByte(char* IPstr)
JBRYU 0:0df3300689d2 202 {
JBRYU 0:0df3300689d2 203 char ip1[4] = {0,}; char ip2[4] = {0,};
JBRYU 0:0df3300689d2 204 char ip3[4] = {0,}; char ip4[4] = {0,};
JBRYU 0:0df3300689d2 205 char* p;
JBRYU 0:0df3300689d2 206 char* p_dot;
JBRYU 0:0df3300689d2 207
JBRYU 0:0df3300689d2 208 p_dot = strstr(IPstr, ".");
JBRYU 0:0df3300689d2 209 memcpy(ip1, IPstr, p_dot-IPstr);
JBRYU 0:0df3300689d2 210 IP_byte[0] = (uint8_t)atoi((const char*)ip1);
JBRYU 0:0df3300689d2 211
JBRYU 0:0df3300689d2 212 p = p_dot + 1;
JBRYU 0:0df3300689d2 213 p_dot = strstr(p, ".");
JBRYU 0:0df3300689d2 214 memcpy(ip2, p, p_dot-p);
JBRYU 0:0df3300689d2 215 IP_byte[1] = (uint8_t)atoi((const char*)ip2);
JBRYU 0:0df3300689d2 216
JBRYU 0:0df3300689d2 217 p = p_dot + 1;
JBRYU 0:0df3300689d2 218 p_dot = strstr(p, ".");
JBRYU 0:0df3300689d2 219 memcpy(ip3, p, p_dot-p);
JBRYU 0:0df3300689d2 220 IP_byte[2] = (uint8_t)atoi((const char*)ip3);
JBRYU 0:0df3300689d2 221
JBRYU 0:0df3300689d2 222 p = p_dot + 1;
JBRYU 0:0df3300689d2 223 memcpy(ip4, p, 3);
JBRYU 0:0df3300689d2 224 IP_byte[3] = (uint8_t)atoi((const char*)ip4);
JBRYU 0:0df3300689d2 225 }
JBRYU 0:0df3300689d2 226
JBRYU 0:0df3300689d2 227 char* mDNSResponder::
JBRYU 0:0df3300689d2 228 skip_name(char* query)
JBRYU 0:0df3300689d2 229 {
JBRYU 0:0df3300689d2 230 unsigned char n;
JBRYU 0:0df3300689d2 231
JBRYU 0:0df3300689d2 232 do
JBRYU 0:0df3300689d2 233 {
JBRYU 0:0df3300689d2 234 n = *query;
JBRYU 0:0df3300689d2 235 if(n & 0xc0)
JBRYU 0:0df3300689d2 236 {
JBRYU 0:0df3300689d2 237 ++query;
JBRYU 0:0df3300689d2 238 break;
JBRYU 0:0df3300689d2 239 }
JBRYU 0:0df3300689d2 240
JBRYU 0:0df3300689d2 241 ++query;
JBRYU 0:0df3300689d2 242
JBRYU 0:0df3300689d2 243 while(n > 0)
JBRYU 0:0df3300689d2 244 {
JBRYU 0:0df3300689d2 245 ++query;
JBRYU 0:0df3300689d2 246 --n;
JBRYU 0:0df3300689d2 247 };
JBRYU 0:0df3300689d2 248 } while(*query != 0);
JBRYU 0:0df3300689d2 249
JBRYU 0:0df3300689d2 250 return query + 1;
JBRYU 0:0df3300689d2 251 }
JBRYU 0:0df3300689d2 252
JBRYU 0:0df3300689d2 253 char* mDNSResponder::
JBRYU 0:0df3300689d2 254 decode_name(char* query, char* packet)
JBRYU 0:0df3300689d2 255 {
JBRYU 0:0df3300689d2 256 char c = 0xff;
JBRYU 0:0df3300689d2 257 static char dest[MAX_DOMAIN_LEN];
JBRYU 0:0df3300689d2 258 int len = 0;
JBRYU 0:0df3300689d2 259
JBRYU 0:0df3300689d2 260 memset(dest, 0, MAX_DOMAIN_LEN);
JBRYU 0:0df3300689d2 261
JBRYU 0:0df3300689d2 262 MDBG("\n");
JBRYU 0:0df3300689d2 263 while((len < MAX_DOMAIN_LEN) && (c != 0x00))
JBRYU 0:0df3300689d2 264 {
JBRYU 0:0df3300689d2 265 c = *query;
JBRYU 0:0df3300689d2 266
JBRYU 0:0df3300689d2 267 while (c == 0xc0)
JBRYU 0:0df3300689d2 268 {
JBRYU 0:0df3300689d2 269 MDBG("%s : read offset\n", __FUNCTION__);
JBRYU 0:0df3300689d2 270 query++;
JBRYU 0:0df3300689d2 271 query = (char*)((uint32_t)packet + *query);
JBRYU 0:0df3300689d2 272 c = *query;
JBRYU 0:0df3300689d2 273 }
JBRYU 0:0df3300689d2 274
JBRYU 0:0df3300689d2 275 memset(&dest[len], c, 1);
JBRYU 0:0df3300689d2 276
JBRYU 0:0df3300689d2 277 query++;
JBRYU 0:0df3300689d2 278 len++;
JBRYU 0:0df3300689d2 279 }
JBRYU 0:0df3300689d2 280
JBRYU 0:0df3300689d2 281 MDBG("\n%s : %s\n", __FUNCTION__, dest);
JBRYU 0:0df3300689d2 282 return dest;
JBRYU 0:0df3300689d2 283 }
JBRYU 0:0df3300689d2 284
JBRYU 0:0df3300689d2 285 void mDNSResponder::
JBRYU 0:0df3300689d2 286 send_dns_ans(struct dns_hdr* hdr)
JBRYU 0:0df3300689d2 287 {
JBRYU 0:0df3300689d2 288 int i = 0;
JBRYU 0:0df3300689d2 289 uint8_t* ptr;
JBRYU 0:0df3300689d2 290 uint32_t off_inst = 0;
JBRYU 0:0df3300689d2 291 uint32_t off_serv = 0;
JBRYU 0:0df3300689d2 292 uint32_t off_domain = 0;
JBRYU 0:0df3300689d2 293 PTR_ANS* ptr_ans;
JBRYU 0:0df3300689d2 294 SRV_ANS* srv_ans;
JBRYU 0:0df3300689d2 295 struct dns_answer* A_ans;
JBRYU 0:0df3300689d2 296 TXT_ANS* txt_ans;
JBRYU 0:0df3300689d2 297 int numbers = g_queries.numbers;
JBRYU 0:0df3300689d2 298
JBRYU 0:0df3300689d2 299 uint8_t ans_mask = DNS_TYPE_ANY; //later, for addtional ans
JBRYU 0:0df3300689d2 300
JBRYU 0:0df3300689d2 301 memcpy(hdr, &SD_res_hdr, sizeof(struct dns_hdr));
JBRYU 0:0df3300689d2 302 hdr->numanswers = htons(numbers);
JBRYU 0:0df3300689d2 303 ptr = (uint8_t*)hdr + sizeof(struct dns_hdr);
JBRYU 0:0df3300689d2 304
JBRYU 0:0df3300689d2 305 while (numbers--)
JBRYU 0:0df3300689d2 306 {
JBRYU 0:0df3300689d2 307 switch (g_queries.reqs[i])
JBRYU 0:0df3300689d2 308 {
JBRYU 0:0df3300689d2 309 case DNS_TYPE_PTR :
JBRYU 0:0df3300689d2 310 ans_mask = ans_mask ^ DNS_TYPE_PTR;
JBRYU 0:0df3300689d2 311 if (off_serv == 0)
JBRYU 0:0df3300689d2 312 {
JBRYU 0:0df3300689d2 313 off_serv = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 314
JBRYU 0:0df3300689d2 315 memcpy(ptr, &SD_domains.elements[0].serv_len,
JBRYU 0:0df3300689d2 316 SD_domains.elements[0].serv_len + 1);
JBRYU 0:0df3300689d2 317 ptr += SD_domains.elements[0].serv_len + 1;
JBRYU 0:0df3300689d2 318
JBRYU 0:0df3300689d2 319 memcpy(ptr, &SD_domains.elements[0].trl_len,
JBRYU 0:0df3300689d2 320 SD_domains.elements[0].trl_len + 1);
JBRYU 0:0df3300689d2 321 ptr += SD_domains.elements[0].trl_len + 1;
JBRYU 0:0df3300689d2 322
JBRYU 0:0df3300689d2 323 memcpy(ptr, &SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 324 SD_domains.elements[0].domain_len + 1);
JBRYU 0:0df3300689d2 325 ptr += SD_domains.elements[0].domain_len + 1;
JBRYU 0:0df3300689d2 326 *ptr = 0x00;
JBRYU 0:0df3300689d2 327 ptr++;
JBRYU 0:0df3300689d2 328 }
JBRYU 0:0df3300689d2 329 else
JBRYU 0:0df3300689d2 330 {
JBRYU 0:0df3300689d2 331 *ptr = 0xc0;
JBRYU 0:0df3300689d2 332 ptr++;
JBRYU 0:0df3300689d2 333 *ptr = (uint8_t)off_serv;
JBRYU 0:0df3300689d2 334 ptr++;
JBRYU 0:0df3300689d2 335 }
JBRYU 0:0df3300689d2 336
JBRYU 0:0df3300689d2 337 ptr_ans = (PTR_ANS*)ptr;
JBRYU 0:0df3300689d2 338
JBRYU 0:0df3300689d2 339 ptr_ans->type = htons(DNS_TYPE_PTR);
JBRYU 0:0df3300689d2 340 ptr_ans->obj = htons(DNS_CLASS_IN);
JBRYU 0:0df3300689d2 341 ptr_ans->ttl[0] = 0;
JBRYU 0:0df3300689d2 342 ptr_ans->ttl[1] = htons(120);
JBRYU 0:0df3300689d2 343
JBRYU 0:0df3300689d2 344 int instance_len = SD_domains.elements[0].inst_len;
JBRYU 0:0df3300689d2 345
JBRYU 0:0df3300689d2 346 ptr = (uint8_t*)ptr_ans->name;
JBRYU 0:0df3300689d2 347
JBRYU 0:0df3300689d2 348 if (off_inst == 0)
JBRYU 0:0df3300689d2 349 {
JBRYU 0:0df3300689d2 350 off_inst = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 351
JBRYU 0:0df3300689d2 352 ptr_ans->len = htons(instance_len + 3);
JBRYU 0:0df3300689d2 353
JBRYU 0:0df3300689d2 354 memcpy(ptr_ans->name,
JBRYU 0:0df3300689d2 355 &SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 356 1 + SD_domains.elements[0].inst_len);
JBRYU 0:0df3300689d2 357
JBRYU 0:0df3300689d2 358 ptr += instance_len + 1;
JBRYU 0:0df3300689d2 359 *ptr = 0xc0;
JBRYU 0:0df3300689d2 360 ptr++;
JBRYU 0:0df3300689d2 361 *ptr = (uint8_t)off_serv;
JBRYU 0:0df3300689d2 362 ptr++;
JBRYU 0:0df3300689d2 363 }
JBRYU 0:0df3300689d2 364 else
JBRYU 0:0df3300689d2 365 {
JBRYU 0:0df3300689d2 366 ptr_ans->len = htons(2);
JBRYU 0:0df3300689d2 367
JBRYU 0:0df3300689d2 368 *ptr = 0xc0;
JBRYU 0:0df3300689d2 369 ptr++;
JBRYU 0:0df3300689d2 370 *ptr = (uint8_t)off_inst;
JBRYU 0:0df3300689d2 371 ptr++;
JBRYU 0:0df3300689d2 372 }
JBRYU 0:0df3300689d2 373 break;
JBRYU 0:0df3300689d2 374 case DNS_TYPE_SRV :
JBRYU 0:0df3300689d2 375 ans_mask = ans_mask ^ DNS_TYPE_SRV;
JBRYU 0:0df3300689d2 376 if (off_inst == 0)
JBRYU 0:0df3300689d2 377 {
JBRYU 0:0df3300689d2 378 off_inst = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 379
JBRYU 0:0df3300689d2 380 memcpy(ptr,
JBRYU 0:0df3300689d2 381 &SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 382 1 + SD_domains.elements[0].inst_len);
JBRYU 0:0df3300689d2 383
JBRYU 0:0df3300689d2 384 ptr += 1 + SD_domains.elements[0].inst_len;
JBRYU 0:0df3300689d2 385
JBRYU 0:0df3300689d2 386 if (off_serv == 0)
JBRYU 0:0df3300689d2 387 {
JBRYU 0:0df3300689d2 388 off_serv = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 389
JBRYU 0:0df3300689d2 390 memcpy(ptr, &SD_domains.elements[0].serv_len,
JBRYU 0:0df3300689d2 391 SD_domains.elements[0].serv_len + 1);
JBRYU 0:0df3300689d2 392 ptr += SD_domains.elements[0].serv_len + 1;
JBRYU 0:0df3300689d2 393
JBRYU 0:0df3300689d2 394 memcpy(ptr, &SD_domains.elements[0].trl_len,
JBRYU 0:0df3300689d2 395 SD_domains.elements[0].trl_len + 1);
JBRYU 0:0df3300689d2 396 ptr += SD_domains.elements[0].trl_len + 1;
JBRYU 0:0df3300689d2 397
JBRYU 0:0df3300689d2 398 memcpy(ptr, &SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 399 SD_domains.elements[0].domain_len + 1);
JBRYU 0:0df3300689d2 400 ptr += SD_domains.elements[0].domain_len + 1;
JBRYU 0:0df3300689d2 401
JBRYU 0:0df3300689d2 402 *ptr = 0x00;
JBRYU 0:0df3300689d2 403 ptr++;
JBRYU 0:0df3300689d2 404 }
JBRYU 0:0df3300689d2 405 else
JBRYU 0:0df3300689d2 406 {
JBRYU 0:0df3300689d2 407 *ptr = 0xc0;
JBRYU 0:0df3300689d2 408 ptr++;
JBRYU 0:0df3300689d2 409 *ptr = (uint8_t)off_serv;
JBRYU 0:0df3300689d2 410 ptr++;
JBRYU 0:0df3300689d2 411 }
JBRYU 0:0df3300689d2 412 }
JBRYU 0:0df3300689d2 413 else
JBRYU 0:0df3300689d2 414 {
JBRYU 0:0df3300689d2 415 *ptr = 0xc0;
JBRYU 0:0df3300689d2 416 ptr++;
JBRYU 0:0df3300689d2 417 *ptr = (uint8_t)off_inst;
JBRYU 0:0df3300689d2 418 ptr++;
JBRYU 0:0df3300689d2 419 }
JBRYU 0:0df3300689d2 420
JBRYU 0:0df3300689d2 421 srv_ans = (SRV_ANS*)(ptr);
JBRYU 0:0df3300689d2 422 srv_ans->type = htons(DNS_TYPE_SRV);
JBRYU 0:0df3300689d2 423 srv_ans->obj = htons(DNS_CLASS_IN | DNS_CASH_FLUSH);
JBRYU 0:0df3300689d2 424 srv_ans->ttl[0] = 0;
JBRYU 0:0df3300689d2 425 srv_ans->ttl[1] = htons(120);
JBRYU 0:0df3300689d2 426 srv_ans->pri = 0;
JBRYU 0:0df3300689d2 427 srv_ans->wei = 0;
JBRYU 0:0df3300689d2 428 srv_ans->port = htons(8080);
JBRYU 0:0df3300689d2 429 ptr = (uint8_t*)srv_ans->name;
JBRYU 0:0df3300689d2 430
JBRYU 0:0df3300689d2 431 if (off_domain == 0)
JBRYU 0:0df3300689d2 432 {
JBRYU 0:0df3300689d2 433 off_domain = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 434
JBRYU 0:0df3300689d2 435 memcpy(ptr,
JBRYU 0:0df3300689d2 436 &SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 437 1 + SD_domains.elements[0].inst_len);
JBRYU 0:0df3300689d2 438
JBRYU 0:0df3300689d2 439 ptr += 1 + SD_domains.elements[0].inst_len;
JBRYU 0:0df3300689d2 440
JBRYU 0:0df3300689d2 441 memcpy(ptr,
JBRYU 0:0df3300689d2 442 &SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 443 1 + SD_domains.elements[0].domain_len);
JBRYU 0:0df3300689d2 444
JBRYU 0:0df3300689d2 445 ptr+= 1 + SD_domains.elements[0].domain_len;
JBRYU 0:0df3300689d2 446 *ptr = 0x00;
JBRYU 0:0df3300689d2 447 ptr++;
JBRYU 0:0df3300689d2 448 }
JBRYU 0:0df3300689d2 449 else
JBRYU 0:0df3300689d2 450 {
JBRYU 0:0df3300689d2 451 *ptr = 0xc0;
JBRYU 0:0df3300689d2 452 ptr++;
JBRYU 0:0df3300689d2 453 *ptr = (uint8_t)off_domain;
JBRYU 0:0df3300689d2 454 ptr++;
JBRYU 0:0df3300689d2 455 }
JBRYU 0:0df3300689d2 456 srv_ans->len =
JBRYU 0:0df3300689d2 457 htons((uint16_t)((uint32_t)ptr - (uint32_t)&srv_ans->pri));
JBRYU 0:0df3300689d2 458
JBRYU 0:0df3300689d2 459 break;
JBRYU 0:0df3300689d2 460 case DNS_TYPE_TXT :
JBRYU 0:0df3300689d2 461 ans_mask = ans_mask ^ DNS_TYPE_TXT;
JBRYU 0:0df3300689d2 462 if (off_inst == 0)
JBRYU 0:0df3300689d2 463 {
JBRYU 0:0df3300689d2 464 off_inst = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 465
JBRYU 0:0df3300689d2 466 memcpy(ptr,
JBRYU 0:0df3300689d2 467 &SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 468 1 + SD_domains.elements[0].inst_len);
JBRYU 0:0df3300689d2 469
JBRYU 0:0df3300689d2 470 ptr += 1 + SD_domains.elements[0].inst_len;
JBRYU 0:0df3300689d2 471
JBRYU 0:0df3300689d2 472 if (off_serv == 0)
JBRYU 0:0df3300689d2 473 {
JBRYU 0:0df3300689d2 474 off_serv = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 475
JBRYU 0:0df3300689d2 476 memcpy(ptr, &SD_domains.elements[0].serv_len,
JBRYU 0:0df3300689d2 477 SD_domains.elements[0].serv_len + 1);
JBRYU 0:0df3300689d2 478 ptr += SD_domains.elements[0].serv_len + 1;
JBRYU 0:0df3300689d2 479
JBRYU 0:0df3300689d2 480 memcpy(ptr, &SD_domains.elements[0].trl_len,
JBRYU 0:0df3300689d2 481 SD_domains.elements[0].trl_len + 1);
JBRYU 0:0df3300689d2 482 ptr += SD_domains.elements[0].trl_len + 1;
JBRYU 0:0df3300689d2 483
JBRYU 0:0df3300689d2 484 memcpy(ptr, &SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 485 SD_domains.elements[0].domain_len + 1);
JBRYU 0:0df3300689d2 486 ptr += SD_domains.elements[0].domain_len + 1;
JBRYU 0:0df3300689d2 487
JBRYU 0:0df3300689d2 488 *ptr = 0x00;
JBRYU 0:0df3300689d2 489 ptr++;
JBRYU 0:0df3300689d2 490 }
JBRYU 0:0df3300689d2 491 else
JBRYU 0:0df3300689d2 492 {
JBRYU 0:0df3300689d2 493 *ptr = 0xc0;
JBRYU 0:0df3300689d2 494 ptr++;
JBRYU 0:0df3300689d2 495 *ptr = (uint8_t)off_serv;
JBRYU 0:0df3300689d2 496 ptr++;
JBRYU 0:0df3300689d2 497 }
JBRYU 0:0df3300689d2 498 }
JBRYU 0:0df3300689d2 499 else
JBRYU 0:0df3300689d2 500 {
JBRYU 0:0df3300689d2 501 *ptr = 0xc0;
JBRYU 0:0df3300689d2 502 ptr++;
JBRYU 0:0df3300689d2 503 *ptr = (uint8_t)off_inst;
JBRYU 0:0df3300689d2 504 ptr++;
JBRYU 0:0df3300689d2 505 }
JBRYU 0:0df3300689d2 506
JBRYU 0:0df3300689d2 507 txt_ans = (TXT_ANS*)(ptr);
JBRYU 0:0df3300689d2 508 txt_ans->type = htons(DNS_TYPE_TXT);
JBRYU 0:0df3300689d2 509 txt_ans->obj = htons(DNS_CLASS_IN | DNS_CASH_FLUSH);
JBRYU 0:0df3300689d2 510 txt_ans->ttl[0] = 0;
JBRYU 0:0df3300689d2 511 txt_ans->ttl[1] = htons(120);
JBRYU 0:0df3300689d2 512 ptr = (uint8_t*)txt_ans->txt;
JBRYU 0:0df3300689d2 513
JBRYU 0:0df3300689d2 514 memcpy(ptr,
JBRYU 0:0df3300689d2 515 &SD_domains.elements[0].txt.len_txtvers,
JBRYU 0:0df3300689d2 516 1 + SD_domains.elements[0].txt.len_txtvers);
JBRYU 0:0df3300689d2 517 ptr += 1 + SD_domains.elements[0].txt.len_txtvers;
JBRYU 0:0df3300689d2 518
JBRYU 0:0df3300689d2 519 memcpy(ptr,
JBRYU 0:0df3300689d2 520 &SD_domains.elements[0].txt.len_dcap,
JBRYU 0:0df3300689d2 521 1 + SD_domains.elements[0].txt.len_dcap);
JBRYU 0:0df3300689d2 522 ptr += 1 + SD_domains.elements[0].txt.len_dcap;
JBRYU 0:0df3300689d2 523
JBRYU 0:0df3300689d2 524 memcpy(ptr,
JBRYU 0:0df3300689d2 525 &SD_domains.elements[0].txt.len_path,
JBRYU 0:0df3300689d2 526 1 + SD_domains.elements[0].txt.len_path);
JBRYU 0:0df3300689d2 527 ptr += 1 + SD_domains.elements[0].txt.len_path;
JBRYU 0:0df3300689d2 528
JBRYU 0:0df3300689d2 529 memcpy(ptr,
JBRYU 0:0df3300689d2 530 &SD_domains.elements[0].txt.len_https,
JBRYU 0:0df3300689d2 531 1 + SD_domains.elements[0].txt.len_https);
JBRYU 0:0df3300689d2 532 ptr += 1 + SD_domains.elements[0].txt.len_https;
JBRYU 0:0df3300689d2 533
JBRYU 0:0df3300689d2 534 memcpy(ptr,
JBRYU 0:0df3300689d2 535 &SD_domains.elements[0].txt.len_level,
JBRYU 0:0df3300689d2 536 1 + SD_domains.elements[0].txt.len_level);
JBRYU 0:0df3300689d2 537 ptr += 1 + SD_domains.elements[0].txt.len_level;
JBRYU 0:0df3300689d2 538
JBRYU 0:0df3300689d2 539 txt_ans->len =
JBRYU 0:0df3300689d2 540 htons((uint16_t)((uint32_t)ptr - (uint32_t)txt_ans->txt));
JBRYU 0:0df3300689d2 541
JBRYU 0:0df3300689d2 542 break;
JBRYU 0:0df3300689d2 543 case DNS_TYPE_A :
JBRYU 0:0df3300689d2 544 ans_mask = ans_mask ^ DNS_TYPE_A;
JBRYU 0:0df3300689d2 545 if (off_domain == 0)
JBRYU 0:0df3300689d2 546 {
JBRYU 0:0df3300689d2 547 off_domain = (uint32_t)ptr - (uint32_t)hdr;
JBRYU 0:0df3300689d2 548
JBRYU 0:0df3300689d2 549 memcpy(ptr,
JBRYU 0:0df3300689d2 550 &SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 551 1 + SD_domains.elements[0].inst_len);
JBRYU 0:0df3300689d2 552
JBRYU 0:0df3300689d2 553 ptr += 1 + SD_domains.elements[0].inst_len;
JBRYU 0:0df3300689d2 554
JBRYU 0:0df3300689d2 555 memcpy(ptr,
JBRYU 0:0df3300689d2 556 &SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 557 1 + SD_domains.elements[0].domain_len);
JBRYU 0:0df3300689d2 558
JBRYU 0:0df3300689d2 559 ptr += 1 + SD_domains.elements[0].domain_len;
JBRYU 0:0df3300689d2 560 *ptr = 0x00;
JBRYU 0:0df3300689d2 561 ptr++;
JBRYU 0:0df3300689d2 562 }
JBRYU 0:0df3300689d2 563 else
JBRYU 0:0df3300689d2 564 {
JBRYU 0:0df3300689d2 565 *ptr = 0xc0;
JBRYU 0:0df3300689d2 566 ptr++;
JBRYU 0:0df3300689d2 567 *ptr = (uint8_t)off_domain;
JBRYU 0:0df3300689d2 568 ptr++;
JBRYU 0:0df3300689d2 569 }
JBRYU 0:0df3300689d2 570
JBRYU 0:0df3300689d2 571 A_ans = (struct dns_answer*)(ptr);
JBRYU 0:0df3300689d2 572
JBRYU 0:0df3300689d2 573 A_ans->type = htons(DNS_TYPE_A);
JBRYU 0:0df3300689d2 574 A_ans->obj = htons(DNS_CLASS_IN | DNS_CASH_FLUSH);
JBRYU 0:0df3300689d2 575 A_ans->ttl[0] = 0;
JBRYU 0:0df3300689d2 576 A_ans->ttl[1] = htons(120);
JBRYU 0:0df3300689d2 577 A_ans->len = htons(4);
JBRYU 0:0df3300689d2 578 memcpy((uint8_t*)A_ans->ipaddr,
JBRYU 0:0df3300689d2 579 IP_byte, 4);
JBRYU 0:0df3300689d2 580
JBRYU 0:0df3300689d2 581 ptr = (uint8_t*)&A_ans->ipaddr + 4;
JBRYU 0:0df3300689d2 582 break;
JBRYU 0:0df3300689d2 583
JBRYU 0:0df3300689d2 584 default :
JBRYU 0:0df3300689d2 585 break;
JBRYU 0:0df3300689d2 586 }
JBRYU 0:0df3300689d2 587 i++;
JBRYU 0:0df3300689d2 588 }
JBRYU 0:0df3300689d2 589
JBRYU 0:0df3300689d2 590 int send_len = ptr - (uint8_t*)hdr;
JBRYU 0:0df3300689d2 591
JBRYU 0:0df3300689d2 592 mdns_sock.sendTo(send_endpt, (char*)hdr, send_len);
JBRYU 0:0df3300689d2 593 }
JBRYU 0:0df3300689d2 594
JBRYU 0:0df3300689d2 595 void mDNSResponder::
JBRYU 0:0df3300689d2 596 MDNS_process(void const *args)
JBRYU 0:0df3300689d2 597 {
JBRYU 0:0df3300689d2 598 char rcv_buf[ 1500 ];
JBRYU 0:0df3300689d2 599 uint8_t nquestions, nanswers;
JBRYU 0:0df3300689d2 600 struct dns_hdr* hdr;
JBRYU 0:0df3300689d2 601 char *queryptr;
JBRYU 0:0df3300689d2 602 uint8_t is_request;
JBRYU 0:0df3300689d2 603 int len;
JBRYU 0:0df3300689d2 604
JBRYU 0:0df3300689d2 605 MDBG("MDNS Process\n");
JBRYU 0:0df3300689d2 606
JBRYU 0:0df3300689d2 607 while ((len = mdns_sock.receiveFrom(rcv_endpt,
JBRYU 0:0df3300689d2 608 rcv_buf, sizeof(rcv_buf))) != 0)
JBRYU 0:0df3300689d2 609 {
JBRYU 0:0df3300689d2 610 hdr = (struct dns_hdr *)rcv_buf;
JBRYU 0:0df3300689d2 611 queryptr = (char *)hdr + sizeof(*hdr);
JBRYU 0:0df3300689d2 612 is_request = ((hdr->flags1 & ~1) == 0) && (hdr->flags2 == 0);
JBRYU 0:0df3300689d2 613 nquestions = (uint8_t) ntohs(hdr->numquestions);
JBRYU 0:0df3300689d2 614 nanswers = (uint8_t) ntohs(hdr->numanswers);
JBRYU 0:0df3300689d2 615
JBRYU 0:0df3300689d2 616 MDBG("resolver: flags1=0x%02X flags2=0x%02X nquestions=%d,\
JBRYU 0:0df3300689d2 617 nanswers=%d, nauthrr=%d, nextrarr=%d\n",\
JBRYU 0:0df3300689d2 618 hdr->flags1, hdr->flags2, (uint8_t) nquestions, (uint8_t) nanswers,\
JBRYU 0:0df3300689d2 619 (uint8_t) ntohs(hdr->numauthrr),\
JBRYU 0:0df3300689d2 620 (uint8_t) ntohs(hdr->numextrarr));
JBRYU 0:0df3300689d2 621
JBRYU 0:0df3300689d2 622 if(hdr->id != 0)
JBRYU 0:0df3300689d2 623 {
JBRYU 0:0df3300689d2 624 return;
JBRYU 0:0df3300689d2 625 }
JBRYU 0:0df3300689d2 626
JBRYU 0:0df3300689d2 627 /** ANSWER HANDLING SECTION ************************************************/
JBRYU 0:0df3300689d2 628 struct dns_question* question = (struct dns_question *)skip_name(queryptr);
JBRYU 0:0df3300689d2 629
JBRYU 0:0df3300689d2 630 uint16_t type;
JBRYU 0:0df3300689d2 631
JBRYU 0:0df3300689d2 632 if (is_request)
JBRYU 0:0df3300689d2 633 {
JBRYU 0:0df3300689d2 634 char* name;
JBRYU 0:0df3300689d2 635
JBRYU 0:0df3300689d2 636 memset(&g_queries, 0, sizeof(QR_MAP));
JBRYU 0:0df3300689d2 637
JBRYU 0:0df3300689d2 638 while (nquestions--)
JBRYU 0:0df3300689d2 639 {
JBRYU 0:0df3300689d2 640 type = ntohs(question->type);
JBRYU 0:0df3300689d2 641 name = decode_name(queryptr, (char*)hdr);
JBRYU 0:0df3300689d2 642
JBRYU 0:0df3300689d2 643 if ((type & DNS_TYPE_PTR) == DNS_TYPE_PTR)
JBRYU 0:0df3300689d2 644 {
JBRYU 0:0df3300689d2 645 if (strncmp((const char*)name,
JBRYU 0:0df3300689d2 646 (const char*)&SD_domains.elements[0].serv_len,
JBRYU 0:0df3300689d2 647 SD_domains.elements[0].serv_len + 1) == 0)
JBRYU 0:0df3300689d2 648 {
JBRYU 0:0df3300689d2 649 MDBG("recv PTR request\n");
JBRYU 0:0df3300689d2 650 g_queries.reqs[g_queries.numbers] = DNS_TYPE_PTR;
JBRYU 0:0df3300689d2 651 g_queries.numbers++;
JBRYU 0:0df3300689d2 652 }
JBRYU 0:0df3300689d2 653 }
JBRYU 0:0df3300689d2 654
JBRYU 0:0df3300689d2 655 if ((type & DNS_TYPE_SRV) == DNS_TYPE_SRV)
JBRYU 0:0df3300689d2 656 {
JBRYU 0:0df3300689d2 657 if ((strncmp((const char*)name,
JBRYU 0:0df3300689d2 658 (const char*)&SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 659 SD_domains.elements[0].inst_len + 1) == 0) &&
JBRYU 0:0df3300689d2 660 (strncmp((const char*)(name + SD_domains.elements[0].inst_len+1),
JBRYU 0:0df3300689d2 661 (const char*)&SD_domains.elements[0].serv_len,
JBRYU 0:0df3300689d2 662 SD_domains.elements[0].serv_len+1) == 0))
JBRYU 0:0df3300689d2 663 {
JBRYU 0:0df3300689d2 664 MDBG("recv SRV request\n");
JBRYU 0:0df3300689d2 665 g_queries.reqs[g_queries.numbers] = DNS_TYPE_SRV;
JBRYU 0:0df3300689d2 666 g_queries.numbers++;
JBRYU 0:0df3300689d2 667 }
JBRYU 0:0df3300689d2 668 }
JBRYU 0:0df3300689d2 669
JBRYU 0:0df3300689d2 670 if ((type & DNS_TYPE_TXT) == DNS_TYPE_TXT)
JBRYU 0:0df3300689d2 671 {
JBRYU 0:0df3300689d2 672 if ((strncmp((const char*)name,
JBRYU 0:0df3300689d2 673 (const char*)&SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 674 SD_domains.elements[0].inst_len + 1) == 0) &&
JBRYU 0:0df3300689d2 675 (strncmp((const char*)(name + SD_domains.elements[0].inst_len+1),
JBRYU 0:0df3300689d2 676 (const char*)&SD_domains.elements[0].serv_len,
JBRYU 0:0df3300689d2 677 SD_domains.elements[0].serv_len+1) == 0))
JBRYU 0:0df3300689d2 678 {
JBRYU 0:0df3300689d2 679 MDBG("recv TXT request\n");
JBRYU 0:0df3300689d2 680 g_queries.reqs[g_queries.numbers] = DNS_TYPE_TXT;
JBRYU 0:0df3300689d2 681 g_queries.numbers++;
JBRYU 0:0df3300689d2 682 }
JBRYU 0:0df3300689d2 683 }
JBRYU 0:0df3300689d2 684
JBRYU 0:0df3300689d2 685 if ((type & DNS_TYPE_A) == DNS_TYPE_A)
JBRYU 0:0df3300689d2 686 {
JBRYU 0:0df3300689d2 687 if ((strncmp((const char*)name,
JBRYU 0:0df3300689d2 688 (const char*)&SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 689 SD_domains.elements[0].inst_len + 1) == 0) &&
JBRYU 0:0df3300689d2 690 (strncmp((const char*)(name + SD_domains.elements[0].inst_len+1),
JBRYU 0:0df3300689d2 691 (const char*)&SD_domains.elements[0].domain_len,
JBRYU 0:0df3300689d2 692 SD_domains.elements[0].domain_len+1) == 0))
JBRYU 0:0df3300689d2 693 {
JBRYU 0:0df3300689d2 694 MDBG("recv AAAA request\n");
JBRYU 0:0df3300689d2 695 g_queries.reqs[g_queries.numbers] = DNS_TYPE_A;
JBRYU 0:0df3300689d2 696 g_queries.numbers++;
JBRYU 0:0df3300689d2 697 }
JBRYU 0:0df3300689d2 698 }
JBRYU 0:0df3300689d2 699
JBRYU 0:0df3300689d2 700 queryptr = (char*)question + sizeof(struct dns_question);
JBRYU 0:0df3300689d2 701 question = (struct dns_question *)skip_name(queryptr);
JBRYU 0:0df3300689d2 702 }
JBRYU 0:0df3300689d2 703
JBRYU 0:0df3300689d2 704 if (g_queries.numbers)
JBRYU 0:0df3300689d2 705 send_dns_ans(hdr);
JBRYU 0:0df3300689d2 706 }
JBRYU 0:0df3300689d2 707 else
JBRYU 0:0df3300689d2 708 {
JBRYU 0:0df3300689d2 709 if (strncmp((const char*)queryptr,
JBRYU 0:0df3300689d2 710 (const char*)&SD_domains.elements[0].inst_len,
JBRYU 0:0df3300689d2 711 SD_domains.elements[0].inst_len + 1) == 0)
JBRYU 0:0df3300689d2 712 {
JBRYU 0:0df3300689d2 713 type = ntohs(question->type);
JBRYU 0:0df3300689d2 714 if (type == DNS_TYPE_A || type == DNS_TYPE_A)
JBRYU 0:0df3300689d2 715 {
JBRYU 0:0df3300689d2 716 char instance_number[4];
JBRYU 0:0df3300689d2 717 sprintf(instance_number, "%.2d%.2X",
JBRYU 0:0df3300689d2 718 (uint8_t)(rand()%100),
JBRYU 0:0df3300689d2 719 IP_byte[3]);
JBRYU 0:0df3300689d2 720 register_service(instance_number);
JBRYU 0:0df3300689d2 721 query_domain();
JBRYU 0:0df3300689d2 722 }
JBRYU 0:0df3300689d2 723 }
JBRYU 0:0df3300689d2 724 }
JBRYU 0:0df3300689d2 725
JBRYU 0:0df3300689d2 726 }
JBRYU 0:0df3300689d2 727 }
JBRYU 0:0df3300689d2 728 #endif
JBRYU 0:0df3300689d2 729