49 #include "net/ipv6/ip64-addr.h" 55 #define LOG_MODULE "uiplib" 56 #define LOG_LEVEL LOG_LEVEL_NONE 59 #if NETSTACK_CONF_WITH_IPV6 61 uiplib_ip6addrconv(
const char *addrstr, uip_ip6addr_t *
ipaddr)
70 if(*addrstr ==
'[') addrstr++;
72 for(len = 0; len <
sizeof(uip_ip6addr_t) - 1; addrstr++) {
74 if(c ==
':' || c ==
'\0' || c ==
']' || c ==
'/') {
75 ipaddr->u8[len] = (value >> 8) & 0xff;
76 ipaddr->u8[len + 1] = value & 0xff;
80 if(c ==
'\0' || c ==
']' || c ==
'/') {
84 if(*(addrstr + 1) ==
':') {
92 if(c >=
'0' && c <=
'9') {
94 }
else if(c >=
'a' && c <=
'f') {
96 }
else if(c >=
'A' && c <=
'F') {
99 LOG_ERR(
"illegal char: '%c'\n", c);
102 value = (value << 4) + (tmp & 0xf);
105 if(c !=
'\0' && c !=
']' && c !=
'/') {
106 LOG_ERR(
"too large address\n");
109 if(len <
sizeof(uip_ip6addr_t)) {
111 LOG_ERR(
"too short address\n");
114 memmove(&ipaddr->u8[zero +
sizeof(uip_ip6addr_t) - len],
115 &ipaddr->u8[zero], len - zero);
116 memset(&ipaddr->u8[zero], 0,
sizeof(uip_ip6addr_t) - len);
126 uiplib_ip4addrconv(
const char *addrstr,
uip_ip4addr_t *ipaddr)
131 uint8_t charsread = 0;
135 for(i = 0; i < 4; ++i) {
143 if(c ==
'.' || c == 0 || c ==
' ') {
146 }
else if(c >=
'0' && c <=
'9') {
147 tmp = (tmp * 10) + (c -
'0');
153 }
while(c !=
'.' && c != 0 && c !=
' ');
156 return charsread - 1;
162 char buf[UIPLIB_IPV6_MAX_STR_LEN];
180 n = snprintf(buf, size,
"(NULL IP addr)");
182 }
else if(ip64_addr_is_ipv4_mapped_addr(addr)) {
197 n = snprintf(buf, size,
"::FFFF:%u.%u.%u.%u", addr->u8[12],
198 addr->u8[13], addr->u8[14], addr->u8[15]);
201 for(i = 0, f = 0; i <
sizeof(uip_ipaddr_t); i += 2) {
202 a = (addr->u8[i] << 8) + addr->u8[i + 1];
203 if(a == 0 && f >= 0) {
205 n += snprintf(buf+n, size-n,
"::");
214 n += snprintf(buf+n, size-n,
":");
219 n += snprintf(buf+n, size-n,
"%x", a);
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.
Representation of an IP address.
Header file for the IP address manipulation library.
Header file for the uIP TCP/IP stack.
void uiplib_ipaddr_print(const uip_ipaddr_t *addr)
Print an IP address using printf().
Header file for the logging system
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.