You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Tim Hardisty <ti...@gmail.com> on 2024/10/08 19:56:00 UTC

NuttX "gadget": resolve its host name via CDC/NCM connection

Not a NuttX question, as such, more a basic embedded device networking question. But you’re all so helpful, and it’s NuttX things I need to do this :-)

I have just tried the recently added CDC/NCM USB networking and it works very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not tried MAC yet) get an IP address and immediately I can exchange data (well…ping between them). And I have set a hostname for my NuttX “gadget” and uname reports it properly.

My intention is to implement a simple web server on the device so as to be able to plug in to it via usb, go to a browser, and go to “http://gadget” rather than “http://10.0.0.10” (for example).

This is DNS…but my embedded networking knowledge is limited and I am not sure what NuttX tools/daemons/examples/whatever I need to use for this? 

I don’t think a hosts file on the gadget is right, as the PC can’t use that to match hostname to IP (and editing a hosts file on the PC is not an option in this case). So probably the gadget needs to also be a DNS server? But I can’t find much information on how to use the NuttX implementation of this.

Have I got that right or am I missing something?

Happy to repay “information that leads to a successful prosecution” ;-) by adding to the NuttX “How To” documentation if appropriate

Thanks,

TimJTi.

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by Tim Hardisty <ti...@gmail.com>.
Yes - my initial research suggests mDNS and Bonjour/Avahi are essentially- if not actually - the same. I’m sure there’s some code out there, hopefully good enough - and lacking license restrictions - so if I get it working I’ll submit a PR.

I have my “gadget” acting as DHCP and web servers now, and can plug USB into Linux or Windows and get “no messing about by the user” browsing but only by IP address at the moment.

Playing around with USB MSD as a parallel activity and, as per usual, it plays with Linux out of the NuttX box but not Windows. Sigh.

> On 9 Oct 2024, at 18:49, Nathan Hartman <ha...@gmail.com> wrote:
> 
> Isn't there Bonjour/Avahi that can make something like this work on a
> local network, at least when accessed from a computer that supports
> Bonjour/Avahi? I think this is how printers are automatically
> discovered on a network.
> 
> On Wed, Oct 9, 2024 at 9:02 AM Tim Hardisty <ti...@gmail.com> wrote:
>> 
>> Yes - I think mDNS might be a good way so I am looking at this. If I get
>> it working can work on a PR to add such a thing as a NETUTIL and/or
>> example :-)
>> 
>> “http://gadget.local <http://gadget.local/>" is fine and (probably) correct anyway.
>> 
>> On 09/10/2024 07:34, David Alessio wrote:
>>>> On Oct 8, 2024, at 12:56 PM, Tim Hardisty<ti...@gmail.com> wrote:
>>>> 
>>>> Not a NuttX question, as such, more a basic embedded device networking question. But you’re all so helpful, and it’s NuttX things I need to do this :-)
>>>> 
>>>> I have just tried the recently added CDC/NCM USB networking and it works very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not tried MAC yet) get an IP address and immediately I can exchange data (well…ping between them). And I have set a hostname for my NuttX “gadget” and uname reports it properly.
>>>> 
>>>> My intention is to implement a simple web server on the device so as to be able to plug in to it via usb, go to a browser, and go to “http://gadget” rather than “http://10.0.0.10” (for example).
>>>> 
>>>> This is DNS…but my embedded networking knowledge is limited and I am not sure what NuttX tools/daemons/examples/whatever I need to use for this?
>>>> 
>>>> I don’t think a hosts file on the gadget is right, as the PC can’t use that to match hostname to IP (and editing a hosts file on the PC is not an option in this case). So probably the gadget needs to also be a DNS server? But I can’t find much information on how to use the NuttX implementation of this.
>>>> 
>>>> Have I got that right or am I missing something?
>>>> 
>>>> Happy to repay “information that leads to a successful prosecution” ;-) by adding to the NuttX “How To” documentation if appropriate
>>>> 
>>>> Thanks,
>>>> 
>>>> TimJTi.
>>> The first thought that comes to my mind is to run an mDNS responder on the NuttX side.  Its hostname will need to be “gadget”.  You may need to settle for “http://gadget.local <http://gadget.local/>"


Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by Nathan Hartman <ha...@gmail.com>.
Isn't there Bonjour/Avahi that can make something like this work on a
local network, at least when accessed from a computer that supports
Bonjour/Avahi? I think this is how printers are automatically
discovered on a network.

On Wed, Oct 9, 2024 at 9:02 AM Tim Hardisty <ti...@gmail.com> wrote:
>
> Yes - I think mDNS might be a good way so I am looking at this. If I get
> it working can work on a PR to add such a thing as a NETUTIL and/or
> example :-)
>
> “http://gadget.local <http://gadget.local/>" is fine and (probably) correct anyway.
>
> On 09/10/2024 07:34, David Alessio wrote:
> >> On Oct 8, 2024, at 12:56 PM, Tim Hardisty<ti...@gmail.com> wrote:
> >>
> >> Not a NuttX question, as such, more a basic embedded device networking question. But you’re all so helpful, and it’s NuttX things I need to do this :-)
> >>
> >> I have just tried the recently added CDC/NCM USB networking and it works very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not tried MAC yet) get an IP address and immediately I can exchange data (well…ping between them). And I have set a hostname for my NuttX “gadget” and uname reports it properly.
> >>
> >> My intention is to implement a simple web server on the device so as to be able to plug in to it via usb, go to a browser, and go to “http://gadget” rather than “http://10.0.0.10” (for example).
> >>
> >> This is DNS…but my embedded networking knowledge is limited and I am not sure what NuttX tools/daemons/examples/whatever I need to use for this?
> >>
> >> I don’t think a hosts file on the gadget is right, as the PC can’t use that to match hostname to IP (and editing a hosts file on the PC is not an option in this case). So probably the gadget needs to also be a DNS server? But I can’t find much information on how to use the NuttX implementation of this.
> >>
> >> Have I got that right or am I missing something?
> >>
> >> Happy to repay “information that leads to a successful prosecution” ;-) by adding to the NuttX “How To” documentation if appropriate
> >>
> >> Thanks,
> >>
> >> TimJTi.
> > The first thought that comes to my mind is to run an mDNS responder on the NuttX side.  Its hostname will need to be “gadget”.  You may need to settle for “http://gadget.local <http://gadget.local/>"

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by Tim Hardisty <ti...@gmail.com>.
Yes - I think mDNS might be a good way so I am looking at this. If I get 
it working can work on a PR to add such a thing as a NETUTIL and/or 
example :-)

“http://gadget.local <http://gadget.local/>" is fine and (probably) correct anyway.

On 09/10/2024 07:34, David Alessio wrote:
>> On Oct 8, 2024, at 12:56 PM, Tim Hardisty<ti...@gmail.com> wrote:
>>
>> Not a NuttX question, as such, more a basic embedded device networking question. But you’re all so helpful, and it’s NuttX things I need to do this :-)
>>
>> I have just tried the recently added CDC/NCM USB networking and it works very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not tried MAC yet) get an IP address and immediately I can exchange data (well…ping between them). And I have set a hostname for my NuttX “gadget” and uname reports it properly.
>>
>> My intention is to implement a simple web server on the device so as to be able to plug in to it via usb, go to a browser, and go to “http://gadget” rather than “http://10.0.0.10” (for example).
>>
>> This is DNS…but my embedded networking knowledge is limited and I am not sure what NuttX tools/daemons/examples/whatever I need to use for this?
>>
>> I don’t think a hosts file on the gadget is right, as the PC can’t use that to match hostname to IP (and editing a hosts file on the PC is not an option in this case). So probably the gadget needs to also be a DNS server? But I can’t find much information on how to use the NuttX implementation of this.
>>
>> Have I got that right or am I missing something?
>>
>> Happy to repay “information that leads to a successful prosecution” ;-) by adding to the NuttX “How To” documentation if appropriate
>>
>> Thanks,
>>
>> TimJTi.
> The first thought that comes to my mind is to run an mDNS responder on the NuttX side.  Its hostname will need to be “gadget”.  You may need to settle for “http://gadget.local <http://gadget.local/>"

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by David Alessio <da...@gmail.com>.
> On Oct 8, 2024, at 12:56 PM, Tim Hardisty <ti...@gmail.com> wrote:
> 
> Not a NuttX question, as such, more a basic embedded device networking question. But you’re all so helpful, and it’s NuttX things I need to do this :-)
> 
> I have just tried the recently added CDC/NCM USB networking and it works very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not tried MAC yet) get an IP address and immediately I can exchange data (well…ping between them). And I have set a hostname for my NuttX “gadget” and uname reports it properly.
> 
> My intention is to implement a simple web server on the device so as to be able to plug in to it via usb, go to a browser, and go to “http://gadget” rather than “http://10.0.0.10” (for example).
> 
> This is DNS…but my embedded networking knowledge is limited and I am not sure what NuttX tools/daemons/examples/whatever I need to use for this? 
> 
> I don’t think a hosts file on the gadget is right, as the PC can’t use that to match hostname to IP (and editing a hosts file on the PC is not an option in this case). So probably the gadget needs to also be a DNS server? But I can’t find much information on how to use the NuttX implementation of this.
> 
> Have I got that right or am I missing something?
> 
> Happy to repay “information that leads to a successful prosecution” ;-) by adding to the NuttX “How To” documentation if appropriate
> 
> Thanks,
> 
> TimJTi.

The first thought that comes to my mind is to run an mDNS responder on the NuttX side.  Its hostname will need to be “gadget”.  You may need to settle for “http://gadget.local <http://gadget.local/>"

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by Tim Hardisty <ti...@gmail.com>.
I am already using dhcpd and it successfully allocates an IP address to 
the Host PC connected over CDC/NCM - I can ping in both directions 
successfully. I should therefore be able to use (something like) the 
webserver example and server pages by using a URL such as 
http://10.0.0.2 - I am trying this out now.

Being able to browse to "http://gadget" or "http://gadget.local" would 
be nicer so I am looking an mDNS etc.

On 09/10/2024 12:58, spudaneco wrote:
> There is this that I wrotw many years ago:https://github.com/apache/nuttx-apps/tree/master/netutils/dhcpd

> Sent from my Galaxy
> -------- Original message --------From:michal.lyszczek@bofc.pl Date: 10/8/24  11:01 PM  (GMT-06:00) To:dev@nuttx.apache.org Subject: Re: NuttX "gadget": resolve its host name via CDC/NCM connection On 2024-10-08 20:56:00, Tim Hardisty wrote:> My intention is to implement a simple web server on the device so as to be> able to plug in to it via usb, go to a browser, and go to “http://gadget”> rather than “http://10.0.0.10” (for example).> > This is DNS…but my embedded networking knowledge is limited and I am not> sure what NuttX tools/daemons/examples/whatever I need to use for this? > > I don’t think a hosts file on the gadget is right, as the PC can’t use> that to match hostname to IP (and editing a hosts file on the PC is not an> option in this case). So probably the gadget needs to also be a DNS> server? But I can’t find much information on how to use the NuttX> implementation of this.> > Have I got that right or am I missing something?The thing you want to do, while possible is not really feasable. Yes, youmust host DNS server on nuttx. I don't think there is anything ready to go,embedded devices usually do not act as a DNS. Then you would have to pushDNS server to the host via DHCP. Problem is, that now you will overwrite DNSaddress on your host pc and you won't be able to resolve anything else otherthan what your nuttx 'gadget' device can. You could forward requests toexternal DNS, but that again requires nuttx to have internet. So DHCP/DNS onnuttx is not really good option.Having it reversed (DHCP/DNS on host pc) could probably solve the problem withsome upnp magic. But that will require user to have upnp or some kind ofzeroconf enabled on host pc as well.To my knowledge it's not possible to do what you want in portable manner.You can try some hacks, but the will not work for anyone - hence I would notrecommend them.I have never ever met a embedded device that would do what you describe.It's always via IP address. So do what others do, and allow access viaIP address only. That's the only portable way that I know of.-- .-----------------.-------------------.----------------------.-----------------.| Michal Lyszczek | Embedded C, Linux |   Company Address    |  .-. opensource || +48 727 564 419 | Software Engineer | Akacjowa 10a; 55-330 |  oo|  supporter ||https://bofc.pl `----.--------------: Brzezinka Sredzka PL | /`'\      &     || GPG FF1EBFE7E3A974B1 | Bits of Code | NIP:   813 349 58 78 |(\_;/) programer |`----------------------^--------------^----------------------^-----------------'

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by spudaneco <sp...@gmail.com>.
There is this that I wrotw many years ago: https://github.com/apache/nuttx-apps/tree/master/netutils/dhcpdSent from my Galaxy
-------- Original message --------From: michal.lyszczek@bofc.pl Date: 10/8/24  11:01 PM  (GMT-06:00) To: dev@nuttx.apache.org Subject: Re: NuttX "gadget": resolve its host name via CDC/NCM connection On 2024-10-08 20:56:00, Tim Hardisty wrote:> My intention is to implement a simple web server on the device so as to be> able to plug in to it via usb, go to a browser, and go to “http://gadget”> rather than “http://10.0.0.10” (for example).> > This is DNS…but my embedded networking knowledge is limited and I am not> sure what NuttX tools/daemons/examples/whatever I need to use for this? > > I don’t think a hosts file on the gadget is right, as the PC can’t use> that to match hostname to IP (and editing a hosts file on the PC is not an> option in this case). So probably the gadget needs to also be a DNS> server? But I can’t find much information on how to use the NuttX> implementation of this.> > Have I got that right or am I missing something?The thing you want to do, while possible is not really feasable. Yes, youmust host DNS server on nuttx. I don't think there is anything ready to go,embedded devices usually do not act as a DNS. Then you would have to pushDNS server to the host via DHCP. Problem is, that now you will overwrite DNSaddress on your host pc and you won't be able to resolve anything else otherthan what your nuttx 'gadget' device can. You could forward requests toexternal DNS, but that again requires nuttx to have internet. So DHCP/DNS onnuttx is not really good option.Having it reversed (DHCP/DNS on host pc) could probably solve the problem withsome upnp magic. But that will require user to have upnp or some kind ofzeroconf enabled on host pc as well.To my knowledge it's not possible to do what you want in portable manner.You can try some hacks, but the will not work for anyone - hence I would notrecommend them.I have never ever met a embedded device that would do what you describe.It's always via IP address. So do what others do, and allow access viaIP address only. That's the only portable way that I know of.-- .-----------------.-------------------.----------------------.-----------------.| Michal Lyszczek | Embedded C, Linux |   Company Address    |  .-. opensource || +48 727 564 419 | Software Engineer | Akacjowa 10a; 55-330 |  oo|  supporter || https://bofc.pl `----.--------------: Brzezinka Sredzka PL | /`'\      &     || GPG FF1EBFE7E3A974B1 | Bits of Code | NIP:   813 349 58 78 |(\_;/) programer |`----------------------^--------------^----------------------^-----------------'

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by mi...@bofc.pl.
On 2024-10-08 20:56:00, Tim Hardisty wrote:
> My intention is to implement a simple web server on the device so as to be
> able to plug in to it via usb, go to a browser, and go to “http://gadget”
> rather than “http://10.0.0.10” (for example).
> 
> This is DNS…but my embedded networking knowledge is limited and I am not
> sure what NuttX tools/daemons/examples/whatever I need to use for this? 
> 
> I don’t think a hosts file on the gadget is right, as the PC can’t use
> that to match hostname to IP (and editing a hosts file on the PC is not an
> option in this case). So probably the gadget needs to also be a DNS
> server? But I can’t find much information on how to use the NuttX
> implementation of this.
> 
> Have I got that right or am I missing something?

The thing you want to do, while possible is not really feasable. Yes, you
must host DNS server on nuttx. I don't think there is anything ready to go,
embedded devices usually do not act as a DNS. Then you would have to push
DNS server to the host via DHCP. Problem is, that now you will overwrite DNS
address on your host pc and you won't be able to resolve anything else other
than what your nuttx 'gadget' device can. You could forward requests to
external DNS, but that again requires nuttx to have internet. So DHCP/DNS on
nuttx is not really good option.

Having it reversed (DHCP/DNS on host pc) could probably solve the problem with
some upnp magic. But that will require user to have upnp or some kind of
zeroconf enabled on host pc as well.

To my knowledge it's not possible to do what you want in portable manner.
You can try some hacks, but the will not work for anyone - hence I would not
recommend them.

I have never ever met a embedded device that would do what you describe.
It's always via IP address. So do what others do, and allow access via
IP address only. That's the only portable way that I know of.

-- 
.-----------------.-------------------.----------------------.-----------------.
| Michal Lyszczek | Embedded C, Linux |   Company Address    |  .-. opensource |
| +48 727 564 419 | Software Engineer | Akacjowa 10a; 55-330 |  oo|  supporter |
| https://bofc.pl `----.--------------: Brzezinka Sredzka PL | /`'\      &     |
| GPG FF1EBFE7E3A974B1 | Bits of Code | NIP:   813 349 58 78 |(\_;/) programer |
`----------------------^--------------^----------------------^-----------------'

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by Tim Hardisty <ti...@gmail.com>.
Thanks for the suggestion - every day's a learning day so more bedtime 
reading :-)

On 09/10/2024 13:39, Marco Casaroli wrote:
> Why not just write a DNS-SD daemon that will send some URP packets and then
> the peers can resolve the hostname?
>
> http://www.dns-sd.org
>
>
> On Wed, 9 Oct 2024 at 02:04, Tim Hardisty<ti...@gmail.com> wrote:
>
>> Not a NuttX question, as such, more a basic embedded device networking
>> question. But you’re all so helpful, and it’s NuttX things I need to do
>> this :-)
>>
>> I have just tried the recently added CDC/NCM USB networking and it works
>> very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not
>> tried MAC yet) get an IP address and immediately I can exchange data
>> (well…ping between them). And I have set a hostname for my NuttX “gadget”
>> and uname reports it properly.
>>
>> My intention is to implement a simple web server on the device so as to be
>> able to plug in to it via usb, go to a browser, and go to “http://gadget”
>> rather than “http://10.0.0.10” (for example).
>>
>> This is DNS…but my embedded networking knowledge is limited and I am not
>> sure what NuttX tools/daemons/examples/whatever I need to use for this?
>>
>> I don’t think a hosts file on the gadget is right, as the PC can’t use
>> that to match hostname to IP (and editing a hosts file on the PC is not an
>> option in this case). So probably the gadget needs to also be a DNS server?
>> But I can’t find much information on how to use the NuttX implementation of
>> this.
>>
>> Have I got that right or am I missing something?
>>
>> Happy to repay “information that leads to a successful prosecution” ;-) by
>> adding to the NuttX “How To” documentation if appropriate
>>
>> Thanks,
>>
>> TimJTi.

Re: NuttX "gadget": resolve its host name via CDC/NCM connection

Posted by Marco Casaroli <ma...@midokura.com.INVALID>.
Why not just write a DNS-SD daemon that will send some URP packets and then
the peers can resolve the hostname?

http://www.dns-sd.org


On Wed, 9 Oct 2024 at 02:04, Tim Hardisty <ti...@gmail.com> wrote:

> Not a NuttX question, as such, more a basic embedded device networking
> question. But you’re all so helpful, and it’s NuttX things I need to do
> this :-)
>
> I have just tried the recently added CDC/NCM USB networking and it works
> very nicely. Coupled with DHCPD, I can have a PC (Windows or Linux; not
> tried MAC yet) get an IP address and immediately I can exchange data
> (well…ping between them). And I have set a hostname for my NuttX “gadget”
> and uname reports it properly.
>
> My intention is to implement a simple web server on the device so as to be
> able to plug in to it via usb, go to a browser, and go to “http://gadget”
> rather than “http://10.0.0.10” (for example).
>
> This is DNS…but my embedded networking knowledge is limited and I am not
> sure what NuttX tools/daemons/examples/whatever I need to use for this?
>
> I don’t think a hosts file on the gadget is right, as the PC can’t use
> that to match hostname to IP (and editing a hosts file on the PC is not an
> option in this case). So probably the gadget needs to also be a DNS server?
> But I can’t find much information on how to use the NuttX implementation of
> this.
>
> Have I got that right or am I missing something?
>
> Happy to repay “information that leads to a successful prosecution” ;-) by
> adding to the NuttX “How To” documentation if appropriate
>
> Thanks,
>
> TimJTi.