Elegant way to get IP address within gcoap

I need to get the IP address within gcoap. If available global, if not ULA, if not ULA then link-local.

best regards Philipp

In all generality, the address may depend upon which interface you are connected to, and what the address of your correspondant is. Particularly the Link-Local. While many devices have only one interface, this is not universally true. It may be better to have an API that takes this into account.

True that. I don't mind getting multiple addresses. I also thought about getting the destination address of the incoming packet or something like this. When I think about it, it probably is even better to get all addresses. Thanks for the input. Yes, an API for this would be very good. Do you know in what modules/files I have to look into it, to get a better understanding where to get this information from?

Hi Philipp,

am I assuming correctly that you want to know on which IP address you received an incoming request?

An API extension for the underlying UDP SOCK API is about to get merged [1], that would allow just this. Still missing are implementations of that API (but the pull requests for those are open and likely much less controversial than an API extension) and an extension to gcoap to forward this info.

I assume this is something that will land sooner or later in RIOT, as the ability to do virtual hosting based on IP address has some interesting use cases (e.g. to provide some resources only on the link-local IPv6 address, while other resources can also be provided to a wider audience).

Kind regards, Marian

[1]: https://github.com/RIOT-OS/RIOT/pull/14703

Hi Philipp,

am I assuming correctly that you want to know on which IP address you received an incoming request?

An API extension for the underlying UDP SOCK API is about to get merged [1], that would allow just this. Still missing are implementations of that API (but the pull requests for those are open and likely much less controversial than an API extension) and an extension to gcoap to forward this info.

I assume this is something that will land sooner or later in RIOT, as the ability to do virtual hosting based on IP address has some interesting use cases (e.g. to provide some resources only on the link-local IPv6 address, while other resources can also be provided to a wider audience).

Kind regards, Marian

Can you send me the PR for gcoap once it is there? I would like to watch it. I need this for the Web of Things implementation. I have to provide the IP address in the current version of the specification. (https://github.com/w3c/wot-thing-description/issues/977#issuecomment-733824110)