[riot-users] Problem with udp sock api
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  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.
> How can I create an UDP server which listen on a specific port and has
> an unique IPv6 addr ?? The example  isn't very helpful. I don't
> understand why some variables like "local"  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.
> 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 )
Further, you can have a look into the "gnrc_networking" example in the
official sources. IIRC it does exactly what you want.
> 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 . 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the users