MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / str2ip6

Function str2ip6

ip_addr.h:628–722  ·  view source on GitHub ↗

! \brief returns an ip_addr struct.; on error returns 0 * the ip_addr struct is static, so subsequent calls will destroy its content*/

Source from the content-addressed store, hash-verified

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*/
628static 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++;

Callers 15

grep_sock_info_extFunction · 0.85
fix_socketFunction · 0.85
mk_net_cidrFunction · 0.85
comp_ipFunction · 0.85
tr_eval_ipFunction · 0.85
resolvehostFunction · 0.85
check_ip_addressFunction · 0.85
sip_resolvehostFunction · 0.85
parse_ip_netFunction · 0.85
parse_domain_addressFunction · 0.85
reload_address_tableFunction · 0.85
check_addrFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected