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)
65 const char *group_start;
70 if(*addrstr ==
'[') addrstr++;
72 group_start = addrstr;
73 for(len = 0; len <
sizeof(uip_ip6addr_t) - 1; addrstr++) {
75 if(c ==
':' || c ==
'\0' || c ==
']' || c ==
'/') {
76 ipaddr->u8[len] = (value >> 8) & 0xff;
77 ipaddr->u8[len + 1] = value & 0xff;
81 if(c ==
'\0' || c ==
']' || c ==
'/') {
85 if(*(addrstr + 1) ==
':') {
92 group_start = addrstr + 1;
96 if(uiplib_ip4addrconv(group_start, &v4) == 0) {
99 ipaddr->u8[len] = v4.u8[0];
100 ipaddr->u8[len + 1] = v4.u8[1];
101 ipaddr->u8[len + 2] = v4.u8[2];
102 ipaddr->u8[len + 3] = v4.u8[3];
107 if(c >=
'0' && c <=
'9') {
109 }
else if(c >=
'a' && c <=
'f') {
111 }
else if(c >=
'A' && c <=
'F') {
114 LOG_ERR(
"illegal char: '%c'\n", c);
117 value = (value << 4) + (tmp & 0xf);
120 if(c !=
'\0' && c !=
']' && c !=
'/') {
121 LOG_ERR(
"too large address\n");
124 if(len <
sizeof(uip_ip6addr_t)) {
126 LOG_ERR(
"too short address\n");
129 memmove(&
ipaddr->u8[zero +
sizeof(uip_ip6addr_t) - len],
130 &
ipaddr->u8[zero], len - zero);
131 memset(&
ipaddr->u8[zero], 0,
sizeof(uip_ip6addr_t) - len);
145 uint8_t charsread = 0;
149 for(i = 0; i < 4; ++i) {
157 if(c ==
'.' || c == 0 || c ==
' ') {
160 }
else if(c >=
'0' && c <=
'9') {
161 tmp = (tmp * 10) + (c -
'0');
167 }
while(c !=
'.' && c != 0 && c !=
' ');
170 return charsread - 1;
176 char buf[UIPLIB_IPV6_MAX_STR_LEN];
191 return snprintf(buf, size,
"(NULL IP addr)");
192 }
else if(ip64_addr_is_ipv4_mapped_addr(
addr)) {
207 return snprintf(buf, size,
"::FFFF:%u.%u.%u.%u",
addr->u8[12],
209 }
else if(ip64_addr_is_ip64(
addr)) {
216 return snprintf(buf, size,
"64:ff9b::%u.%u.%u.%u",
addr->u8[12],
220 for(
size_t i = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
221 uint16_t a = (
addr->u8[i] << 8) +
addr->u8[i + 1];
222 if(a == 0 && f >= 0) {
224 n += snprintf(buf+n, size-n,
"::");
233 n += snprintf(buf+n, size-n,
":");
238 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.