@@ -39,14 +39,18 @@ static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX
3939static void send (char * addr_str , char * port_str , char * data , unsigned int num ,
4040 unsigned int delay )
4141{
42- int iface ;
42+ char * iface ;
43+ gnrc_netif_t * netif = NULL ;
4344 uint16_t port ;
4445 ipv6_addr_t addr ;
4546
4647 /* get interface, if available */
4748 iface = ipv6_addr_split_iface (addr_str );
48- if ((iface < 0 ) && (gnrc_netif_numof () == 1 )) {
49- iface = gnrc_netif_iter (NULL )-> pid ;
49+ if ((!iface ) && (gnrc_netif_numof () == 1 )) {
50+ netif = gnrc_netif_iter (NULL );
51+ }
52+ else if (iface ) {
53+ netif = gnrc_netif_get_by_pid (atoi (iface ));
5054 }
5155 /* parse destination address */
5256 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,
8690 return ;
8791 }
8892 /* add netif header, if interface was given */
89- if (iface > 0 ) {
90- gnrc_pktsnip_t * netif = gnrc_netif_hdr_build (NULL , 0 , NULL , 0 );
93+ if (netif ) {
94+ gnrc_pktsnip_t * netif_hdr = gnrc_netif_hdr_build (NULL , 0 , NULL , 0 );
9195
92- ((gnrc_netif_hdr_t * )netif -> data )-> if_pid = ( kernel_pid_t ) iface ;
93- LL_PREPEND (ip , netif );
96+ ((gnrc_netif_hdr_t * )netif_hdr -> data )-> if_pid = netif -> pid ;
97+ LL_PREPEND (ip , netif_hdr );
9498 }
9599 /* send packet */
96100 if (!gnrc_netapi_dispatch_send (GNRC_NETTYPE_UDP , GNRC_NETREG_DEMUX_CTX_ALL , ip )) {
0 commit comments