mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
examples,tests: use gnrc_netif_hdr_set_netif()
This commit is contained in:
parent
3671f69a43
commit
37eb634ff9
@ -39,6 +39,7 @@ static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX
|
||||
static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||
unsigned int delay)
|
||||
{
|
||||
gnrc_netif_t *netif;
|
||||
int iface;
|
||||
uint16_t port;
|
||||
ipv6_addr_t addr;
|
||||
@ -46,7 +47,10 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||
/* get interface, if available */
|
||||
iface = ipv6_addr_split_iface(addr_str);
|
||||
if ((iface < 0) && (gnrc_netif_numof() == 1)) {
|
||||
iface = gnrc_netif_iter(NULL)->pid;
|
||||
netif = gnrc_netif_iter(NULL);
|
||||
}
|
||||
else {
|
||||
netif = gnrc_netif_get_by_pid(iface);
|
||||
}
|
||||
/* parse destination address */
|
||||
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
|
||||
@ -86,11 +90,11 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||
return;
|
||||
}
|
||||
/* add netif header, if interface was given */
|
||||
if (iface > 0) {
|
||||
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
if (netif != NULL) {
|
||||
gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
|
||||
((gnrc_netif_hdr_t *)netif->data)->if_pid = (kernel_pid_t)iface;
|
||||
LL_PREPEND(ip, netif);
|
||||
gnrc_netif_hdr_set_netif(netif_hdr->data, netif);
|
||||
LL_PREPEND(ip, netif_hdr);
|
||||
}
|
||||
/* send packet */
|
||||
if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) {
|
||||
|
@ -38,6 +38,7 @@ static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX
|
||||
static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||
unsigned int delay)
|
||||
{
|
||||
gnrc_netif_t *netif;
|
||||
int iface;
|
||||
uint16_t port;
|
||||
ipv6_addr_t addr;
|
||||
@ -45,7 +46,10 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||
/* get interface, if available */
|
||||
iface = ipv6_addr_split_iface(addr_str);
|
||||
if ((iface < 0) && (gnrc_netif_numof() == 1)) {
|
||||
iface = gnrc_netif_iter(NULL)->pid;
|
||||
netif = gnrc_netif_iter(NULL);
|
||||
}
|
||||
else {
|
||||
netif = gnrc_netif_get_by_pid(iface);
|
||||
}
|
||||
/* parse destination address */
|
||||
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
|
||||
@ -85,11 +89,11 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num,
|
||||
return;
|
||||
}
|
||||
/* add netif header, if interface was given */
|
||||
if (iface > 0) {
|
||||
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
if (netif != NULL) {
|
||||
gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
|
||||
((gnrc_netif_hdr_t *)netif->data)->if_pid = (kernel_pid_t)iface;
|
||||
LL_PREPEND(ip, netif);
|
||||
gnrc_netif_hdr_set_netif(netif_hdr->data, netif);
|
||||
LL_PREPEND(ip, netif_hdr);
|
||||
}
|
||||
/* send packet */
|
||||
if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) {
|
||||
|
@ -131,12 +131,10 @@ static gnrc_pktsnip_t *_build_recvd_pkt(void)
|
||||
{
|
||||
gnrc_pktsnip_t *netif;
|
||||
gnrc_pktsnip_t *pkt;
|
||||
gnrc_netif_hdr_t *netif_hdr;
|
||||
|
||||
netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
assert(netif);
|
||||
netif_hdr = netif->data;
|
||||
netif_hdr->if_pid = _mock_netif->pid;
|
||||
gnrc_netif_hdr_set_netif(netif->data, _mock_netif);
|
||||
pkt = gnrc_pktbuf_add(netif, _l2_payload, sizeof(_l2_payload),
|
||||
GNRC_NETTYPE_IPV6);
|
||||
assert(pkt);
|
||||
|
@ -141,7 +141,7 @@ static void _send_packet(void)
|
||||
|
||||
gnrc_netif_hdr_init(&(netif_hdr.netif_hdr), 8, 8);
|
||||
|
||||
netif_hdr.netif_hdr.if_pid = netif->pid;
|
||||
gnrc_netif_hdr_set_netif(&netif_hdr.netif_hdr, netif);
|
||||
|
||||
uint8_t data1[] = {
|
||||
/* 6LoWPAN Header */
|
||||
|
@ -82,6 +82,7 @@ static void *_eventloop(void *arg)
|
||||
static void send(char *addr_str, char *port_str, char *data_len_str, unsigned int num,
|
||||
unsigned int delay)
|
||||
{
|
||||
gnrc_netif_t *netif;
|
||||
int iface;
|
||||
char *conversion_end;
|
||||
uint16_t port;
|
||||
@ -91,7 +92,10 @@ static void send(char *addr_str, char *port_str, char *data_len_str, unsigned in
|
||||
/* get interface, if available */
|
||||
iface = ipv6_addr_split_iface(addr_str);
|
||||
if ((iface < 0) && (gnrc_netif_numof() == 1)) {
|
||||
iface = gnrc_netif_iter(NULL)->pid;
|
||||
netif = gnrc_netif_iter(NULL);
|
||||
}
|
||||
else {
|
||||
netif = gnrc_netif_get_by_pid(iface);
|
||||
}
|
||||
/* parse destination address */
|
||||
if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
|
||||
@ -135,16 +139,16 @@ static void send(char *addr_str, char *port_str, char *data_len_str, unsigned in
|
||||
return;
|
||||
}
|
||||
/* add netif header, if interface was given */
|
||||
if (iface > 0) {
|
||||
gnrc_pktsnip_t *netif = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
if (netif != NULL) {
|
||||
gnrc_pktsnip_t *netif_hdr = gnrc_netif_hdr_build(NULL, 0, NULL, 0);
|
||||
|
||||
if(netif == NULL) {
|
||||
puts("Error: unable to allocate NETIF header");
|
||||
gnrc_pktbuf_release(ip);
|
||||
return;
|
||||
}
|
||||
((gnrc_netif_hdr_t *)netif->data)->if_pid = (kernel_pid_t)iface;
|
||||
LL_PREPEND(ip, netif);
|
||||
gnrc_netif_hdr_set_netif(netif_hdr->data, netif);
|
||||
LL_PREPEND(ip, netif_hdr);
|
||||
}
|
||||
/* send packet */
|
||||
if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) {
|
||||
|
Loading…
Reference in New Issue
Block a user