Ignore:
Timestamp:
Apr 11, 2007 7:48:42 PM (17 years ago)
Author:
bennylp
Message:

Applying ticket #220 to Symbian branch: Bug in retransmission of non-INVITE SIP requests in UAC transaction (thanks Martin Peterzon)

File:
1 edited

Legend:

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

    r65 r1192  
    5050} 
    5151 
     52/* Resolve the IP address of local machine */ 
     53PJ_DEF(pj_status_t) pj_gethostip(pj_in_addr *addr) 
     54{ 
     55    const pj_str_t *hostname = pj_gethostname(); 
     56    struct pj_hostent he; 
     57    pj_status_t status; 
     58 
     59 
     60#ifdef _MSC_VER 
     61    /* Get rid of "uninitialized he variable" with MS compilers */ 
     62    pj_memset(&he, 0, sizeof(he)); 
     63#endif 
     64 
     65    /* Try with resolving local hostname first */ 
     66    status = pj_gethostbyname(hostname, &he); 
     67    if (status == PJ_SUCCESS) { 
     68        *addr = *(pj_in_addr*)he.h_addr; 
     69    } 
     70 
     71 
     72    /* If we end up with 127.x.x.x, resolve the IP by getting the default 
     73     * interface to connect to some public host. 
     74     */ 
     75    if (status != PJ_SUCCESS || (pj_ntohl(addr->s_addr) >> 24)==127) { 
     76        pj_sock_t fd; 
     77        pj_str_t cp; 
     78        pj_sockaddr_in a; 
     79        int len; 
     80 
     81        status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd); 
     82        if (status != PJ_SUCCESS) { 
     83            return status; 
     84        } 
     85 
     86        cp = pj_str("1.1.1.1"); 
     87        pj_sockaddr_in_init(&a, &cp, 53); 
     88 
     89        status = pj_sock_connect(fd, &a, sizeof(a)); 
     90        if (status != PJ_SUCCESS) { 
     91            pj_sock_close(fd); 
     92            /* Return 127.0.0.1 as the address */ 
     93            return PJ_SUCCESS; 
     94        } 
     95 
     96        len = sizeof(a); 
     97        status = pj_sock_getsockname(fd, &a, &len); 
     98        if (status != PJ_SUCCESS) { 
     99            pj_sock_close(fd); 
     100            /* Return 127.0.0.1 as the address */ 
     101            return PJ_SUCCESS; 
     102        } 
     103 
     104        pj_sock_close(fd); 
     105 
     106        *addr = a.sin_addr; 
     107    } 
     108 
     109    return status; 
     110} 
     111 
     112 
Note: See TracChangeset for help on using the changeset viewer.