! \brief checks if ip is in host(name) and ?host(ip)=name? * ip must be in network byte order! * resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made * \return 0 if equal */
| 657 | * resolver = DO_DNS | DO_REV_DNS; if 0 no dns check is made |
| 658 | * \return 0 if equal */ |
| 659 | int check_ip_address(struct ip_addr* ip, str *name, |
| 660 | unsigned short port, unsigned short proto, int resolver) |
| 661 | { |
| 662 | struct ip_addr *ip2; |
| 663 | struct hostent* he; |
| 664 | int i; |
| 665 | |
| 666 | /* maybe we are lucky and host (name) is an IP */ |
| 667 | if ( (ip2=str2ip(name))!=NULL || (ip2=str2ip6(name))!=NULL ) { |
| 668 | /* It's an IP :D */ |
| 669 | if (ip_addr_cmp(ip, ip2)) |
| 670 | return 0; |
| 671 | return -1; |
| 672 | } |
| 673 | |
| 674 | /* host is not an IP, do the DNS lookups on it :(*/ |
| 675 | if (port==0) port=SIP_PORT; |
| 676 | if (resolver&DO_DNS){ |
| 677 | LM_DBG("doing dns lookup\n"); |
| 678 | /* try all names ips */ |
| 679 | he=sip_resolvehost(name, &port, &proto, 0, 0); |
| 680 | if (he && (int)ip->af==he->h_addrtype){ |
| 681 | for(i=0;he && he->h_addr_list[i];i++){ |
| 682 | if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0) |
| 683 | return 0; |
| 684 | } |
| 685 | } |
| 686 | } |
| 687 | if (resolver&DO_REV_DNS){ |
| 688 | LM_DBG("doing rev. dns lookup\n"); |
| 689 | /* try reverse dns */ |
| 690 | he=rev_resolvehost(ip); |
| 691 | if (he && (strncmp(he->h_name, name->s, name->len)==0)) |
| 692 | return 0; |
| 693 | for (i=0; he && he->h_aliases[i];i++){ |
| 694 | if (strncmp(he->h_aliases[i],name->s, name->len)==0) |
| 695 | return 0; |
| 696 | } |
| 697 | } |
| 698 | return -1; |
| 699 | } |
| 700 | |
| 701 | |
| 702 |