Search code examples
contikiiot

How to access the IP address list in contiki?


I have a UDP server and client connection. The stack is 802.15.4, TSCH, 6lowpan, IPv6. I believe there is a function in contiki that lists the IP addresses of clients when it is associated to server. I would like to know which function I can use to access this list, save to this list and get stored IP's from this list.


Solution

  • Whether or not you're using RPL, in a contiki server (device receiving DIO messages in case of RPL and RS message in case of NDP) you can access the list of clients by looking in the Neighbor Cache. This cache is located in the ds6_neighbors table.

    I'd try something like that:

    #include "uip-ds6-nbr.h"
    #include "nbr-table.h"
    
    uip_ds6_nbr_t *nbr = nbr_table_head(ds6_neighbors);
    while(nbr != NULL) {
        // do something with the neighbor here
        // its IP address is nbr->ipaddr
        // ...
        nbr = nbr_table_next(ds6_neighbors, nbr);
    }