Changeset 1744 for pjproject/trunk


Ignore:
Timestamp:
Jan 24, 2008 7:59:41 PM (17 years ago)
Author:
bennylp
Message:

Related to ticket #458: pj_getaddrinfo() should return success if IP address is given

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c

    r1714 r1744  
    7171                     af==PJ_AF_UNSPEC, PJ_EINVAL); 
    7272 
     73    /* Check if nodename is IP address */ 
     74    pj_bzero(&ai[0], sizeof(ai[0])); 
     75    ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 
     76    if (pj_inet_pton(af, nodename, pj_sockaddr_get_addr(&ai[0].ai_addr))  
     77         == PJ_SUCCESS)  
     78    { 
     79        pj_str_t tmp; 
     80 
     81        tmp.ptr = ai[0].ai_canonname; 
     82        pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 
     83        ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 
     84        *count = 1; 
     85 
     86        return PJ_SUCCESS; 
     87    } 
     88 
    7389    /* Copy node name to null terminated string. */ 
    7490    if (nodename->slen >= PJ_MAX_HOSTNAME) 
     
    119135#else   /* PJ_SOCK_HAS_GETADDRINFO */ 
    120136 
    121     PJ_ASSERT_RETURN(count, PJ_EINVAL); 
     137    PJ_ASSERT_RETURN(count && *count, PJ_EINVAL); 
     138 
     139    /* Check if nodename is IP address */ 
     140    pj_bzero(&ai[0], sizeof(ai[0])); 
     141    ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 
     142    if (pj_inet_pton(af, nodename, pj_sockaddr_get_addr(&ai[0].ai_addr))  
     143         == PJ_SUCCESS)  
     144    { 
     145        pj_str_t tmp; 
     146 
     147        tmp.ptr = ai[0].ai_canonname; 
     148        pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 
     149        ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 
     150        *count = 1; 
     151 
     152        return PJ_SUCCESS; 
     153    } 
    122154 
    123155    if (af == PJ_AF_INET || af == PJ_AF_UNSPEC) { 
Note: See TracChangeset for help on using the changeset viewer.