Implement function uip_sr_link_snprint

This commit is contained in:
Simon Duquennoy 2018-05-18 05:52:09 -07:00
parent 8b248ceafa
commit bc9934ee5a
2 changed files with 57 additions and 0 deletions

View File

@ -41,6 +41,7 @@
#include "contiki.h"
#include "net/ipv6/uip-sr.h"
#include "net/ipv6/uiplib.h"
#include "net/routing/routing.h"
#include "lib/list.h"
#include "lib/memb.h"
@ -246,4 +247,49 @@ uip_sr_free_all(void)
num_nodes--;
}
}
/*---------------------------------------------------------------------------*/
int
uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link)
{
int index = 0;
uip_ipaddr_t child_ipaddr;
uip_ipaddr_t parent_ipaddr;
NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link);
NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent);
index += uiplib_ipaddr_snprint(buf+index, buflen-index, &child_ipaddr);
if(index >= buflen) {
return index;
}
if(link->parent == NULL) {
index += snprintf(buf+index, buflen-index, " (DODAG root)");
if(index >= buflen) {
return index;
}
} else {
index += snprintf(buf+index, buflen-index, " to ");
if(index >= buflen) {
return index;
}
index += uiplib_ipaddr_snprint(buf+index, buflen-index, &parent_ipaddr);
if(index >= buflen) {
return index;
}
}
if(link->lifetime != UIP_SR_INFINITE_LIFETIME) {
index += snprintf(buf+index, buflen-index,
" (lifetime: %lu seconds)", (unsigned long)link->lifetime);
if(index >= buflen) {
return index;
}
} else {
index += snprintf(buf+index, buflen-index, " (lifetime: infinite)");
if(index >= buflen) {
return index;
}
}
return index;
}
/** @} */

View File

@ -180,6 +180,17 @@ void uip_sr_init(void);
*/
void uip_sr_free_all(void);
/**
* Print a textual description of a source routing link
*
* \param buf The buffer where to write content
* \param buflen The buffer len
* \param link A pointer to the source routing link
* \return Identical to snprintf: number of bytes written excluding ending null
* byte. A value >= buflen if the buffer was too small.
*/
int uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link);
/** @} */
#endif /* UIP_SR_H */