49#include "net/ipv6/ip64-addr.h"
55#define LOG_MODULE "uiplib"
56#define LOG_LEVEL LOG_LEVEL_NONE
60uiplib_ip6addrconv(
const char *addrstr, uip_ip6addr_t *
ipaddr)
69 if(*addrstr ==
'[') addrstr++;
71 for(len = 0; len <
sizeof(uip_ip6addr_t) - 1; addrstr++) {
73 if(c ==
':' || c ==
'\0' || c ==
']' || c ==
'/') {
74 ipaddr->u8[len] = (value >> 8) & 0xff;
75 ipaddr->u8[len + 1] = value & 0xff;
79 if(c ==
'\0' || c ==
']' || c ==
'/') {
83 if(*(addrstr + 1) ==
':') {
91 if(c >=
'0' && c <=
'9') {
93 }
else if(c >=
'a' && c <=
'f') {
95 }
else if(c >=
'A' && c <=
'F') {
98 LOG_ERR(
"illegal char: '%c'\n", c);
101 value = (value << 4) + (tmp & 0xf);
104 if(c !=
'\0' && c !=
']' && c !=
'/') {
105 LOG_ERR(
"too large address\n");
108 if(len <
sizeof(uip_ip6addr_t)) {
110 LOG_ERR(
"too short address\n");
113 memmove(&
ipaddr->u8[zero +
sizeof(uip_ip6addr_t) - len],
114 &
ipaddr->u8[zero], len - zero);
115 memset(&
ipaddr->u8[zero], 0,
sizeof(uip_ip6addr_t) - len);
129 uint8_t charsread = 0;
133 for(i = 0; i < 4; ++i) {
141 if(c ==
'.' || c == 0 || c ==
' ') {
144 }
else if(c >=
'0' && c <=
'9') {
145 tmp = (tmp * 10) + (c -
'0');
151 }
while(c !=
'.' && c != 0 && c !=
' ');
154 return charsread - 1;
160 char buf[UIPLIB_IPV6_MAX_STR_LEN];
175 return snprintf(buf, size,
"(NULL IP addr)");
176 }
else if(ip64_addr_is_ipv4_mapped_addr(
addr)) {
191 return snprintf(buf, size,
"::FFFF:%u.%u.%u.%u",
addr->u8[12],
195 for(
size_t i = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
196 uint16_t a = (
addr->u8[i] << 8) +
addr->u8[i + 1];
197 if(a == 0 && f >= 0) {
199 n += snprintf(buf+n, size-n,
"::");
208 n += snprintf(buf+n, size-n,
":");
213 n += snprintf(buf+n, size-n,
"%x", a);
void uiplib_ipaddr_print(const uip_ipaddr_t *addr)
Print an IP address using printf().
int uiplib_ipaddr_snprint(char *buf, size_t size, const uip_ipaddr_t *addr)
Write at most size - 1 characters of the IP address to the output string.
Header file for the logging system.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Header file for the uIP TCP/IP stack.
Header file for the IP address manipulation library.
Representation of an IP address.