Changeset 5627 for pjproject


Ignore:
Timestamp:
Jul 18, 2017 11:49:04 AM (7 years ago)
Author:
nanang
Message:

Close #2027: Fixed assertion in pj_gethostip() when system hostname is empty.

File:
1 edited

Legend:

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

    r5485 r5627  
    794794    PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION == 0 
    795795    /* Get hostname's IP address */ 
    796     count = 1; 
    797     status = pj_getaddrinfo(af, pj_gethostname(), &count, &ai); 
    798     if (status == PJ_SUCCESS) { 
    799         pj_assert(ai.ai_addr.addr.sa_family == (pj_uint16_t)af); 
    800         pj_sockaddr_copy_addr(&cand_addr[cand_cnt], &ai.ai_addr); 
    801         pj_sockaddr_set_port(&cand_addr[cand_cnt], 0); 
    802         cand_weight[cand_cnt] += WEIGHT_HOSTNAME; 
    803         ++cand_cnt; 
    804  
    805         TRACE_((THIS_FILE, "hostname IP is %s", 
    806                 pj_sockaddr_print(&ai.ai_addr, strip, sizeof(strip), 0))); 
     796    { 
     797        const pj_str_t *hostname = pj_gethostname(); 
     798        count = 1; 
     799 
     800        if (hostname->slen > 0) 
     801            status = pj_getaddrinfo(af, hostname, &count, &ai); 
     802        else 
     803            status = PJ_ERESOLVE; 
     804 
     805        if (status == PJ_SUCCESS) { 
     806            pj_assert(ai.ai_addr.addr.sa_family == (pj_uint16_t)af); 
     807            pj_sockaddr_copy_addr(&cand_addr[cand_cnt], &ai.ai_addr); 
     808            pj_sockaddr_set_port(&cand_addr[cand_cnt], 0); 
     809            cand_weight[cand_cnt] += WEIGHT_HOSTNAME; 
     810            ++cand_cnt; 
     811 
     812            TRACE_((THIS_FILE, "hostname IP is %s", 
     813                    pj_sockaddr_print(&ai.ai_addr, strip, sizeof(strip), 0))); 
     814        } 
    807815    } 
    808816#else 
Note: See TracChangeset for help on using the changeset viewer.