mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #8223 from kb2ma/gcoap/cli_link_local
net/gcoap: Require interface for link local address in shell example
This commit is contained in:
commit
b8eb857ea6
@ -58,7 +58,7 @@ Start the libcoap example server with the command below.
|
||||
|
||||
Enter the query below in the RIOT CLI.
|
||||
|
||||
> coap get fe80::d8b8:65ff:feee:121b 5683 /.well-known/core
|
||||
> coap get fe80::d8b8:65ff:feee:121b%6 5683 /.well-known/core
|
||||
|
||||
CLI output:
|
||||
|
||||
|
@ -144,13 +144,35 @@ static size_t _send(uint8_t *buf, size_t len, char *addr_str, char *port_str)
|
||||
sock_udp_ep_t remote;
|
||||
|
||||
remote.family = AF_INET6;
|
||||
remote.netif = SOCK_ADDR_ANY_NETIF;
|
||||
|
||||
/* parse for interface */
|
||||
int iface = ipv6_addr_split_iface(addr_str);
|
||||
if (iface == -1) {
|
||||
if (gnrc_netif_numof() == 1) {
|
||||
/* assign the single interface found in gnrc_netif_numof() */
|
||||
remote.netif = (uint16_t)gnrc_netif_iter(NULL)->pid;
|
||||
}
|
||||
else {
|
||||
remote.netif = SOCK_ADDR_ANY_NETIF;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (gnrc_netif_get_by_pid(iface) == NULL) {
|
||||
puts("gcoap_cli: interface not valid");
|
||||
return 0;
|
||||
}
|
||||
remote.netif = iface;
|
||||
}
|
||||
|
||||
/* parse destination address */
|
||||
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
|
||||
puts("gcoap_cli: unable to parse destination address");
|
||||
return 0;
|
||||
}
|
||||
if ((remote.netif == SOCK_ADDR_ANY_NETIF) && ipv6_addr_is_link_local(&addr)) {
|
||||
puts("gcoap_cli: must specify interface for link local target");
|
||||
return 0;
|
||||
}
|
||||
memcpy(&remote.addr.ipv6[0], &addr.u8[0], sizeof(addr.u8));
|
||||
|
||||
/* parse port */
|
||||
@ -248,7 +270,7 @@ int gcoap_cli_cmd(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
printf("usage: %s <get|post|put> [-c] <addr> <port> <path> [data]\n",
|
||||
printf("usage: %s <get|post|put> [-c] <addr>[%%iface] <port> <path> [data]\n",
|
||||
argv[0]);
|
||||
printf("Options\n");
|
||||
printf(" -c Send confirmably (defaults to non-confirmable)\n");
|
||||
|
Loading…
Reference in New Issue
Block a user