! \brief returns an ip_addr struct.; on error returns 0 * the ip_addr struct is static, so subsequent calls will destroy its content*/
| 626 | /*! \brief returns an ip_addr struct.; on error returns 0 |
| 627 | * the ip_addr struct is static, so subsequent calls will destroy its content*/ |
| 628 | static inline struct ip_addr* str2ip6(str* st) |
| 629 | { |
| 630 | int i, idx1, rest; |
| 631 | int no_colons; |
| 632 | int double_colon; |
| 633 | int hex; |
| 634 | static struct ip_addr ip; |
| 635 | unsigned short* addr_start; |
| 636 | unsigned short addr_end[8]; |
| 637 | unsigned short* addr; |
| 638 | unsigned char* limit; |
| 639 | unsigned char* s; |
| 640 | |
| 641 | if (st == NULL || st->s == NULL) goto error_char; |
| 642 | /* init */ |
| 643 | if ((st->len) && (st->s[0]=='[')){ |
| 644 | /* skip over [ ] */ |
| 645 | if (st->s[st->len-1]!=']') goto error_char; |
| 646 | s=(unsigned char*)(st->s+1); |
| 647 | limit=(unsigned char*)(st->s+st->len-1); |
| 648 | }else{ |
| 649 | s=(unsigned char*)st->s; |
| 650 | limit=(unsigned char*)(st->s+st->len); |
| 651 | } |
| 652 | i=idx1=rest=0; |
| 653 | double_colon=0; |
| 654 | no_colons=0; |
| 655 | ip.af=AF_INET6; |
| 656 | ip.len=16; |
| 657 | addr_start=ip.u.addr16; |
| 658 | addr=addr_start; |
| 659 | memset(addr_start, 0 , 8*sizeof(unsigned short)); |
| 660 | memset(addr_end, 0 , 8*sizeof(unsigned short)); |
| 661 | for (; s<limit; s++){ |
| 662 | if (*s==':'){ |
| 663 | no_colons++; |
| 664 | if (no_colons>7) goto error_too_many_colons; |
| 665 | if (double_colon){ |
| 666 | idx1=i; |
| 667 | i=0; |
| 668 | if (addr==addr_end) goto error_colons; |
| 669 | addr=addr_end; |
| 670 | }else{ |
| 671 | double_colon=1; |
| 672 | addr[i]=htons(addr[i]); |
| 673 | i++; |
| 674 | } |
| 675 | }else if ((hex=HEX2I(*s))>=0){ |
| 676 | addr[i]=addr[i]*16+hex; |
| 677 | double_colon=0; |
| 678 | }else{ |
| 679 | /* error, unknown char */ |
| 680 | goto error_char; |
| 681 | } |
| 682 | } |
| 683 | if (!double_colon){ /* not ending in ':' */ |
| 684 | addr[i]=htons(addr[i]); |
| 685 | i++; |
no outgoing calls
no test coverage detected