Home | History | Annotate | Download | only in mDNSShared

Lines Matching refs:request

93 typedef void (*req_termination_fn)(request_state *request);
100 request_state *request;
112 request_state *request;
141 // for each new request. This is because, until we've read the ipc_msg_hdr to find out what the
161 registered_record_entry *reg_recs; // list of registrations for a connection-oriented request
345 // We also set req->terminate to a bogus value so we know if abort_request() gets called again for this request
358 mDNSlocal reply_state *create_reply(const reply_op_t op, const size_t datalen, request_state *const request)
379 reply->mhdr->client_context = request->hdr.client_context;
385 // Append a reply to the list in a request object
386 // If our request is sharing a connection, then we append our reply_state onto the primary's list
400 request_state *const request, reply_state **const rep, reply_op_t op, DNSServiceFlags flags, mStatus err)
428 *rep = create_reply(op, len, request);
446 request_state *const request, reply_state **const rep, reply_op_t op, DNSServiceFlags flags, mStatus err)
471 *rep = create_reply(op, len, request);
486 mDNSlocal AuthRecord *read_rr_from_ipc_msg(request_state *request, int GetTTL, int validate_flags)
488 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
489 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
491 int str_err = get_string(&request->msgptr, request->msgend, name, sizeof(name));
492 mDNSu16 type = get_uint16(&request->msgptr, request->msgend);
493 mDNSu16 class = get_uint16(&request->msgptr, request->msgend);
494 mDNSu16 rdlen = get_uint16(&request->msgptr, request->msgend);
495 const char *rdata = get_rdata (&request->msgptr, request->msgend, rdlen);
496 mDNSu32 ttl = GetTTL ? get_uint32(&request->msgptr, request->msgend) : 0;
502 request->flags = flags;
506 if (!request->msgptr) { LogMsg("Error reading Resource Record from client"); return NULL; }
574 mDNSlocal mDNSBool AuthorizedDomain(const request_state * const request, const domainname * const d, const DNameListElem * const doms)
581 if (SystemUID(request->uid)) return mDNStrue;
593 allow = (allow || (delem->uid == request->uid));
614 if (mDNSIPPortIsZero(instance->request->u.servicereg.port))
630 for ( i = 0; i < instance->request->u.servicereg.num_subtypes; i++)
652 for ( i = 0; i < instance->request->u.servicereg.num_subtypes; i++)
691 if (srv->request)
693 service_instance **p = &srv->request->u.servicereg.instances;
749 if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request, &rep, reg_service_reply_op, 0, mStatus_NoError) != mStatus_NoError)
750 LogMsg("%3d: SendServiceRemovalNotification: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.resrec.name->c);
751 else { append_reply(instance->request, rep); instance->clientnotified = mDNSfalse; }
770 if (instance->request &&
771 instance->request->u.servicereg.default_domain &&
783 if (instance->request) mDNS_snprintf(prefix, sizeof(prefix), "%3d:", instance->request->sd);
788 if (!instance->request && result != mStatus_MemFree) { LogMsg("regservice_callback: instance->request is NULL %d", result); return; }
792 if (instance->request->u.servicereg.allowremotequery)
802 if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request, &rep, reg_service_reply_op, kDNSServiceFlagsAdd, result) != mStatus_NoError)
803 LogMsg("%3d: regservice_callback: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.resrec.name->c);
804 else { append_reply(instance->request, rep); instance->clientnotified = mDNStrue; }
806 if (instance->request->u.servicereg.InterfaceID == mDNSInterface_P2P || (!instance->request->u.servicereg.InterfaceID && SameDomainName(&instance->domain, &localdomain) && (instance->request->flags & kDNSServiceFlagsIncludeP2P)))
811 if (instance->request->u.servicereg.autoname && CountPeerRegistrations(m, srs) == 0)
816 if (instance->request && instance->renameonmemfree)
820 err = mDNS_RenameAndReregisterService(m, srs, &instance->request->u.servicereg.name);
829 if (instance->request->u.servicereg.autorename)
832 if (instance->request->u.servicereg.autoname && CountPeerRegistrations(m, srs) == 0)
848 if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request, &rep, reg_service_reply_op, kDNSServiceFlagsAdd, result) != mStatus_NoError)
849 LogMsg("%3d: regservice_callback: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.resrec.name->c);
850 else { append_reply(instance->request, rep); instance->clientnotified = mDNStrue; }
859 if (GenerateNTDResponse(srs->RR_SRV.resrec.name, srs->RR_SRV.resrec.InterfaceID, instance->request, &rep, reg_service_reply_op, kDNSServiceFlagsAdd, result) != mStatus_NoError)
860 LogMsg("%3d: regservice_callback: %##s is not valid DNS-SD SRV name", instance->request->sd, srs->RR_SRV.resrec.name->c);
861 else { append_reply(instance->request, rep); instance->clientnotified = mDNStrue; }
888 request_state *request = re->request;
896 LogOperation(fmt, request->sd, re->key, RRDisplayString(m, &rr->resrec), result);
902 reply_state *reply = create_reply(reg_record_reply_op, len, request);
907 append_reply(request, reply);
913 registered_record_entry **ptr = &request->u.reg_recs;
924 if (re->origInterfaceID == mDNSInterface_P2P || (!re->origInterfaceID && IsLocalDomain(&rr->namestorage) && (request->flags & kDNSServiceFlagsIncludeP2P)))
934 mDNSlocal void connection_termination(request_state *request)
940 LogOperation("%3d: DNSServiceCreateConnection STOP", request->sd);
944 if ((*req)->primary == request)
946 // Since we're already doing a list traversal, we unlink the request directly instead of using AbortUnlinkAndFree()
958 while (request->u.reg_recs)
960 registered_record_entry *ptr = request->u.reg_recs;
961 LogOperation("%3d: DNSServiceRegisterRecord(%u %s) STOP", request->sd, ptr->key, RRDisplayString(&mDNSStorage, &ptr->rr->resrec));
962 request->u.reg_recs = request->u.reg_recs->next;
974 mDNSlocal void handle_cancel_request(request_state *request)
977 LogOperation("%3d: Cancel %08X %08X", request->sd, request->hdr.client_context.u32[1], request->hdr.client_context.u32[0]);
980 if ((*req)->primary == request &&
981 (*req)->hdr.client_context.u32[0] == request->hdr.client_context.u32[0] &&
982 (*req)->hdr.client_context.u32[1] == request->hdr.client_context.u32[1])
984 // Since we're already doing a list traversal, we unlink the request directly instead of using AbortUnlinkAndFree()
995 mDNSlocal mStatus handle_regrecord_request(request_state *request)
998 AuthRecord *rr = read_rr_from_ipc_msg(request, 1, 1);
1014 re->key = request->hdr.reg_index;
1016 re->regrec_client_context = request->hdr.client_context;
1017 re->request = request;
1025 if (!AuthorizedDomain(request, rr->resrec.name, AutoRegistrationDomains)) return (mStatus_NoError);
1030 LogOperation("%3d: DNSServiceRegisterRecord(%u %s) START", request->sd, re->key, RRDisplayString(&mDNSStorage, &rr->resrec));
1034 LogOperation("%3d: DNSServiceRegisterRecord(%u %s) ERROR (%d)", request->sd, re->key, RRDisplayString(&mDNSStorage, &rr->resrec), err);
1040 re->next = request->u.reg_recs;
1041 request->u.reg_recs = re;
1049 mDNSlocal void regservice_termination_callback(request_state *request)
1051 if (!request) { LogMsg("regservice_termination_callback context is NULL"); return; }
1052 while (request->u.servicereg.instances)
1054 service_instance *p = request->u.servicereg.instances;
1055 request->u.servicereg.instances = request->u.servicereg.instances->next;
1058 request->sd, p->srs.RR_SRV.resrec.name->c, mDNSVal16(p->srs.RR_SRV.resrec.rdata->u.srv.port));
1064 // request->u.servicereg.instances as we work our way through the list, implicitly cutting one element at a time
1065 // We can't clear p->request *after* the calling mDNS_DeregisterService/unlink_and_free_service_instance
1067 p->request = NULL;
1071 if (request->u.servicereg.txtdata)
1072 { freeL("service_info txtdata", request->u.servicereg.txtdata); request->u.servicereg.txtdata = NULL; }
1073 if (request->u.servicereg.autoname)
1076 request->u.servicereg.autoname = mDNSfalse;
1081 mDNSlocal request_state *LocateSubordinateRequest(request_state *request)
1085 if (req->primary == request &&
1086 req->hdr.client_context.u32[0] == request->hdr.client_context.u32[0] &&
1087 req->hdr.client_context.u32[1] == request->hdr.client_context.u32[1]) return(req);
1088 return(request);
1091 mDNSlocal mStatus add_record_to_service(request_state *request, service_instance *instance, mDNSu16 rrtype, mDNSu16 rdlen, const char *rdata, mDNSu32 ttl)
1106 (request->flags & kDNSServiceFlagsIncludeP2P) ? 1: 0);
1109 extra->ClientID = request->hdr.reg_index;
1110 if (instance->external_advertise && (instance->request->u.servicereg.InterfaceID == mDNSInterface_P2P || (!instance->request->u.servicereg.InterfaceID && SameDomainName(&instance->domain, &localdomain) && (instance->request->flags & kDNSServiceFlagsIncludeP2P))))
1118 mDNSlocal mStatus handle_add_request(request_state *request)
1122 DNSServiceFlags flags = get_flags (&request->msgptr, request->msgend);
1123 mDNSu16 rrtype = get_uint16(&request->msgptr, request->msgend);
1124 mDNSu16 rdlen = get_uint16(&request->msgptr, request->msgend);
1125 const char *rdata = get_rdata (&request->msgptr, request->msgend, rdlen);
1126 mDNSu32 ttl = get_uint32(&request->msgptr, request->msgend);
1130 if (!request->msgptr) { LogMsg("%3d: DNSServiceAddRecord(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
1133 if (request->terminate == connection_termination) request = LocateSubordinateRequest(request);
1135 if (request->terminate != regservice_termination_callback)
1136 { LogMsg("%3d: DNSServiceAddRecord(not a registered service ref)", request->sd); return(mStatus_BadParamErr); }
1140 if (mDNSIPPortIsZero(request->u.servicereg.port))
1141 { LogMsg("%3d: DNSServiceAddRecord: adding record to a service registered with zero port", request->sd); return(mStatus_BadParamErr); }
1143 LogOperation("%3d: DNSServiceAddRecord(%X, %##s, %s, %d)", request->sd, flags,
1144 (request->u.servicereg.instances) ? request->u.servicereg.instances->srs.RR_SRV.resrec.name->c : NULL, DNSTypeName(rrtype), rdlen);
1146 for (i = request->u.servicereg.instances; i; i = i->next)
1148 result = add_record_to_service(request, i, rrtype, rdlen, rdata, ttl);
1204 mDNSlocal mStatus handle_update_request(request_state *request)
1206 const ipc_msg_hdr *const hdr = &request->hdr;
1212 DNSServiceFlags flags = get_flags (&request->msgptr, request->msgend); // flags unused
1213 mDNSu16 rdlen = get_uint16(&request->msgptr, request->msgend);
1214 const char *rdata = get_rdata (&request->msgptr, request->msgend, rdlen);
1215 mDNSu32 ttl = get_uint32(&request->msgptr, request->msgend);
1218 if (!request->msgptr) { LogMsg("%3d: DNSServiceUpdateRecord(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
1221 if (request->terminate == connection_termination) request = LocateSubordinateRequest(request);
1223 if (request->terminate == connection_termination)
1227 for (reptr = request->u.reg_recs; reptr; reptr = reptr->next)
1233 request->sd, reptr->rr->resrec.name->c, reptr->rr ? DNSTypeName(reptr->rr->resrec.rrtype) : "<NONE>");
1241 if (request->terminate != regservice_termination_callback)
1242 { LogMsg("%3d: DNSServiceUpdateRecord(not a registered service ref)", request->sd); return(mStatus_BadParamErr); }
1245 if (mDNSIPPortIsZero(request->u.servicereg.port))
1246 request->sd); return(mStatus_BadParamErr); }
1251 if (request->u.servicereg.txtdata)
1252 { freeL("service_info txtdata", request->u.servicereg.txtdata); request->u.servicereg.txtdata = NULL; }
1255 request->u.servicereg.txtdata = mallocL("service_info txtdata", rdlen);
1256 if (!request->u.servicereg.txtdata) FatalError("ERROR: handle_update_request - malloc");
1257 mDNSPlatformMemCopy(request->u.servicereg.txtdata, rdata, rdlen);
1259 request->u.servicereg.txtlen = rdlen;
1263 for (i = request->u.servicereg.instances; i; i = i->next)
1280 if (request->terminate == regservice_termination_callback)
1281 LogOperation("%3d: DNSServiceUpdateRecord(%##s, %s)", request->sd,
1282 (request->u.servicereg.instances) ? request->u.servicereg.instances->srs.RR_SRV.resrec.name->c : NULL,
1289 mDNSlocal mStatus remove_record(request_state *request)
1292 registered_record_entry *e, **ptr = &request->u.reg_recs;
1294 while (*ptr && (*ptr)->key != request->hdr.reg_index) ptr = &(*ptr)->next;
1295 if (!*ptr) { LogMsg("%3d: DNSServiceRemoveRecord(%u) not found", request->sd, request->hdr.reg_index); return mStatus_BadReferenceErr; }
1299 LogOperation("%3d: DNSServiceRemoveRecord(%u %s)", request->sd, e->key, RRDisplayString(&mDNSStorage, &e->rr->resrec));
1317 mDNSlocal mStatus remove_extra(const request_state *const request, service_instance *const serv, mDNSu16 *const rrtype)
1324 if (ptr->ClientID == request->hdr.reg_index) // found match
1335 mDNSlocal mStatus handle_removerecord_request(request_state *request)
1338 get_flags(&request->msgptr, request->msgend); // flags unused
1340 if (!request->msgptr) { LogMsg("%3d: DNSServiceRemoveRecord(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
1343 if (request->terminate == connection_termination) request = LocateSubordinateRequest(request);
1345 if (request->terminate == connection_termination)
1346 err = remove_record(request); // remove individually registered record
1347 else if (request->terminate != regservice_termination_callback)
1348 { LogMsg("%3d: DNSServiceRemoveRecord(not a registered service ref)", request->sd); return(mStatus_BadParamErr); }
1353 LogOperation("%3d: DNSServiceRemoveRecord(%##s, %s)", request->sd,
1354 (request->u.servicereg.instances) ? request->u.servicereg.instances->srs.RR_SRV.resrec.name->c : NULL,
1356 for (i = request->u.servicereg.instances; i; i = i->next)
1358 err = remove_extra(request, i, &rrtype);
1438 mDNSlocal mStatus register_service_instance(request_state *request, const domainname *domain)
1441 const int extra_size = (request->u.servicereg.txtlen > sizeof(RDataBody)) ? (request->u.servicereg.txtlen - sizeof(RDataBody)) : 0;
1444 mDNSInterfaceID interfaceID = request->u.servicereg.InterfaceID;
1452 else if (request->flags & kDNSServiceFlagsIncludeP2P)
1456 if (request->flags & kDNSServiceFlagsForce)
1464 if (request->u.servicereg.default_domain && !DomainIsLocal) interfaceID = mDNSInterface_Any;
1466 for (ptr = &request->u.servicereg.instances; *ptr; ptr = &(*ptr)->next)
1471 domain->c, &request->u.servicereg.name, &request->u.servicereg.type);
1481 if (SameDomainName(&request->u.servicereg.type, (const domainname *) "\x4" "_smb" "\x4" "_tcp"))
1492 instance->request = request;
1493 instance->subtypes = AllocateSubTypes(request->u.servicereg.num_subtypes, request->u.servicereg.type_as_string);
1496 instance->default_local = (request->u.servicereg.default_domain && DomainIsLocal);
1500 if (request->u.servicereg.num_subtypes && !instance->subtypes)
1504 &request->u.servicereg.name, &request->u.servicereg.type, domain,
1505 request->u.servicereg.host.c[0] ? &request->u.servicereg.host : NULL,
1506 request->u.servicereg.port,
1507 request->u.servicereg.txtdata, request->u.servicereg.txtlen,
1508 instance->subtypes, request->u.servicereg.num_subtypes,
1513 *ptr = instance; // Append this to the end of our request->u.servicereg.instances list
1515 instance->request->sd, instance->srs.RR_SRV.resrec.name->c, mDNSVal16(request->u.servicereg.port));
1520 &request->u.servicereg.name, &request->u.servicereg.type, domain->c, result);
1529 request_state *request;
1536 for (request = all_requests; request; request = request->next)
1538 if (request->terminate != regservice_termination_callback) continue;
1539 if (!request->u.servicereg.default_domain) continue;
1540 if (!d->uid || SystemUID(request->uid) || request->uid == d->uid)
1542 service_instance **ptr = &request->u.servicereg.instances;
1547 if (!*ptr) register_service_instance(request, &d->name);
1557 &d->name, request->u.servicereg.name.c, request->u.servicereg.type_as_string);
1562 if (!p->uid || SystemUID(request->uid) || request->uid == p->uid)
1570 if (si->clientnotified) SendServiceRemovalNotification(&si->srs); // Do this *before* clearing si->request backpointer
1571 // Now that we've cut this service_instance from the list, we MUST clear the si->request backpointer.
1579 // a service_instance with a stale si->request backpointer pointing to memory that's already been freed.
1580 si->request = NULL;
1590 mDNSlocal mStatus handle_regservice_request(request_state *request)
1598 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
1599 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
1604 if (get_string(&request->msgptr, request->msgend, name, sizeof(name)) < 0 ||
1605 get_string(&request->msgptr, request->msgend, type_as_string, MAX_ESCAPED_DOMAIN_NAME) < 0 ||
1606 get_string(&request->msgptr, request->msgend, domain, MAX_ESCAPED_DOMAIN_NAME) < 0 ||
1607 get_string(&request->msgptr, request->msgend, host, MAX_ESCAPED_DOMAIN_NAME) < 0)
1610 request->flags = flags;
1611 request->u.servicereg.InterfaceID = InterfaceID;
1612 request->u.servicereg.instances = NULL;
1613 request->u.servicereg.txtlen = 0;
1614 request->u.servicereg.txtdata = NULL;
1615 mDNSPlatformStrCopy(request->u.servicereg.type_as_string, type_as_string);
1617 if (request->msgptr + 2 > request->msgend) request->msgptr = NULL;
1620 request->u.servicereg.port.b[0] = *request->msgptr++;
1621 request->u.servicereg.port.b[1] = *request->msgptr++;
1624 request->u.servicereg.txtlen = get_uint16(&request->msgptr, request->msgend);
1625 if (request->u.servicereg.txtlen)
1627 request->u.servicereg.txtdata = mallocL("service_info txtdata", request->u.servicereg.txtlen);
1628 if (!request->u.servicereg.txtdata) FatalError("ERROR: handle_regservice_request - malloc");
1629 mDNSPlatformMemCopy(request->u.servicereg.txtdata, get_rdata(&request->msgptr, request->msgend, request->u.servicereg.txtlen), request->u.servicereg.txtlen);
1632 if (!request->msgptr) { LogMsg("%3d: DNSServiceRegister(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
1635 request->u.servicereg.num_subtypes = ChopSubTypes(request->u.servicereg.type_as_string); // Note: Modifies regtype string to remove trailing subtypes
1636 if (request->u.servicereg.num_subtypes < 0)
1637 { LogMsg("ERROR: handle_regservice_request - ChopSubTypes failed %s", request
1640 if (!*request->u.servicereg.type_as_string || !MakeDomainNameFromDNSNameString(&request->u.servicereg.type, request->u.servicereg.type_as_string))
1641 { LogMsg("ERROR: handle_regservice_request - type_as_string bad %s", request->u.servicereg.type_as_string); return(mStatus_BadParamErr); }
1645 request->u.servicereg.name = mDNSStorage.nicelabel;
1646 request->u.servicereg.autoname = mDNStrue;
1656 if (!MakeDomainLabelFromLiteralString(&request->u.servicereg.name, name))
1658 request->u.servicereg.autoname = mDNSfalse;
1663 request->u.servicereg.default_domain = mDNSfalse;
1669 request->u.servicereg.default_domain = mDNStrue;
1673 if (!ConstructServiceName(&srv, &request->u.servicereg.name, &request->u.servicereg.type, &d))
1676 request->u.servicereg.name.c, request->u.servicereg.type.c, d.c); return(mStatus_BadParamErr);
1679 if (!MakeDomainNameFromDNSNameString(&request->u.servicereg.host, host))
1681 request->u.servicereg.autorename = (flags & kDNSServiceFlagsNoAutoRename ) == 0;
1682 request->u.servicereg.allowremotequery = (flags & kDNSServiceFlagsAllowRemoteQuery) != 0;
1687 if (!mDNSIPPortIsZero(request->u.servicereg.port))
1689 int count = CountExistingRegistrations(&srv, request->u.servicereg.port);
1692 count+1, srv.c, mDNSVal16(request->u.servicereg.port));
1696 request->sd, flags, interfaceIndex, name, request->u.servicereg.type_as_string, domain, host, mDNSVal16(request->u.servicereg.port));
1698 // We need to unconditionally set request->terminate, because even if we didn't successfully
1701 // We also need to set request->terminate first, before adding additional service instances,
1702 // because the uds_validatelists uses the request->terminate function pointer to determine
1703 // what kind of request this is, and therefore what kind of list validation is required.
1704 request->terminate = regservice_termination_callback;
1706 err = register_service_instance(request, &d);
1709 err = AuthorizedDomain(request, &d, AutoRegistrationDomains) ? register_service_instance(request, &d) : mStatus_NoError;
1713 if (request->u.servicereg.autoname) UpdateDeviceInfoRecord(&mDNSStorage);
1720 if (!ptr->uid || SystemUID(request->uid) || request->uid == ptr->uid)
1721 register_service_instance(request, &ptr->name);
1828 request_state *request;
1835 for (request = all_requests; request; request = request->next)
1837 if (request->terminate != browse_termination_callback) continue; // Not a browse operation
1838 if (!request->u.browser.default_domain) continue; // Not an auto-browse operation
1839 if (!d->uid || SystemUID(request->uid) || request->uid == d->uid)
1841 browser_t **ptr = &request->u.browser.browsers;
1846 if (!*ptr) add_domain_to_browser(request, &d->name);
1856 if (!p->uid || SystemUID(request->uid) || request->uid == p->uid)
2120 mDNSlocal mStatus handle_sethost_request(request_state *request)
2122 get_flags(&request->msgptr, request->msgend);
2126 if (get_string(&request->msgptr, request->msgend, hostName, MAX_DOMAIN_LABEL) < 0) return(mStatus_BadParamErr);
2129 request->sd, request->flags);
2132 // request->terminate = sethost_termination_callback;
2147 mDNSlocal mStatus handle_browse_request(request_state *request)
2154 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
2155 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
2159 if (get_string(&request->msgptr, request->msgend, regtype, MAX_ESCAPED_DOMAIN_NAME) < 0 ||
2160 get_string(&request->msgptr, request->msgend, domain, MAX_ESCAPED_DOMAIN_NAME) < 0) return(mStatus_BadParamErr);
2162 if (!request->msgptr) { LogMsg("%3d: DNSServiceBrowse(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
2166 request->flags = flags;
2179 request->u.browser.ForceMCast = (flags & kDNSServiceFlagsForceMulticast) != 0;
2180 request->u.browser.interface_id = InterfaceID;
2181 AssignDomainName(&request->u.browser.regtype, &typedn);
2182 request->u.browser.default_domain = !domain[0];
2183 request->u.browser.browsers = NULL;
2186 request->sd, request->flags, interfaceIndex, request->u.browser.regtype.c, domain);
2188 // We need to unconditionally set request->terminate, because even if we didn't successfully
2191 request->terminate = browse_termination_callback;
2196 err = add_domain_to_browser(request, &d);
2198 err = AuthorizedDomain(request, &d, AutoBrowseDomains) ? add_domain_to_browser(request, &d) : mStatus_NoError;
2205 if (!sdom->uid || SystemUID(request->uid) || request->uid == sdom->uid)
2207 err = add_domain_to_browser(request, &sdom->name);
2280 mDNSlocal void resolve_termination_callback(request_state *request)
2282 LogOperation("%3d: DNSServiceResolve(%##s) STOP", request->sd, request->u.resolve.qtxt.qname.c);
2283 mDNS_StopQuery(&mDNSStorage, &request->u.resolve.qtxt);
2284 mDNS_StopQuery(&mDNSStorage, &request->u.resolve.qsrv);
2285 if (request->u.resolve.external_advertise) external_stop_resolving_service(&request->u.resolve.qsrv.qname);
2288 mDNSlocal mStatus handle_resolve_request(request_state *request)
2295 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
2296 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
2301 request->flags = flags;
2308 if (get_string(&request->msgptr, request->msgend, name, 256) < 0 ||
2309 get_string(&request->msgptr, request->msgend, regtype, MAX_ESCAPED_DOMAIN_NAME) < 0 ||
2310 get_string(&request->msgptr, request->msgend, domain, MAX_ESCAPED_DOMAIN_NAME) < 0)
2313 if (!request->msgptr) { LogMsg("%3d: DNSServiceResolve(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
2318 mDNSPlatformMemZero(&request->u.resolve, sizeof(request->u.resolve));
2321 request->u.resolve.qsrv.InterfaceID = InterfaceID;
2322 request->u.resolve.qsrv.Target = zeroAddr;
2323 AssignDomainName(&request->u.resolve.qsrv.qname, &fqdn);
2324 request->u.resolve.qsrv.qtype = kDNSType_SRV;
2325 request->u.resolve.qsrv.qclass = kDNSClass_IN;
2326 request->u.resolve.qsrv.LongLived = (flags & kDNSServiceFlagsLongLivedQuery ) != 0;
2327 request->u.resolve.qsrv.ExpectUnique = mDNStrue;
2328 request->u.resolve.qsrv.ForceMCast = (flags & kDNSServiceFlagsForceMulticast ) != 0;
2329 request->u.resolve.qsrv.ReturnIntermed = (flags & kDNSServiceFlagsReturnIntermediates) != 0;
2330 request->u.resolve.qsrv.SuppressUnusable = mDNSfalse;
2331 request->u.resolve.qsrv.SearchListIndex = 0;
2332 request->u.resolve.qsrv.AppendSearchDomains = 0;
2333 request->u.resolve.qsrv.RetryWithSearchDomains = mDNSfalse;
2334 request->u.resolve.qsrv.TimeoutQuestion = 0;
2335 request->u.resolve.qsrv.WakeOnResolve = (flags & kDNSServiceFlagsWakeOnResolve) != 0;
2336 request->u.resolve.qsrv.qnameOrig = mDNSNULL;
2337 request->u.resolve.qsrv.QuestionCallback = resolve_result_callback;
2338 request->u.resolve.qsrv.QuestionContext = request;
2340 request->u.resolve.qtxt.InterfaceID = InterfaceID;
2341 request->u.resolve.qtxt.Target = zeroAddr;
2342 AssignDomainName(&request->u.resolve.qtxt.qname, &fqdn);
2343 request->u.resolve.qtxt.qtype = kDNSType_TXT;
2344 request->u.resolve.qtxt.qclass = kDNSClass_IN;
2345 request->u.resolve.qtxt.LongLived = (flags & kDNSServiceFlagsLongLivedQuery ) != 0;
2346 request->u.resolve.qtxt.ExpectUnique = mDNStrue;
2347 request->u.resolve.qtxt.ForceMCast = (flags & kDNSServiceFlagsForceMulticast ) != 0;
2348 request->u.resolve.qtxt.ReturnIntermed = (flags & kDNSServiceFlagsReturnIntermediates) != 0;
2349 request->u.resolve.qtxt.SuppressUnusable = mDNSfalse;
2350 request->u.resolve.qtxt.SearchListIndex = 0;
2351 request->u.resolve.qtxt.AppendSearchDomains = 0;
2352 request->u.resolve.qtxt.RetryWithSearchDomains = mDNSfalse;
2353 request->u.resolve.qtxt.TimeoutQuestion = 0;
2354 request->u.resolve.qtxt.WakeOnResolve = 0;
2355 request->u.resolve.qtxt.qnameOrig = mDNSNULL;
2356 request->u.resolve.qtxt.QuestionCallback = resolve_result_callback;
2357 request->u.resolve.qtxt.QuestionContext = request;
2359 request->u.resolve.ReportTime = NonZeroTime(mDNS_TimeNow(&mDNSStorage) + 130 * mDNSPlatformOneSecond);
2361 request->u.resolve.external_advertise = mDNSfalse;
2364 if (!AuthorizedDomain(request, &fqdn, AutoBrowseDomains)) return(mStatus_NoError);
2368 LogOperation("%3d: DNSServiceResolve(%##s) START", request->sd, request->u.resolve.qsrv.qname.c);
2369 err = mDNS_StartQuery(&mDNSStorage, &request->u.resolve.qsrv);
2372 err = mDNS_StartQuery(&mDNSStorage, &request->u.resolve.qtxt);
2373 if (err) mDNS_StopQuery(&mDNSStorage, &request->u.resolve.qsrv);
2376 request->terminate = resolve_termination_callback;
2378 if (wasP2P || (!InterfaceID && IsLocalDomain(&fqdn) && (request->flags & kDNSServiceFlagsIncludeP2P)))
2380 request->u.resolve.external_advertise = mDNStrue;
2396 // mDNS operation functions. Each operation has 3 associated functions - a request handler that parses
2397 // the client's request and makes the appropriate mDNSCore call, a result handler (passed as a callback
2488 mDNSlocal mStatus SendAdditionalQuery(DNSQuestion *q, request_state *request, mStatus err)
2496 if (request->hdr.op == query_request)
2497 question2 = &request->u.queryrecord.q2;
2498 else if (request->hdr.op == addrinfo_request)
2501 question2 = &request->u.addrinfo.q42;
2503 question2 = &request->u.addrinfo.q62;
2576 LogOperation("%3d: DNSServiceQueryRecord(%##s, %s) unicast", request->sd, q2->qname.c, DNSTypeName(q2->qtype));
2578 if (err) LogMsg("%3d: ERROR: DNSServiceQueryRecord %##s %s mDNS_StartQuery: %d", request->sd, q2->qname.c, DNSTypeName(q2->qtype), (int)err);
2918 mDNSlocal void queryrecord_termination_callback(request_state *request)
2921 request->sd, request->u.queryrecord.q.qname.c, DNSTypeName(request->u.queryrecord.q.qtype));
2922 if (request->u.queryrecord.q.QuestionContext)
2924 mDNS_StopQuery(&mDNSStorage, &request->u.queryrecord.q); // no need to error check
2925 request->u.queryrecord.q.QuestionContext = mDNSNULL;
2929 DNSQuestion *question = &request->u.queryrecord.q;
2933 if (request->u.queryrecord.q.qnameOrig)
2935 freeL("QueryTermination", request->u.queryrecord.q.qnameOrig);
2936 request->u.queryrecord.q.qnameOrig = mDNSNULL;
2938 if (request->u.queryrecord.q.InterfaceID == mDNSInterface_P2P || (!request->u.queryrecord.q.InterfaceID && SameDomainName((const domainname *)LastLabel(&request->u.queryrecord.q.qname), &localdomain) && (request->flags & kDNSServiceFlagsIncludeP2P)))
2941 external_stop_browsing_for_service(&mDNSStorage, &request->u.queryrecord.q.qname, request->u.queryrecord.q.qtype);
2943 if (request->u.queryrecord.q2)
2945 if (request->u.queryrecord.q2->QuestionContext)
2947 LogInfo("queryrecord_termination_callback: Stopping q2 %##s", request->u.queryrecord.q2->qname.c);
2948 mDNS_StopQuery(&mDNSStorage, request->u.queryrecord.q2);
2952 DNSQuestion *question = request->u.queryrecord.q2;
2955 if (request->u.queryrecord.q2->qnameOrig)
2957 LogInfo("queryrecord_termination_callback: freeing q2 qnameOrig %##s", request->u.queryrecord.q2->qnameOrig->c);
2958 freeL("QueryTermination q2", request->u.queryrecord.q2->qnameOrig);
2959 request->u.queryrecord.q2->qnameOrig = mDNSNULL;
2961 freeL("queryrecord Q2", request->u.queryrecord.q2);
2962 request->u.queryrecord.q2 = mDNSNULL;
2966 mDNSlocal mStatus handle_queryrecord_request(request_state *request)
2968 DNSQuestion *const q = &request->u.queryrecord.q;
2973 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
2974 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
2978 if (get_string(&request->msgptr, request->msgend, name, 256) < 0) return(mStatus_BadParamErr);
2979 rrtype = get_uint16(&request->msgptr, request->msgend);
2980 rrclass = get_uint16(&request->msgptr, request->msgend);
2982 if (!request->msgptr)
2983 { LogMsg("%3d: DNSServiceQueryRecord(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
2985 request->flags = flags;
2986 mDNSPlatformMemZero(&request->u.queryrecord, sizeof(request->u.queryrecord));
2992 if (!AuthorizedDomain(request, &q->qname, AutoBrowseDomains)) return (mStatus_NoError);
3004 q->QuestionContext = request;
3035 LogOperation("%3d: DNSServiceQueryRecord(%X, %d, %##s, %s) START", request->sd, flags, interfaceIndex, q->qname.c, DNSTypeName(q->qtype));
3037 if (err) LogMsg("%3d: ERROR: DNSServiceQueryRecord %##s %s mDNS_StartQuery: %d", request->sd, q->qname.c, DNSTypeName(q->qtype), (int)err);
3040 request->terminate = queryrecord_termination_callback;
3049 err = SendAdditionalQuery(q, request, err);
3061 mDNSlocal reply_state *format_enumeration_reply(request_state *request,
3073 reply = create_reply(enumeration_reply_op, len, request);
3082 mDNSlocal void enum_termination_callback(request_state *request)
3084 mDNS_StopGetDomains(&mDNSStorage, &request->u.enumeration.q_all);
3085 mDNS_StopGetDomains(&mDNSStorage, &request->u.enumeration.q_default);
3092 request_state *request = question->QuestionContext;
3100 if (!AuthorizedDomain(request, &answer->rdata->u.name, request->u.enumeration.flags ? AutoRegistrationDomains : AutoBrowseDomains)) return;
3105 if (question == &request->u.enumeration.q_default && !AddRecord) return;
3110 if (question == &request->u.enumeration.q_default) flags |= kDNSServiceFlagsDefault;
3117 reply = format_enumeration_reply(request, domain, flags, kDNSServiceInterfaceIndexAny, kDNSServiceErr_NoError);
3120 request->sd, question->qname.c, AddRecord ? "Add" : "Rmv", domain);
3122 append_reply(request, reply);
3125 mDNSlocal mStatus handle_enum_request(request_state *request)
3128 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
3132 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
3136 if (!request->msgptr)
3137 { LogMsg("%3d: DNSServiceEnumerateDomains(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
3144 request->u.enumeration.flags = reg;
3149 request->u.enumeration.q_all .QuestionContext = request;
3150 request->u.enumeration.q_default.QuestionContext = request;
3156 LogOperation("%3d: DNSServiceEnumerateDomains(%X=%s)", request->sd, flags,
3159 err = mDNS_GetDomains(&mDNSStorage, &request->u.enumeration.q_all, t_all, NULL, InterfaceID, enum_result_callback, request);
3162 err = mDNS_GetDomains(&mDNSStorage, &request->u.enumeration.q_default, t_default, NULL, InterfaceID, enum_result_callback, request);
3163 if (err) mDNS_StopGetDomains(&mDNSStorage, &request->u.enumeration.q_all);
3164 else request->terminate = enum_termination_callback;
3176 mDNSlocal mStatus handle_reconfirm_request(request_state *request)
3179 AuthRecord *rr = read_rr_from_ipc_msg(request, 0, 0);
3187 request->sd, RRDisplayString(&mDNSStorage, &rr->resrec),
3194 mDNSlocal mStatus handle_setdomain_request(request_state *request)
3198 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
3200 if (get_string(&request->msgptr, request->msgend, domainstr, MAX_ESCAPED_DOMAIN_NAME) < 0 ||
3202 { LogMsg("%3d: DNSServiceSetDefaultDomainForUser(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
3204 LogOperation("%3d: DNSServiceSetDefaultDomainForUser(%##s)", request->sd, domain.c);
3215 mDNSlocal void handle_getproperty_request(request_state *request)
3219 if (get_string(&request->msgptr, request->msgend, prop, sizeof(prop)) >= 0)
3221 LogOperation("%3d: DNSServiceGetProperty(%s)", request->sd, prop);
3225 send_all(request->sd, (const char *)&x, sizeof(x));
3231 send_all(request->sd, (const char *)&BadParamErr, sizeof(BadParamErr));
3242 mDNSlocal void port_mapping_termination_callback(request_state *request)
3244 LogOperation("%3d: DNSServiceNATPortMappingCreate(%X, %u, %u, %d) STOP", request->sd,
3245 DNSServiceProtocol(request->u.pm.NATinfo.Protocol),
3246 mDNSVal16(request->u.pm.NATinfo.IntPort), mDNSVal16(request->u.pm.ReqExt), request->u.pm.NATinfo.NATLease);
3247 mDNS_StopNATOperation(&mDNSStorage, &request->u.pm.NATinfo);
3250 // Called via function pointer when we get a NAT-PMP address request or port mapping response
3253 request_state *request = (request_state *)n->clientContext;
3258 if (!request) { LogMsg("port_mapping_create_request_callback called with unknown request_state object"); return; }
3267 rep = create_reply(port_mapping_reply_op, replyLen, request);
3275 *data++ = request->u.pm.NATinfo.ExternalAddress.b[0];
3276 *data++ = request->u.pm.NATinfo.ExternalAddress.b[1];
3277 *data++ = request->u.pm.NATinfo.ExternalAddress.b[2];
3278 *data++ = request->u.pm.NATinfo.ExternalAddress.b[3];
3279 *data++ = DNSServiceProtocol(request->u.pm.NATinfo.Protocol);
3280 *data++ = request->u.pm.NATinfo.IntPort.b[0];
3281 *data++ = request->u.pm.NATinfo.IntPort.b[1];
3282 *data++ = request->u.pm.NATinfo.ExternalPort.b[0];
3283 *data++ = request->u.pm.NATinfo.ExternalPort.b[1];
3284 put_uint32(request->u.pm.NATinfo.Lifetime, &data);
3286 LogOperation("%3d: DNSServiceNATPortMappingCreate(%X, %u, %u, %d) RESULT %.4a:%u TTL %u", request->sd,
3287 DNSServiceProtocol(request->u.pm.NATinfo.Protocol),
3288 mDNSVal16(request->u.pm.NATinfo.IntPort), mDNSVal16(request->u.pm.ReqExt), request->u.pm.NATinfo.NATLease,
3289 &request->u.pm.NATinfo.ExternalAddress, mDNSVal16(request->u.pm.NATinfo.ExternalPort), request->u.pm.NATinfo.Lifetime);
3291 append_reply(request, rep);
3294 mDNSlocal mStatus handle_port_mapping_request(request_state *request)
3299 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
3300 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
3302 mDNSu8 protocol = (mDNSu8)get_uint32(&request->msgptr, request->msgend);
3305 if (request->msgptr + 8 > request->msgend) request->msgptr = NULL;
3308 request->u.pm.NATinfo.IntPort.b[0] = *request->msgptr++;
3309 request->u.pm.NATinfo.IntPort.b[1] = *request->msgptr++;
3310 request->u.pm.ReqExt.b[0] = *request->msgptr++;
3311 request->u.pm.ReqExt.b[1] = *request->msgptr++;
3312 ttl = get_uint32(&request->msgptr, request->msgend);
3315 if (!request->msgptr)
3316 { LogMsg("%3d: DNSServiceNATPortMappingCreate(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
3318 if (protocol == 0) // If protocol == 0 (i.e. just request public address) then IntPort, ExtPort, ttl must be zero too
3320 if (!mDNSIPPortIsZero(request->u.pm.NATinfo.IntPort) || !mDNSIPPortIsZero(request->u.pm.ReqExt) || ttl) return(mStatus_BadParamErr);
3324 if (mDNSIPPortIsZero(request->u.pm.NATinfo.IntPort)) return(mStatus_BadParamErr);
3328 request->u.pm.NATinfo.Protocol = !protocol ? NATOp_AddrRequest : (protocol == kDNSServiceProtocol_UDP) ? NATOp_MapUDP : NATOp_MapTCP;
3330 request->u.pm.NATinfo.RequestedPort = request->u.pm.ReqExt;
3331 request->u.pm.NATinfo.NATLease = ttl;
3332 request->u.pm.NATinfo.clientCallback = port_mapping_create_request_callback;
3333 request->u.pm.NATinfo.clientContext = request;
3335 LogOperation("%3d: DNSServiceNATPortMappingCreate(%X, %u, %u, %d) START", request->sd,
3336 protocol, mDNSVal16(request->u.pm.NATinfo.IntPort), mDNSVal16(request->u.pm.ReqExt), request->u.pm.NATinfo.NATLease);
3337 err = mDNS_StartNATOperation(&mDNSStorage, &request->u.pm.NATinfo);
3339 else request->terminate = port_mapping_termination_callback;
3350 mDNSlocal void addrinfo_termination_callback(request_state *request)
3352 LogOperation("%3d: DNSServiceGetAddrInfo(%##s) STOP", request->sd, request->u.addrinfo.q4.qname.c);
3354 if (request->u.addrinfo.q4.QuestionContext)
3356 mDNS_StopQuery(&mDNSStorage, &request->u.addrinfo.q4);
3357 request->u.addrinfo.q4.QuestionContext = mDNSNULL;
3359 if (request->u.addrinfo.q4.qnameOrig)
3361 freeL("QueryTermination", request->u.addrinfo.q4.qnameOrig);
3362 request->u.addrinfo.q4.qnameOrig = mDNSNULL;
3364 if (request->u.addrinfo.q42)
3366 if (request->u.addrinfo.q42->QuestionContext)
3368 LogInfo("addrinfo_termination_callback: Stopping q42 %##s", request->u.addrinfo.q42->qname.c);
3369 mDNS_StopQuery(&mDNSStorage, request->u.addrinfo.q42);
3371 if (request->u.addrinfo.q42->qnameOrig)
3373 LogInfo("addrinfo_termination_callback: freeing q42 qnameOrig %##s", request->u.addrinfo.q42->qnameOrig->c);
3374 freeL("QueryTermination q42", request->u.addrinfo.q42->qnameOrig);
3375 request->u.addrinfo.q42->qnameOrig = mDNSNULL;
3377 freeL("addrinfo Q42", request->u.addrinfo.q42);
3378 request->u.addrinfo.q42 = mDNSNULL;
3381 if (request->u.addrinfo.q6.QuestionContext)
3383 mDNS_StopQuery(&mDNSStorage, &request->u.addrinfo.q6);
3384 request->u.addrinfo.q6.QuestionContext = mDNSNULL;
3386 if (request->u.addrinfo.q6.qnameOrig)
3388 freeL("QueryTermination", request->u.addrinfo.q6.qnameOrig);
3389 request->u.addrinfo.q6.qnameOrig = mDNSNULL;
3391 if (request->u.addrinfo.q62)
3393 if (request->u.addrinfo.q62->QuestionContext)
3395 LogInfo("addrinfo_termination_callback: Stopping q62 %##s", request->u.addrinfo.q62->qname.c);
3396 mDNS_StopQuery(&mDNSStorage, request->u.addrinfo.q62);
3398 if (request->u.addrinfo.q62->qnameOrig)
3400 LogInfo("addrinfo_termination_callback: freeing q62 qnameOrig %##s", request->u.addrinfo.q62->qnameOrig->c);
3401 freeL("QueryTermination q62", request->u.addrinfo.q62->qnameOrig);
3402 request->u.addrinfo.q62->qnameOrig = mDNSNULL;
3404 freeL("addrinfo Q62", request->u.addrinfo.q62);
3405 request->u.addrinfo.q62 = mDNSNULL;
3409 mDNSlocal mStatus handle_addrinfo_request(request_state *request)
3415 DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend);
3416 mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
3418 mDNSPlatformMemZero(&request->u.addrinfo, sizeof(request->u.addrinfo));
3419 request->u.addrinfo.interface_id = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex);
3420 request->u.addrinfo.flags = flags;
3421 request->u.addrinfo.protocol = get_uint32(&request->msgptr, request->msgend);
3423 if (interfaceIndex && !request->u.addrinfo.interface_id) return(mStatus_BadParamErr);
3424 if (request->u.addrinfo.protocol > (kDNSServiceProtocol_IPv4|kDNSServiceProtocol_IPv6)) return(mStatus_BadParamErr);
3426 if (get_string(&request->msgptr, request->msgend, hostname, 256) < 0) return(mStatus_BadParamErr);
3428 if (!request->msgptr) { LogMsg("%3d: DNSServiceGetAddrInfo(unreadable parameters)", request->sd); return(mStatus_BadParamErr); }
3434 if (!AuthorizedDomain(request, &d, AutoBrowseDomains)) return (mStatus_NoError);
3437 if (!request->u.addrinfo.protocol)
3440 request->u.addrinfo.protocol = (kDNSServiceProtocol_IPv4 | kDNSServiceProtocol_IPv6);
3443 request->u.addrinfo.q4.InterfaceID = request->u.addrinfo.q6.InterfaceID = request->u.addrinfo.interface_id;
3444 request->u.addrinfo.q4.Target = request->u.addrinfo.q6.Target = zeroAddr;
3445 request->u.addrinfo.q4.qname = request->u.addrinfo.q6.qname = d;
3446 request->u.addrinfo.q4.qclass = request->u.addrinfo.q6.qclass = kDNSServiceClass_IN;
3447 request->u.addrinfo.q4.LongLived = request->u.addrinfo.q6.LongLived = (flags & kDNSServiceFlagsLongLivedQuery ) != 0;
3448 request->u.addrinfo.q4.ExpectUnique = request->u.addrinfo.q6.ExpectUnique = mDNSfalse;
3449 request->u.addrinfo.q4.ForceMCast = request->u.addrinfo.q6.ForceMCast = (flags & kDNSServiceFlagsForceMulticast ) != 0;
3450 request->u.addrinfo.q4.ReturnIntermed = request->u.addrinfo.q6.ReturnIntermed = (flags & kDNSServiceFlagsReturnIntermediates) != 0;
3451 request->u.addrinfo.q4.SuppressUnusable = request->u.addrinfo.q6.SuppressUnusable = (flags & kDNSServiceFlagsSuppressUnusable ) != 0;
3452 request->u.addrinfo.q4.TimeoutQuestion = request->u.addrinfo.q6.TimeoutQuestion = (flags & kDNSServiceFlagsTimeout ) != 0;
3453 request->u.addrinfo.q4.WakeOnResolve = request->u.addrinfo.q6.WakeOnResolve = 0;
3454 request->u.addrinfo.q4.qnameOrig = request->u.addrinfo.q6.qnameOrig = mDNSNULL;
3456 if (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv4)
3458 request->u.addrinfo.q4.qtype = kDNSServiceType_A;
3459 request->u.addrinfo.q4.SearchListIndex = 0;
3466 request->u.addrinfo.q4.AppendSearchDomains = 1;
3467 request->u.addrinfo.q4.AppendLocalSearchDomains = 1;
3471 request->u.addrinfo.q4.AppendSearchDomains = 0;
3472 request->u.addrinfo.q4.AppendLocalSearchDomains = 0;
3474 request->u.addrinfo.q4.RetryWithSearchDomains = (ApplySearchDomainsFirst(&request->u.addrinfo.q4) ? 1 : 0);
3475 request->u.addrinfo.q4.QuestionCallback = queryrecord_result_callback;
3476 request->u.addrinfo.q4.QuestionContext = request;
3477 err = mDNS_StartQuery(&mDNSStorage, &request->u.addrinfo.q4);
3481 request->u.addrinfo.q4.QuestionContext = mDNSNULL;
3484 err = SendAdditionalQuery(&request->u.addrinfo.q4, request, err);
3488 if (!err && (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv6))
3490 request->u.addrinfo.q6.qtype = kDNSServiceType_AAAA;
3491 request->u.addrinfo.q6.SearchListIndex = 0;
3494 request->u.addrinfo.q6.AppendSearchDomains = 1;
3495 request->u.addrinfo.q6.AppendLocalSearchDomains = 1;
3499 request->u.addrinfo.q6.AppendSearchDomains = 0;
3500 request->u.addrinfo.q6.AppendLocalSearchDomains = 0;
3502 request->u.addrinfo.q6.RetryWithSearchDomains = (ApplySearchDomainsFirst(&request->u.addrinfo.q6) ? 1 : 0);
3503 request->u.addrinfo.q6.QuestionCallback = queryrecord_result_callback;
3504 request->u.addrinfo.q6.QuestionContext = request;
3505 err = mDNS_StartQuery(&mDNSStorage, &request->u.addrinfo.q6);
3509 request->u.addrinfo.q6.QuestionContext = mDNSNULL;
3510 if (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv4)
3513 mDNS_StopQuery(&mDNSStorage, &request->u.addrinfo.q4);
3514 request->u.addrinfo.q4.QuestionContext = mDNSNULL;
3518 err = SendAdditionalQuery(&request->u.addrinfo.q6, request, err);
3523 request->sd, flags, interfaceIndex, request->u.addrinfo.protocol, d.c);
3525 if (!err) request->terminate = addrinfo_termination_callback;
3533 #pragma mark - Main Request Handler etc.
3559 LogMsg("%3d: ERROR: read data from a completed request", req->sd);
3584 // Largest conceivable single request is a DNSServiceRegisterRecord() or DNSServiceAddRecord()
3853 // There's no return data for a cancel request (DNSServiceRefDeallocate returns no result)
3917 request_state *request = NewRequest();
3918 request->ts = t_morecoming;
3919 request->sd = sd;
3920 request->errsd = sd;
3924 if (getsockopt(sd, 0, LOCAL_PEERCRED, &x, &xucredlen) >= 0 && x.cr_version == XUCRED_VERSION) request->uid = x.cr_uid;
3928 LogOperation("%3d: Adding FD for uid %u", request->sd, request->uid);
3929 udsSupportAddFDToEventLoop(sd, request_callback, request, &request->platform_data);
4423 LogMsgNoIdent("%3d: Orhpan operation %p; parent %p not found in request list", req->sd);
4446 LogMsgNoIdent("%p Address Request Retry %5d Interval %5d", nat,
4574 LogMemCorruption("UDS request list: %p is garbage (%d)", req, req->sd);
4577 LogMemCorruption("UDS request list: req->primary should not point to self %p/%d", req, req->sd);
4580 LogMemCorruption("UDS request list: Subordinate request %p/%d/%p should not have replies (%p)",
4585 LogMemCorruption("UDS request list: req %p primary %p is misaligned (%d)", req, p, req->sd);
4587 LogMemCorruption("UDS request list: req %p primary %p is garbage (%d)", req, p, p->sd);
4731 if (!dnssd_SocketValid(r->sd)) // If this request is finished, unlink it from the list and free the memory
4733 // Since we're already doing a list traversal, we unlink the request directly instead of using AbortUnlinkAndFree()