mDNS

Dependents:   OS

This is a mDNS server.

Committer:
sPymbed
Date:
Wed Nov 20 13:27:10 2019 +0000
Revision:
6:3bf9f4943d1a
Parent:
5:4b6323e78f58
fixed: print line in screen

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