mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-16 10:03:50 +01:00
net/gcoap: Read interface from CLI in shell example
This commit is contained in:
parent
7745060ad9
commit
a1efa03981
@ -58,7 +58,7 @@ Start the libcoap example server with the command below.
|
|||||||
|
|
||||||
Enter the query below in the RIOT CLI.
|
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:
|
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;
|
sock_udp_ep_t remote;
|
||||||
|
|
||||||
remote.family = AF_INET6;
|
remote.family = AF_INET6;
|
||||||
|
|
||||||
|
/* 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;
|
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 */
|
/* parse destination address */
|
||||||
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
|
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
|
||||||
puts("gcoap_cli: unable to parse destination address");
|
puts("gcoap_cli: unable to parse destination address");
|
||||||
return 0;
|
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));
|
memcpy(&remote.addr.ipv6[0], &addr.u8[0], sizeof(addr.u8));
|
||||||
|
|
||||||
/* parse port */
|
/* parse port */
|
||||||
@ -248,7 +270,7 @@ int gcoap_cli_cmd(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else {
|
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]);
|
argv[0]);
|
||||||
printf("Options\n");
|
printf("Options\n");
|
||||||
printf(" -c Send confirmably (defaults to non-confirmable)\n");
|
printf(" -c Send confirmably (defaults to non-confirmable)\n");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user