Ignore:
Timestamp:
Apr 5, 2009 6:30:45 PM (15 years ago)
Author:
bennylp
Message:

Ticket #776: IPv6 option in pjsua

File:
1 edited

Legend:

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

    r2566 r2568  
    5959    pjsua_media_config      media_cfg; 
    6060    pj_bool_t               no_refersub; 
     61    pj_bool_t               ipv6; 
    6162    pj_bool_t               no_tcp; 
    6263    pj_bool_t               no_udp; 
     
    139140static pj_status_t transport_adapter_sample(void); 
    140141#endif 
     142static pj_status_t create_ipv6_media_transports(void); 
    141143pj_status_t app_destroy(void); 
    142144 
     
    196198    puts  (""); 
    197199    puts  ("Transport Options:"); 
     200#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6 
     201    puts  ("  --ipv6              Use IPv6 instead for SIP and media."); 
     202#endif 
    198203    puts  ("  --local-port=port   Set TCP/UDP port. This implicitly enables both "); 
    199204    puts  ("                      TCP and UDP transports on the specified port, unless"); 
     
    201206    puts  ("  --ip-addr=IP        Use the specifed address as SIP and RTP addresses."); 
    202207    puts  ("                      (Hint: the IP may be the public IP of the NAT/router)"); 
     208    puts  ("  --bound-addr=IP     Bind transports to this IP interface"); 
    203209    puts  ("  --no-tcp            Disable TCP transport."); 
    204210    puts  ("  --no-udp            Disable UDP transport."); 
     
    465471           OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY,  
    466472           OPT_REGISTRAR, OPT_REG_TIMEOUT, OPT_PUBLISH, OPT_ID, OPT_CONTACT, 
    467            OPT_CONTACT_PARAMS, 
     473           OPT_BOUND_ADDR, OPT_CONTACT_PARAMS, 
    468474           OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD, 
    469475           OPT_NAMESERVER, OPT_STUN_DOMAIN, OPT_STUN_SRV, 
     
    486492           OPT_CAPTURE_DEV, OPT_PLAYBACK_DEV, 
    487493           OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT, OPT_NO_TONES, OPT_JB_MAX_SIZE, 
    488            OPT_STDOUT_REFRESH, OPT_STDOUT_REFRESH_TEXT, 
     494           OPT_STDOUT_REFRESH, OPT_STDOUT_REFRESH_TEXT, OPT_IPV6, 
    489495#ifdef _IONBF 
    490496           OPT_STDOUT_NO_BUF, 
     
    509515        { "local-port", 1, 0, OPT_LOCAL_PORT}, 
    510516        { "ip-addr",    1, 0, OPT_IP_ADDR}, 
     517        { "bound-addr", 1, 0, OPT_BOUND_ADDR}, 
    511518        { "no-tcp",     0, 0, OPT_NO_TCP}, 
    512519        { "no-udp",     0, 0, OPT_NO_UDP}, 
     
    596603        { "no-tones",    0, 0, OPT_NO_TONES}, 
    597604        { "jb-max-size", 1, 0, OPT_JB_MAX_SIZE}, 
     605#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6 
     606        { "ipv6",        0, 0, OPT_IPV6}, 
     607#endif 
    598608        { NULL, 0, 0, 0} 
    599609    }; 
     
    736746            break; 
    737747 
     748        case OPT_BOUND_ADDR: /* bound-addr */ 
     749            cfg->udp_cfg.bound_addr = pj_str(pj_optarg); 
     750            cfg->rtp_cfg.bound_addr = pj_str(pj_optarg); 
     751            break; 
     752 
    738753        case OPT_NO_UDP: /* no-udp */ 
    739754            if (cfg->no_tcp) { 
     
    12571272            cfg->media_cfg.jb_max = atoi(pj_optarg); 
    12581273            break; 
     1274 
     1275#if defined(PJ_HAS_IPV6) && PJ_HAS_IPV6 
     1276        case OPT_IPV6: 
     1277            cfg->ipv6 = PJ_TRUE; 
     1278            break; 
     1279#endif 
    12591280 
    12601281        default: 
     
    15051526    } 
    15061527 
     1528    /* Transport options */ 
     1529    if (config->ipv6) { 
     1530        pj_strcat2(&cfg, "--ipv6\n"); 
     1531    } 
    15071532 
    15081533    /* UDP Transport. */ 
     
    15151540                        (int)config->udp_cfg.public_addr.slen, 
    15161541                        config->udp_cfg.public_addr.ptr); 
     1542        pj_strcat2(&cfg, line); 
     1543    } 
     1544 
     1545    /* Bound IP address, if any. */ 
     1546    if (config->udp_cfg.bound_addr.slen) { 
     1547        pj_ansi_sprintf(line, "--bound-addr %.*s\n",  
     1548                        (int)config->udp_cfg.bound_addr.slen, 
     1549                        config->udp_cfg.bound_addr.ptr); 
    15171550        pj_strcat2(&cfg, line); 
    15181551    } 
     
    43344367    if (!app_config.no_udp) { 
    43354368        pjsua_acc_id aid; 
    4336  
    4337         status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, 
     4369        pjsip_transport_type_e type = PJSIP_TRANSPORT_UDP; 
     4370 
     4371        if (app_config.ipv6) 
     4372            type = PJSIP_TRANSPORT_UDP6; 
     4373 
     4374        status = pjsua_transport_create(type, 
    43384375                                        &app_config.udp_cfg,  
    43394376                                        &transport_id); 
     
    44314468 
    44324469#else 
    4433     status = pjsua_media_transports_create(&app_config.rtp_cfg); 
     4470    if (app_config.ipv6) 
     4471        status = create_ipv6_media_transports(); 
     4472    else 
     4473        status = pjsua_media_transports_create(&app_config.rtp_cfg); 
    44344474#endif 
    44354475    if (status != PJ_SUCCESS) 
     
    46554695#endif 
    46564696 
     4697static pj_status_t create_ipv6_media_transports(void) 
     4698{ 
     4699    pjsua_media_transport tp[PJSUA_MAX_CALLS]; 
     4700    pj_status_t status; 
     4701    int port = app_config.rtp_cfg.port; 
     4702    unsigned i; 
     4703 
     4704    for (i=0; i<app_config.cfg.max_calls; ++i) { 
     4705        enum { MAX_RETRY = 10 }; 
     4706        unsigned j; 
     4707 
     4708        /* Get rid of uninitialized var compiler warning with MSVC */ 
     4709        status = PJ_SUCCESS; 
     4710 
     4711        for (j=0; j<MAX_RETRY; ++j) { 
     4712            status = pjmedia_transport_udp_create3(pjsua_get_pjmedia_endpt(),  
     4713                                                   pj_AF_INET6(), 
     4714                                                   NULL,  
     4715                                                   &app_config.rtp_cfg.bound_addr, 
     4716                                                   port,  
     4717                                                   0, &tp[i].transport); 
     4718 
     4719            if (port != 0) 
     4720                port += 10; 
     4721            else 
     4722                break; 
     4723 
     4724            if (status == PJ_SUCCESS) 
     4725                break; 
     4726        } 
     4727 
     4728        if (status != PJ_SUCCESS) { 
     4729            pjsua_perror(THIS_FILE, "Error creating IPv6 UDP media transport",  
     4730                         status); 
     4731            for (j=0; j<i; ++j) { 
     4732                pjmedia_transport_close(tp[j].transport); 
     4733            } 
     4734            return status; 
     4735        } 
     4736    } 
     4737 
     4738    return pjsua_media_transports_attach(tp, i, PJ_TRUE); 
     4739} 
Note: See TracChangeset for help on using the changeset viewer.