Changeset 947


Ignore:
Timestamp:
Feb 14, 2007 2:36:13 PM (17 years ago)
Author:
bennylp
Message:

Fixed ticket #101: PJSUA transport is not updated with correct port number if application specifies port is zero

Location:
pjproject/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c

    r904 r947  
    486486        case OPT_LOCAL_PORT:   /* local-port */ 
    487487            lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 
    488             if (lval < 1 || lval > 65535) { 
     488            if (lval < 0 || lval > 65535) { 
    489489                PJ_LOG(1,(THIS_FILE,  
    490490                          "Error: expecting integer value for " 
     
    28922892{ 
    28932893    pjsua_transport_id transport_id = -1; 
     2894    pjsua_transport_config tcp_cfg; 
    28942895    unsigned i; 
    28952896    pj_status_t status; 
     
    29962997    } 
    29972998 
     2999    pj_memcpy(&tcp_cfg, &app_config.udp_cfg, sizeof(tcp_cfg)); 
     3000 
    29983001    /* Add UDP transport unless it's disabled. */ 
    29993002    if (!app_config.no_udp) { 
     
    30103013        //pjsua_acc_set_transport(aid, transport_id); 
    30113014        pjsua_acc_set_online_status(current_acc, PJ_TRUE); 
     3015 
     3016        if (app_config.udp_cfg.port == 0) { 
     3017            pjsua_transport_info ti; 
     3018            pj_sockaddr_in *a; 
     3019 
     3020            pjsua_transport_get_info(transport_id, &ti); 
     3021            a = (pj_sockaddr_in*)&ti.local_addr; 
     3022 
     3023            tcp_cfg.port = pj_ntohs(a->sin_port); 
     3024        } 
    30123025    } 
    30133026 
     
    30153028    if (!app_config.no_tcp) { 
    30163029        status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, 
    3017                                         &app_config.udp_cfg,  
     3030                                        &tcp_cfg,  
    30183031                                        &transport_id); 
    30193032        if (status != PJ_SUCCESS) 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c

    r941 r947  
    842842    } 
    843843 
     844    /* If port is zero, get the bound port */ 
     845    if (port == 0) { 
     846        pj_sockaddr_in bound_addr; 
     847        int namelen = sizeof(bound_addr); 
     848        status = pj_sock_getsockname(sock, &bound_addr, &namelen); 
     849        if (status != PJ_SUCCESS) { 
     850            pjsua_perror(THIS_FILE, "getsockname() error", status); 
     851            pj_sock_close(sock); 
     852            return status; 
     853        } 
     854 
     855        port = pj_ntohs(bound_addr.sin_port); 
     856    } 
     857 
    844858    /* Copy and normalize STUN param */ 
    845859    if (use_stun) { 
     
    874888         * address, only set the port. 
    875889         */ 
    876         /* Do nothing */ 
     890        if (p_pub_addr->sin_port == 0) 
     891            p_pub_addr->sin_port = pj_htons((pj_uint16_t)port); 
    877892 
    878893    } else { 
Note: See TracChangeset for help on using the changeset viewer.