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

Function resolvehost

resolve.c:495–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493}
494
495inline struct hostent* resolvehost(char* name, int no_ip_test)
496{
497 static struct hostent *he = NULL;
498#ifdef HAVE_GETIPNODEBYNAME
499 int err;
500 static struct hostent *he2 = NULL;
501#endif
502 struct timeval start;
503 struct ip_addr *ip;
504 str s;
505
506 if (!no_ip_test) {
507 s.s = (char *)name;
508 s.len = strlen(name);
509
510 /* check if it's an ip address */
511 if ((ip = str2ip(&s)) || (ip = str2ip6(&s))) {
512 /* we are lucky, this is an ip address */
513 return ip_addr2he(&s, ip);
514 }
515 }
516
517 start_expire_timer(start, execdnsthreshold);
518
519 if (dns_try_ipv6) {
520 /* try ipv6 */
521 #ifdef HAVE_GETHOSTBYNAME2
522 if (dnscache_fetch_func)
523 he = own_gethostbyname2(name,AF_INET6);
524 else
525 he = gethostbyname2(name, AF_INET6);
526
527 #elif defined HAVE_GETIPNODEBYNAME
528 /* on solaris 8 getipnodebyname has a memory leak,
529 * after some time calls to it will fail with err=3
530 * solution: patch your solaris 8 installation */
531 if (he2) freehostent(he2);
532 he = he2 = getipnodebyname(name, AF_INET6, 0, &err);
533 #else
534 #error "neither gethostbyname2 or getipnodebyname present"
535 #endif
536 if (he != 0)
537 /* return the inet6 result if exists */
538 goto out;
539 }
540
541 if (dnscache_fetch_func)
542 he = own_gethostbyname2(name,AF_INET);
543 else
544 he = gethostbyname(name);
545
546out:
547 _stop_expire_timer(start, execdnsthreshold, "dns",
548 name, strlen(name), 0, dns_slow_queries, dns_total_queries);
549 return he;
550}
551
552struct hostent * own_gethostbyaddr(void *addr, socklen_t len, int af)

Callers 15

fixup_f_send_sockFunction · 0.85
fix_socketFunction · 0.85
tr_eval_ipFunction · 0.85
do_srv_lookupFunction · 0.85
sip_resolvehostFunction · 0.85
get_next_heFunction · 0.85
datagram_parseFunction · 0.85
stream_parseFunction · 0.85
net_resolve_ipv4Function · 0.85
xj_jcon_connectFunction · 0.85
rc_get_ipaddrFunction · 0.85
jsonrpc_get_dstFunction · 0.85

Calls 4

str2ipFunction · 0.85
str2ip6Function · 0.85
ip_addr2heFunction · 0.85
own_gethostbyname2Function · 0.85

Tested by

no test coverage detected