Ignore:
Timestamp:
Dec 30, 2005 11:50:15 PM (18 years ago)
Author:
bennylp
Message:

Basic module, transport, and sending messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c

    r105 r106  
    2222#include <pj/pool.h> 
    2323#include <pj/sock.h> 
     24#include <pj/addr_resolv.h> 
    2425#include <pj/os.h> 
    2526#include <pj/lock.h> 
     
    268269    pj_status_t status; 
    269270 
     271    PJ_ASSERT_RETURN(endpt && sock!=PJ_INVALID_SOCKET && a_name && async_cnt>0, 
     272                     PJ_EINVAL); 
     273 
    270274    /* Create pool. */ 
    271275    pool = pjsip_endpt_create_pool(endpt, "udp%p", PJSIP_POOL_LEN_TRANSPORT,  
     
    328332                              pj_inet_ntoa(((pj_sockaddr_in*)&tp->base.local_addr)->sin_addr), 
    329333                              pj_ntohs(((pj_sockaddr_in*)&tp->base.local_addr)->sin_port), 
    330                               tp->base.local_name.host, 
     334                              tp->base.local_name.host.ptr, 
    331335                              tp->base.local_name.port); 
    332336 
     
    368372    /* Create rdata and put it in the array. */ 
    369373    tp->rdata_cnt = 0; 
     374    tp->rdata = pj_pool_calloc(tp->base.pool, async_cnt,  
     375                               sizeof(pjsip_rx_data*)); 
    370376    for (i=0; i<async_cnt; ++i) { 
    371377        pj_pool_t *rdata_pool = pjsip_endpt_create_pool(endpt, "rtd%p",  
     
    383389        tp->rdata[i]->tp_info.pool = rdata_pool; 
    384390        tp->rdata[i]->tp_info.transport = &tp->base; 
     391        tp->rdata[i]->tp_info.op_key.rdata = tp->rdata[i]; 
    385392        pj_ioqueue_op_key_init(&tp->rdata[i]->tp_info.op_key.op_key,  
    386393                               sizeof(pj_ioqueue_op_key_t)); 
     
    437444    pjsip_host_port bound_name; 
    438445 
     446    PJ_ASSERT_RETURN(local != NULL, PJ_EINVAL); 
     447 
    439448    status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock); 
    440449    if (status != PJ_SUCCESS) 
     
    448457 
    449458    if (a_name == NULL) { 
     459        /* Address name is not specified.  
     460         * Build a name based on bound address. 
     461         */ 
    450462        a_name = &bound_name; 
    451463        bound_name.host.ptr = addr_buf; 
    452         pj_strcpy2(&bound_name.host, pj_inet_ntoa(local->sin_addr)); 
    453464        bound_name.port = pj_ntohs(local->sin_port); 
     465 
     466        /* If bound address specifies "0.0.0.0", get the IP address 
     467         * of local hostname. 
     468         */ 
     469        if (local->sin_addr.s_addr == PJ_INADDR_ANY) { 
     470            pj_hostent he; 
     471            const pj_str_t *hostname = pj_gethostname(); 
     472            status = pj_gethostbyname(hostname, &he); 
     473            if (status != PJ_SUCCESS) { 
     474                pj_sock_close(sock); 
     475                return status; 
     476            } 
     477            pj_strcpy2(&bound_name.host,  
     478                       pj_inet_ntoa(*(pj_in_addr*)he.h_addr)); 
     479        } else { 
     480            /* Otherwise use bound address. */ 
     481            pj_strcpy2(&bound_name.host, pj_inet_ntoa(local->sin_addr)); 
     482        } 
     483         
    454484    } 
    455485 
Note: See TracChangeset for help on using the changeset viewer.