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

Function ip_addr2a

ip_addr.h:430–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428 */
429extern __thread char _ip_addr_A_buffs[IP_ADDR2STR_BUF_NO][IP_ADDR_MAX_STR_SIZE];
430static inline char* ip_addr2a(struct ip_addr* ip)
431{
432 static __thread unsigned int it = 0;
433 int offset;
434 register unsigned char a,b,c;
435 register unsigned char d;
436 register unsigned short hex4;
437 int r;
438 char *_ip_addr_A_buff;
439 #define HEXDIG(x) (((x)>=10)?(x)-10+'A':(x)+'0')
440
441 if ((++it)==IP_ADDR2STR_BUF_NO) it = 0;
442 _ip_addr_A_buff = _ip_addr_A_buffs[it];
443
444 offset=0;
445 switch(ip->af){
446 case AF_INET6:
447 for(r=0;r<7;r++){
448 hex4=ntohs(ip->u.addr16[r]);
449 a=hex4>>12;
450 b=(hex4>>8)&0xf;
451 c=(hex4>>4)&0xf;
452 d=hex4&0xf;
453 if (a){
454 _ip_addr_A_buff[offset]=HEXDIG(a);
455 _ip_addr_A_buff[offset+1]=HEXDIG(b);
456 _ip_addr_A_buff[offset+2]=HEXDIG(c);
457 _ip_addr_A_buff[offset+3]=HEXDIG(d);
458 _ip_addr_A_buff[offset+4]=':';
459 offset+=5;
460 }else if(b){
461 _ip_addr_A_buff[offset]=HEXDIG(b);
462 _ip_addr_A_buff[offset+1]=HEXDIG(c);
463 _ip_addr_A_buff[offset+2]=HEXDIG(d);
464 _ip_addr_A_buff[offset+3]=':';
465 offset+=4;
466 }else if(c){
467 _ip_addr_A_buff[offset]=HEXDIG(c);
468 _ip_addr_A_buff[offset+1]=HEXDIG(d);
469 _ip_addr_A_buff[offset+2]=':';
470 offset+=3;
471 }else{
472 _ip_addr_A_buff[offset]=HEXDIG(d);
473 _ip_addr_A_buff[offset+1]=':';
474 offset+=2;
475 }
476 }
477 /* last int16*/
478 hex4=ntohs(ip->u.addr16[r]);
479 a=hex4>>12;
480 b=(hex4>>8)&0xf;
481 c=(hex4>>4)&0xf;
482 d=hex4&0xf;
483 if (a){
484 _ip_addr_A_buff[offset]=HEXDIG(a);
485 _ip_addr_A_buff[offset+1]=HEXDIG(b);
486 _ip_addr_A_buff[offset+2]=HEXDIG(c);
487 _ip_addr_A_buff[offset+3]=HEXDIG(d);

Callers 15

received_builderFunction · 0.85
receive_msgFunction · 0.85
expand_interfaceFunction · 0.85
fix_socketFunction · 0.85
pv_get_srcipFunction · 0.85
pv_get_proxy_protocolFunction · 0.85
get_out_socketFunction · 0.85
forward_replyFunction · 0.85
tr_eval_ipFunction · 0.85
mi_print_blacklist_ruleFunction · 0.85
tls_find_server_domainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected