Changeset 1587


Ignore:
Timestamp:
Nov 20, 2007 9:47:32 AM (16 years ago)
Author:
bennylp
Message:

Ticket #419: initial support for DNS AAAA resolution

Location:
pjproject/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/include/pjlib-util/dns.h

    r1032 r1587  
    4242 * This module provides low-level services to parse and packetize DNS queries 
    4343 * and responses. The functions support building a DNS query packet and parse 
    44  * the data in the DNS response. 
     44 * the data in the DNS response. This implementation conforms to the  
     45 * following specifications: 
     46 *  - RFC 1035: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION 
     47 *  - RFC 1886: DNS Extensions to support IP version 6 
    4548 * 
    4649 * To create a DNS query packet, application should call #pj_dns_make_query() 
     
    259262        /** A Resource Data (PJ_DNS_TYPE_A, 1) */ 
    260263        struct a { 
    261             pj_in_addr  ip_addr;/**< IP host address string.                */ 
     264            pj_in_addr  ip_addr;/**< IPv4 address in network byte order.    */ 
    262265        } a; 
     266 
     267        /** AAAA Resource Data (PJ_DNS_TYPE_AAAA, 28) */ 
     268        struct aaaa { 
     269            pj_in6_addr ip_addr;/**< IPv6 address in network byte order.    */ 
     270        } aaaa; 
    263271 
    264272    } rdata; 
  • pjproject/trunk/pjlib-util/include/pjlib-util/srv_resolver.h

    r1357 r1587  
    7676 
    7777/** 
     78 * Flags to be specified when starting the DNS SRV query. 
     79 */ 
     80enum pj_dns_srv_option 
     81{ 
     82    /** 
     83     * Specify if the resolver should fallback with DNS A 
     84     * resolution when the SRV resolution fails. This option may 
     85     * be specified together with PJ_DNS_SRV_FALLBACK_AAAA to 
     86     * make the resolver fallback to AAAA if SRV resolution fails, 
     87     * and then to DNS A resolution if the AAAA resolution fails. 
     88     */ 
     89    PJ_DNS_SRV_FALLBACK_A       = 1, 
     90 
     91    /** 
     92     * Specify if the resolver should fallback with DNS AAAA 
     93     * resolution when the SRV resolution fails. This option may 
     94     * be specified together with PJ_DNS_SRV_FALLBACK_A to 
     95     * make the resolver fallback to AAAA if SRV resolution fails, 
     96     * and then to DNS A resolution if the AAAA resolution fails. 
     97     */ 
     98    PJ_DNS_SRV_FALLBACK_AAAA    = 2, 
     99 
     100    /** 
     101     * Specify if the resolver should try to resolve with DNS AAAA 
     102     * resolution first of each targets in the DNS SRV record. If 
     103     * this option is not specified, the SRV resolver will query 
     104     * the DNS A record for the target instead. 
     105     */ 
     106    PJ_DNS_SRV_RESOLVE_AAAA     = 4 
     107 
     108} pj_dns_srv_option; 
     109 
     110 
     111/** 
    78112 * This structure represents DNS SRV records as the result of DNS SRV 
    79113 * resolution using #pj_dns_srv_resolve(). 
     
    86120    /** Address records. */ 
    87121    struct 
    88 v    { 
     122    { 
    89123        /** Server priority (the lower the higher the priority). */ 
    90124        unsigned                priority; 
     
    126160 * @param pool          Memory pool used to allocate memory for the query. 
    127161 * @param resolver      The resolver instance. 
    128  * @param fallback_a    Specify if the resolver should fallback with DNS A 
    129  *                      resolution when the SRV resolution fails. 
     162 * @param option        Option flags, which can be constructed from 
     163 *                      #pj_dns_srv_option bitmask. Note that this argument 
     164 *                      was called "fallback_a" in pjsip version 0.8.0 and 
     165 *                      older, but the new option should be backward  
     166 *                      compatible with existing applications. If application 
     167 *                      specifies PJ_TRUE as "fallback_a" value, it will 
     168 *                      correspond to PJ_DNS_SRV_FALLBACK_A option. 
    130169 * @param token         Arbitrary data to be associated with this query when 
    131170 *                      the calback is called. 
     
    143182                                        pj_pool_t *pool, 
    144183                                        pj_dns_resolver *resolver, 
    145                                         pj_bool_t fallback_a, 
     184                                        unsigned option, 
    146185                                        void *token, 
    147186                                        pj_dns_srv_resolver_cb *cb, 
  • pjproject/trunk/pjlib-util/src/pjlib-util/dns.c

    r1364 r1587  
    3030    switch (type) { 
    3131    case PJ_DNS_TYPE_A:     return "A"; 
     32    case PJ_DNS_TYPE_AAAA:  return "AAAA"; 
    3233    case PJ_DNS_TYPE_SRV:   return "SRV"; 
    3334    case PJ_DNS_TYPE_NS:    return "NS"; 
     
    346347        pj_memcpy(&rr->rdata.a.ip_addr, p, 4); 
    347348        p += 4; 
     349 
     350    } else if (rr->type == PJ_DNS_TYPE_AAAA) { 
     351        pj_memcpy(&rr->rdata.aaaa.ip_addr, p, 16); 
     352        p += 16; 
    348353 
    349354    } else if (rr->type == PJ_DNS_TYPE_CNAME || 
     
    592597    } else if (src->type == PJ_DNS_TYPE_A) { 
    593598        dst->rdata.a.ip_addr.s_addr =  src->rdata.a.ip_addr.s_addr; 
     599    } else if (src->type == PJ_DNS_TYPE_AAAA) { 
     600        pj_memcpy(&dst->rdata.aaaa.ip_addr, &src->rdata.aaaa.ip_addr, 
     601                  sizeof(pj_in6_addr)); 
    594602    } else if (src->type == PJ_DNS_TYPE_CNAME) { 
    595603        pj_strdup(pool, &dst->rdata.cname.name, &src->rdata.cname.name); 
  • pjproject/trunk/pjlib-util/src/pjlib-util/dns_dump.c

    r1031 r1587  
    118118        PJ_LOG(3,(THIS_FILE, "    IP address: %s", 
    119119                  pj_inet_ntoa(rr->rdata.a.ip_addr))); 
     120    } else if (rr->type == PJ_DNS_TYPE_AAAA) { 
     121        char addr[PJ_INET6_ADDRSTRLEN]; 
     122        PJ_LOG(3,(THIS_FILE, "    IPv6 address: %s", 
     123                  pj_inet_ntop(pj_AF_INET6(), &rr->rdata.aaaa.ip_addr, 
     124                               addr, sizeof(addr)))); 
    120125    } 
    121126} 
  • pjproject/trunk/pjlib-util/src/pjlib-util/srv_resolver.c

    r1383 r1587  
    5656 
    5757    /* Original request: */ 
    58     pj_bool_t                fallback_a; 
     58    unsigned                 option; 
    5959    pj_str_t                 full_name; 
    6060    pj_str_t                 domain_part; 
     
    8686                                        pj_pool_t *pool, 
    8787                                        pj_dns_resolver *resolver, 
    88                                         pj_bool_t fallback_a, 
     88                                        unsigned option, 
    8989                                        void *token, 
    9090                                        pj_dns_srv_resolver_cb *cb, 
     
    117117    query_job->token = token; 
    118118    query_job->cb = cb; 
    119     query_job->fallback_a = fallback_a; 
     119    query_job->option = option; 
    120120    query_job->full_name = target_name; 
    121121    query_job->domain_part.ptr = target_name.ptr + len; 
     
    418418 
    419419            /* Trigger error when fallback is disabled */ 
    420             if (query_job->fallback_a == PJ_FALSE) { 
     420            if ((query_job->option & 
     421                 (PJ_DNS_SRV_FALLBACK_A | PJ_DNS_SRV_FALLBACK_AAAA)) == 0)  
     422            { 
    421423                goto on_error; 
    422424            } 
  • pjproject/trunk/pjlib/src/pj/sock_bsd.c

    r1585 r1587  
    308308{ 
    309309    PJ_ASSERT_RETURN(src && dst && size, PJ_EINVAL); 
     310 
     311    *dst = '\0'; 
     312 
    310313    PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL); 
    311314 
Note: See TracChangeset for help on using the changeset viewer.