0

I need android discovery the service in the windows。 I use nsd service in android app which as client. And i note that windows started supporting mDNS/DNS-SD in window 10, so i use the api DnsServiceRegister to register an mDNS server in windows. It seems that android app can discovery the service which is based in windows, but android app can't resolve the service success.

I use wireshar to capture the packets on the LAN port. The android NSD Service always query the Host Address with MDNS packet to the windows, but windows don't response the Host Address Info to android.

Following is my code in the windows,

#include <iostream>
#include <stdio.h>
#include <wtypes.h>
#include <minwinbase.h>
#include <winnt.h>
#include <windns.h>
#include <winerror.h>


VOID WINAPI register_cb(DWORD status, PVOID pQueryContext, PDNS_SERVICE_INSTANCE pInstance)
{
    cout << "register_cb:" << status << endl;
}

int main(void)
{
    IP4_ADDRESS ipv4_address = { 0 };
    ipv4_address = inet_addr("192.168.50.27");

    PDNS_SERVICE_INSTANCE instance = DnsServiceConstructInstance(
        L"windows-mxj._http._tcp.local", L"mxj.local", 
        &ipv4_address, NULL, 90006, 0, 0, 0, NULL, NULL);


    DNS_SERVICE_REGISTER_REQUEST req = {0};
    req.Version = DNS_QUERY_REQUEST_VERSION1;
    req.InterfaceIndex = 0;
    req.pServiceInstance = instance;
    req.pRegisterCompletionCallback = register_cb;
    req.pQueryContext = instance;
    DNS_STATUS regstatus  = DnsServiceRegister(&req, nullptr);
    if (regstatus == DNS_REQUEST_PENDING) {
        std::cout << "register success" << endl;
    } else {
        std::cout <<  register fail,ret:" << regstatus << endl;
        std::cout << "LastErr:" << GetLastError() << endl;
    }
}

I think it may be that there is no Host Address dns record, so i try to add Host Address dns rescord with the api DnsModifyRecordsInSet_A in register_cb, but the api return 9002. It is hard to program in the windows.

// DNS_ERROR_RCODE_SERVER_FAILURE        0x0000232a
//
// MessageId: DNS_ERROR_RCODE_SERVER_FAILURE
//
// MessageText:
//
// DNS server failure.
//
#define DNS_ERROR_RCODE_SERVER_FAILURE   9002L


    recordA.pNext = NULL;
    recordA.pName = instance->pszHostName;
    recordA.wType = DNS_TYPE_A;
    recordA.wDataLength = sizeof(DNS_A_DATA);
    recordA.Flags.S.Section = DnsSectionAddtional;
    recordA.Flags.S.CharSet = DnsCharSetAnsi;
    recordA.dwTtl = 60;
    recordA.Data.A.IpAddress = inet_addr("192.168.50.27");

    DNS_STATUS ret = DnsModifyRecordsInSet_A(&recordA, NULL, DNS_UPDATE_SECURITY_OFF, NULL, NULL, NULL);
    cout << "ModifyRecords :" << ret << "   " << recordA.Data.A.IpAddress << endl;


0 Answers0