[riot-users] Problem with udp sock api

Robin robin at chilio.net
Thu Jul 18 15:48:15 CEST 2019


On 18.07.19 15:25, oliver wrote:
> Hello together,
> I'm trying to understand, how the UDP sock API [1] works, but the
> documentation /example are very bad / useless.
That's a little bit harsh when you consider that there is a full working 
example in the link you provided. But feel free to send improvements and 
actual criticism i guess.
> 1:
> How can I create an UDP server which listen on a specific port and has
> an unique IPv6 addr ?? The example [1] isn't very helpful. I don't
> understand why some variables like "local" [2] are defined. The
> documentation does not help. The documentation says "Common IP-based
> transport layer end point." for the struct sock_udp_ep_t. But why do I
> need this?? I want to receive and send udp packages to other boards. Why
> is this so difficult to implement ??

To send to and receive from a socket you need an endpoint. That's how 
sockets works. In POSIX your endpoint is just a file descriptor.

You can use the POSIX socket wrapper if you like but if you click on 
SOCK_ADDR_ANY_NETIF it shows exactly what it means.

"Special netif ID for "any interface"."

So this endpoint just listen on any interface your board provides. you 
can also listen on a specific address/interface if you want. (See below)


This is your UDP port.

> 2:
> How can I send an udp package with the following parameters given:
> - message
> - portnumber
> - dst ipv6 addr
> The documentation / example does not help here either.
There is a UDP Client in the documentation which works perfectly for me. 
To be fair this example uses multicast addresses but you can exchange 
"ipv6_addr_set_all_nodes_multicast" with "ipv6_addr_from_str" to set 
for unicast. (Also checkout [1])

Further, you can have a look into the "gnrc_networking" example in the 
official sources. IIRC it does exactly what you want.

> 3:
> How can I get the unique Ipv6 addr from my device (samr21-xpro). I want
> to call "getIPv6()" and want the Ipv6 addr which this device has.

That's not how networking with IPv6 works. You got one or more 
interfaces available to your OS. Every interface can have a number of 
IPv6 addresses with different scopes.

Normally every interface should have a link local scope address. You can 
have a look in the ifconfig shell command if you want a code example. 
Also there is a documentation under [2]. You can use the 
"gnrc_netif_iter" function to iterate over all network interfaces and 
have a look into the ipv6 member of the returned structs to get the 
actual addresses.


[1] https://doc.riot-os.org/group__net__ipv6__addr.html

[2] https://doc.riot-os.org/group__net__gnrc__netif.html

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/users/attachments/20190718/417d3300/attachment-0001.htm>

More information about the users mailing list