Exemplo n.º 1
0
/*
 * sip_config_get_nat_ipaddr()
 *
 * Get the nat IP address.
 * Note: the IP Address is returned in the non-Telecaster
 *       SIP format, which is not byte reversed.
 *       Eg. 0xac2c33f8 = 161.44.51.248
 */
void
sip_config_get_nat_ipaddr (cpr_ip_addr_t *ip_addr)
{
    cpr_ip_addr_t IPAddress;
    char address[MAX_IPADDR_STR_LEN];
    int dnsErrorCode = 1;

    if (redirected_nat_ipaddr.type == CPR_IP_ADDR_INVALID) {
        config_get_string(CFGID_NAT_ADDRESS, address, sizeof(address));
        if ((cpr_strcasecmp(address, UNPROVISIONED) != 0) && (address[0] != 0)) {
            dnsErrorCode = dnsGetHostByName(address, &IPAddress, 100, 1);
        }

        if (dnsErrorCode == 0) {
            util_ntohl(ip_addr, &IPAddress);
            return ;
        } else {
            /*
             * If the NAT address is not provisioned or
             * unavailable, return the local address instead.
             */
            sip_config_get_net_device_ipaddr(ip_addr);
            return;
        }
    } else {
        *ip_addr = redirected_nat_ipaddr;
        return ;
    }

}
Exemplo n.º 2
0
int
sip_dns_gethostbysrvorname (char *hname,
                            cpr_ip_addr_t *ipaddr_ptr,
                            uint16_t *port)
{
    /*
     * OK according to rfc2543bis-03
     * 1. If the destination is an IP address it is used. If no port is
     *    specified then use 5060
     * 2. If the destination specifies the default port (5060) or no port
     *    then try SRV
     * 3. If the destination specifies a port number other than 5060 or
     *    there are no SRV records A record lookup
     */
    srv_handle_t srv_order = NULL;
    int rc=DNS_ERR_NOHOST;

    if ((*port == SIP_WELL_KNOWN_PORT) || (*port == 0)) {
        rc = sip_dns_gethostbysrv(hname, ipaddr_ptr, port, &srv_order, FALSE);
    }
    if (rc != DNS_OK) {
        rc = dnsGetHostByName(hname, ipaddr_ptr, 100, 1);
    }
    if (srv_order) {
        dnsFreeSrvHandle(srv_order);
    }
    return rc;
}