NBNS example request

jeronimo479 wrote on Tuesday, June 19, 2018:

I want 8 nodes on my private network to be able to call each other by name, yet I don’t want any of them to have to be the DNS. LMNR uses TCP mulitcast and NBNS uses UDP broadcast, so I think I want NBNS.

Can anyone provide an example implementation including the required call-back.

thanks,
Wayne

heinbali01 wrote on Tuesday, June 19, 2018:

Hi Wayne,

I want 8 nodes on my private network to be able to call each other by name, yet I don’t want
any of them to have to be the DNS. LMNR uses TCP mulitcast and NBNS uses UDP broadcast,
so I think I want NBNS.

Correction: LLMNR has no direct relation with TCP, and indeed it does use multicasting. When you use a local name in a browser, it is most likely to start a look-up with LLMNR first. Only after a time-out, it will try the same look-up using NBNS. For this reason I would prefer to use LLMNR.
A second advantage of LLMNR is multi-casting. You can selectively enable multi-cast addresses, so that you only receive the type of messages that you are interested in.
Broadcasting is not specific: either you enable all broadcasting ( and get disturbed very often ), or you disable it.

Can anyone provide an example implementation including the required call-back.

Just enable the proper define(s):

    #define ipconfigUSE_LLMNR             ( 1 )
    #define ipconfigUSE_NBNS              ( 1 )

and define the application call-back, returning pdPASS if a match is found:

BaseType_t xApplicationDNSQueryHook( const char *pcName )
{
BaseType_t xReturn;

    /* Determine if a name lookup is for this node.  Two names are given
    to this node: that returned by pcApplicationHostnameHook() and that set
    by mainDEVICE_NICK_NAME. */
    if( strcasecmp( pcName, "speaker_01_r" ) == 0 )
    {
        xReturn = pdPASS;
    }
    else if( strcasecmp( pcName, "audio-output" ) == 0 )
    {
        xReturn = pdPASS;
    }
    else
    {
        xReturn = pdFAIL;
    }

    return xReturn;
}
/*-----------------------------------------------------------*/

In this example, the device can be found as follows:

    ping speaker_01_r

Or as a URL:

    http://speaker_01_r/index.html

Note that local names may not contain a dot. Addresses with a dot will be looked up with DNS.

The following +TCP look-up function is aware of this:

    uint32_t FreeRTOS_gethostbyname( const char *pcHostName );

It will either use DNS or LLMNR to find a node.

jeronimo479 wrote on Tuesday, July 17, 2018:

Thanks for all the help. While I was looking into LLMNR, I saw that the implementation always sent it’s query to a specific MAC address, and that’s why I thought there had to be a central server, which is what I wanted to avoid.