- const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *const dstaddr, const mDNSIPPort dstport,
- const mDNSInterfaceID InterfaceID)
- {
- (void)dstaddr; // Unused
- // Snag copy of header ID, then call through
- lastid = msg->h.id;
- lastsrc = *srcaddr;
-
- // We *want* to allow off-net unicast responses here.
- // For now, the simplest way to allow that is to pretend it was received via multicast so that mDNSCore doesn't reject the packet
- __MDNS__mDNSCoreReceive(m, msg, end, srcaddr, srcport, &AllDNSLinkGroup_v4, dstport, InterfaceID);
- }
-
-static void NameCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
- {
- (void)m; // Unused
- (void)question; // Unused
- (void)AddRecord;// Unused
- if (!id.NotAnInteger) id = lastid;
- if (answer->rrtype == kDNSType_PTR || answer->rrtype == kDNSType_CNAME)
- {
- ConvertDomainNameToCString(&answer->rdata->u.name, hostname);
- StopNow = 1;
- mprintf("%##s %s %##s\n", answer->name->c, DNSTypeName(answer->rrtype), answer->rdata->u.name.c);
- }
- }
-
-static void InfoCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
- {
- (void)m; // Unused
- (void)question; // Unused
- (void)AddRecord;// Unused
- if (answer->rrtype == kDNSType_A)
- {
- if (!id.NotAnInteger) id = lastid;
- NumAnswers++;
- NumAddr++;
- mprintf("%##s %s %.4a\n", answer->name->c, DNSTypeName(answer->rrtype), &answer->rdata->u.ipv4);
- hostaddr.type = mDNSAddrType_IPv4; // Prefer v4 target to v6 target, for now
- hostaddr.ip.v4 = answer->rdata->u.ipv4;
- }
- else if (answer->rrtype == kDNSType_AAAA)
- {
- if (!id.NotAnInteger) id = lastid;
- NumAnswers++;
- NumAAAA++;
- mprintf("%##s %s %.16a\n", answer->name->c, DNSTypeName(answer->rrtype), &answer->rdata->u.ipv6);
- if (!hostaddr.type) // Prefer v4 target to v6 target, for now
- {
- hostaddr.type = mDNSAddrType_IPv6;
- hostaddr.ip.v6 = answer->rdata->u.ipv6;
- }
- }
- else if (answer->rrtype == kDNSType_HINFO)
- {
- mDNSu8 *p = answer->rdata->u.data;
- strncpy(hardware, (char*)(p+1), p[0]);
- hardware[p[0]] = 0;
- p += 1 + p[0];
- strncpy(software, (char*)(p+1), p[0]);
- software[p[0]] = 0;
- NumAnswers++;
- NumHINFO++;
- }
-
- // If we've got everything we're looking for, don't need to wait any more
- if (NumHINFO && (NumAddr || NumAAAA)) StopNow = 1;
- }
-
-static void ServicesCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
- {
- (void)m; // Unused
- (void)question; // Unused
- (void)AddRecord;// Unused
- // Right now the mDNSCore targeted-query code is incomplete --
- // it issues targeted queries, but accepts answers from anywhere
- // For now, we'll just filter responses here so we don't get confused by responses from someone else
- if (answer->rrtype == kDNSType_PTR && mDNSSameAddress(&lastsrc, &target))
- {
- NumAnswers++;
- NumAddr++;
- mprintf("%##s %s %##s\n", answer->name->c, DNSTypeName(answer->rrtype), answer->rdata->u.name.c);
- StopNow = 1;
- }
- }
-
-mDNSexport void WaitForAnswer(mDNS *const m, int seconds)
- {
- struct timeval end;
- gettimeofday(&end, NULL);
- end.tv_sec += seconds;
- StopNow = 0;
- NumAnswers = 0;
- while (!StopNow)
- {
- int nfds = 0;
- fd_set readfds;
- struct timeval now, remain = end;
- int result;
-
- FD_ZERO(&readfds);
- gettimeofday(&now, NULL);
- if (remain.tv_usec < now.tv_usec) { remain.tv_usec += 1000000; remain.tv_sec--; }
- if (remain.tv_sec < now.tv_sec) return;
- remain.tv_usec -= now.tv_usec;
- remain.tv_sec -= now.tv_sec;
- mDNSPosixGetFDSet(m, &nfds, &readfds, &remain);
- result = select(nfds, &readfds, NULL, NULL, &remain);
- if (result >= 0) mDNSPosixProcessFDSet(m, &readfds);
- else if (errno != EINTR) StopNow = 2;
- }
- }
+ const mDNSAddr *const srcaddr, const mDNSIPPort srcport, const mDNSAddr *const dstaddr, const mDNSIPPort dstport,
+ const mDNSInterfaceID InterfaceID)
+{
+ (void)dstaddr; // Unused
+ // Snag copy of header ID, then call through
+ lastid = msg->h.id;
+ lastsrc = *srcaddr;
+
+ // We *want* to allow off-net unicast responses here.
+ // For now, the simplest way to allow that is to pretend it was received via multicast so that mDNSCore doesn't reject the packet
+ __MDNS__mDNSCoreReceive(m, msg, end, srcaddr, srcport, &AllDNSLinkGroup_v4, dstport, InterfaceID);
+}
+
+mDNSlocal void NameCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
+{
+ (void)m; // Unused
+ (void)question; // Unused
+ (void)AddRecord; // Unused
+ if (!id.NotAnInteger) id = lastid;
+ if (answer->rrtype == kDNSType_PTR || answer->rrtype == kDNSType_CNAME)
+ {
+ ConvertDomainNameToCString(&answer->rdata->u.name, hostname);
+ StopNow = 1;
+ mprintf("%##s %s %##s\n", answer->name->c, DNSTypeName(answer->rrtype), answer->rdata->u.name.c);
+ }
+}
+
+mDNSlocal void InfoCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
+{
+ (void)m; // Unused
+ (void)question; // Unused
+ (void)AddRecord; // Unused
+ if (answer->rrtype == kDNSType_A)
+ {
+ if (!id.NotAnInteger) id = lastid;
+ NumAnswers++;
+ NumAddr++;
+ mprintf("%##s %s %.4a\n", answer->name->c, DNSTypeName(answer->rrtype), &answer->rdata->u.ipv4);
+ hostaddr.type = mDNSAddrType_IPv4; // Prefer v4 target to v6 target, for now
+ hostaddr.ip.v4 = answer->rdata->u.ipv4;
+ }
+ else if (answer->rrtype == kDNSType_AAAA)
+ {
+ if (!id.NotAnInteger) id = lastid;
+ NumAnswers++;
+ NumAAAA++;
+ mprintf("%##s %s %.16a\n", answer->name->c, DNSTypeName(answer->rrtype), &answer->rdata->u.ipv6);
+ if (!hostaddr.type) // Prefer v4 target to v6 target, for now
+ {
+ hostaddr.type = mDNSAddrType_IPv6;
+ hostaddr.ip.v6 = answer->rdata->u.ipv6;
+ }
+ }
+ else if (answer->rrtype == kDNSType_HINFO)
+ {
+ mDNSu8 *p = answer->rdata->u.data;
+ strncpy(hardware, (char*)(p+1), p[0]);
+ hardware[p[0]] = 0;
+ p += 1 + p[0];
+ strncpy(software, (char*)(p+1), p[0]);
+ software[p[0]] = 0;
+ NumAnswers++;
+ NumHINFO++;
+ }
+
+ // If we've got everything we're looking for, don't need to wait any more
+ if (/*NumHINFO && */ (NumAddr || NumAAAA)) StopNow = 1;
+}
+
+mDNSlocal void ServicesCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord)
+{
+ (void)m; // Unused
+ (void)question; // Unused
+ (void)AddRecord; // Unused
+ // Right now the mDNSCore targeted-query code is incomplete --
+ // it issues targeted queries, but accepts answers from anywhere
+ // For now, we'll just filter responses here so we don't get confused by responses from someone else
+ if (answer->rrtype == kDNSType_PTR && mDNSSameAddress(&lastsrc, &target))
+ {
+ NumAnswers++;
+ mprintf("%##s %s %##s\n", answer->name->c, DNSTypeName(answer->rrtype), answer->rdata->u.name.c);
+ }
+}
+
+mDNSlocal void WaitForAnswer(mDNS *const m, int seconds)
+{
+ struct timeval end;
+ gettimeofday(&end, NULL);
+ end.tv_sec += seconds;
+ StopNow = 0;
+ NumAnswers = 0;
+ while (!StopNow)
+ {
+ int nfds = 0;
+ fd_set readfds, writefds;
+ struct timeval now, remain = end;
+ int result;
+
+ FD_ZERO(&readfds);
+ FD_ZERO(&writefds);
+ gettimeofday(&now, NULL);
+ if (remain.tv_usec < now.tv_usec) { remain.tv_usec += 1000000; remain.tv_sec--; }
+ if (remain.tv_sec < now.tv_sec)
+ {
+ if (!NumAnswers) printf("No response after %d seconds\n", seconds);
+ return;
+ }
+ remain.tv_usec -= now.tv_usec;
+ remain.tv_sec -= now.tv_sec;
+ mDNSPosixGetFDSet(m, &nfds, &readfds, &writefds, &remain);
+ result = select(nfds, &readfds, &writefds, NULL, &remain);
+ if (result >= 0) mDNSPosixProcessFDSet(m, &readfds, &writefds);
+ else if (errno != EINTR) StopNow = 2;
+ }
+}