70 const ip_addr_t ip6_addr_any = IPADDR6_INIT(0ul, 0ul, 0ul, 0ul);
73 #define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) 74 #define isprint(c) in_range(c, 0x20, 0x7f) 75 #define isdigit(c) in_range(c, '0', '9') 76 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) 77 #define islower(c) in_range(c, 'a', 'z') 78 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') 79 #define xchar(i) ((i) < 10 ? '0' + (i) : 'A' + (i) - 10) 92 ip6addr_aton(
const char *cp, ip6_addr_t *addr)
94 u32_t addr_index, zero_blocks, current_block_index, current_block_value;
100 for (s = cp; *s != 0; s++) {
103 }
else if (!isxdigit(*s)) {
110 current_block_index = 0;
111 current_block_value = 0;
112 for (s = cp; *s != 0; s++) {
115 if (current_block_index & 0x1) {
116 addr->addr[addr_index++] |= current_block_value;
119 addr->addr[addr_index] = current_block_value << 16;
122 current_block_index++;
123 current_block_value = 0;
124 if (current_block_index > 7) {
135 while (zero_blocks > 0) {
137 if (current_block_index & 0x1) {
141 addr->addr[addr_index] = 0;
144 current_block_index++;
145 if (current_block_index > 7) {
151 }
else if (isxdigit(*s)) {
153 current_block_value = (current_block_value << 4) +
154 (isdigit(*s) ? (u32_t)(*s -
'0') :
155 (u32_t)(10 + (islower(*s) ? *s -
'a' : *s -
'A')));
163 if (current_block_index & 0x1) {
164 addr->addr[addr_index++] |= current_block_value;
167 addr->addr[addr_index] = current_block_value << 16;
173 for (addr_index = 0; addr_index < 4; addr_index++) {
174 addr->addr[addr_index] = lwip_htonl(addr->addr[addr_index]);
178 if (current_block_index != 7) {
194 ip6addr_ntoa(
const ip6_addr_t *addr)
197 return ip6addr_ntoa_r(addr, str, 40);
210 ip6addr_ntoa_r(
const ip6_addr_t *addr,
char *buf,
int buflen)
212 u32_t current_block_index, current_block_value, next_block_value;
214 u8_t zero_flag, empty_block_flag;
217 empty_block_flag = 0;
219 for (current_block_index = 0; current_block_index < 8; current_block_index++) {
221 current_block_value = lwip_htonl(addr->addr[current_block_index >> 1]);
222 if ((current_block_index & 0x1) == 0) {
223 current_block_value = current_block_value >> 16;
225 current_block_value &= 0xffff;
228 if (current_block_value == 0) {
229 if (current_block_index == 7 && empty_block_flag == 1) {
237 if (empty_block_flag == 0) {
240 next_block_value = lwip_htonl(addr->addr[(current_block_index + 1) >> 1]);
241 if ((current_block_index & 0x1) == 0x01) {
242 next_block_value = next_block_value >> 16;
244 next_block_value &= 0xffff;
245 if (next_block_value == 0) {
246 empty_block_flag = 1;
253 }
else if (empty_block_flag == 1) {
257 }
else if (empty_block_flag == 1) {
259 empty_block_flag = 2;
262 if (current_block_index > 0) {
269 if ((current_block_value & 0xf000) == 0) {
272 buf[i++] = xchar(((current_block_value & 0xf000) >> 12));
279 if (((current_block_value & 0xf00) == 0) && (zero_flag)) {
282 buf[i++] = xchar(((current_block_value & 0xf00) >> 8));
289 if (((current_block_value & 0xf0) == 0) && (zero_flag)) {
293 buf[i++] = xchar(((current_block_value & 0xf0) >> 4));
300 buf[i++] = xchar((current_block_value & 0xf));