Changeset 1851 for pjproject/trunk
- Timestamp:
- Mar 8, 2008 9:26:22 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/simpleua.c
r1735 r1851 30 30 * Capabilities to be demonstrated here: 31 31 * - Basic call 32 * - Should support IPv6 (not tested) 32 33 * - UDP transport at port 5060 (hard coded) 33 34 * - RTP socket at port 4000 (hard coded) … … 63 64 64 65 #include "util.h" 66 67 68 /* Settings */ 69 #define AF pj_AF_INET() /* Change to pj_AF_INET6() for IPv6. 70 * PJ_HAS_IPV6 must be enabled and 71 * your system must support IPv6. */ 72 #define SIP_PORT 5060 /* Listening SIP port */ 73 #define RTP_PORT 4000 /* RTP port */ 65 74 66 75 /* … … 180 189 */ 181 190 { 182 pj_sockaddr_in addr; 183 184 addr.sin_family = pj_AF_INET(); 185 addr.sin_addr.s_addr = 0; 186 addr.sin_port = pj_htons(5060); 187 188 status = pjsip_udp_transport_start( g_endpt, &addr, NULL, 1, NULL); 191 pj_sockaddr addr; 192 193 pj_sockaddr_init(AF, &addr, NULL, (pj_uint16_t)SIP_PORT); 194 195 if (AF == pj_AF_INET()) { 196 status = pjsip_udp_transport_start( g_endpt, &addr.ipv4, NULL, 197 1, NULL); 198 } else if (AF == pj_AF_INET6()) { 199 status = pjsip_udp_transport_start6(g_endpt, &addr.ipv6, NULL, 200 1, NULL); 201 } else { 202 status = PJ_EAFNOTSUP; 203 } 204 189 205 if (status != PJ_SUCCESS) { 190 206 app_perror(THIS_FILE, "Unable to start UDP transport", status); … … 274 290 * opt to re-use the same media transport for subsequent calls. 275 291 */ 276 status = pjmedia_transport_udp_create (g_med_endpt, NULL, 4000, 0,277 292 status = pjmedia_transport_udp_create3(g_med_endpt, AF, NULL, NULL, 293 RTP_PORT, 0, &g_med_transport); 278 294 if (status != PJ_SUCCESS) { 279 295 app_perror(THIS_FILE, "Unable to create media transport", status); … … 293 309 */ 294 310 if (argc > 1) { 311 pj_sockaddr hostaddr; 312 char hostip[PJ_INET6_ADDRSTRLEN+2]; 295 313 char temp[80]; 296 314 pj_str_t dst_uri = pj_str(argv[1]); … … 300 318 pjsip_tx_data *tdata; 301 319 302 pj_ansi_sprintf(temp, "sip:simpleuac@%s", pjsip_endpt_name(g_endpt)->ptr); 320 if (pj_gethostip(AF, &hostaddr) != PJ_SUCCESS) { 321 app_perror(THIS_FILE, "Unable to retrieve local host IP", status); 322 return 1; 323 } 324 pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2); 325 326 pj_ansi_sprintf(temp, "<sip:simpleuac@%s:%d>", 327 hostip, SIP_PORT); 303 328 local_uri = pj_str(temp); 304 329 … … 306 331 status = pjsip_dlg_create_uac( pjsip_ua_instance(), 307 332 &local_uri, /* local URI */ 308 NULL,/* local Contact */333 &local_uri, /* local Contact */ 309 334 &dst_uri, /* remote URI */ 310 335 &dst_uri, /* remote target */ … … 462 487 static pj_bool_t on_rx_request( pjsip_rx_data *rdata ) 463 488 { 489 pj_sockaddr hostaddr; 490 char temp[80], hostip[PJ_INET6_ADDRSTRLEN]; 491 pj_str_t local_uri; 464 492 pjsip_dialog *dlg; 465 493 pjmedia_sdp_session *local_sdp; … … 514 542 515 543 /* 544 * Generate Contact URI 545 */ 546 if (pj_gethostip(AF, &hostaddr) != PJ_SUCCESS) { 547 app_perror(THIS_FILE, "Unable to retrieve local host IP", status); 548 return PJ_TRUE; 549 } 550 pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2); 551 552 pj_ansi_sprintf(temp, "<sip:simpleuas@%s:%d>", 553 hostip, SIP_PORT); 554 local_uri = pj_str(temp); 555 556 /* 516 557 * Create UAS dialog. 517 558 */ 518 559 status = pjsip_dlg_create_uas( pjsip_ua_instance(), 519 560 rdata, 520 NULL, /* contact */561 &local_uri, /* contact */ 521 562 &dlg); 522 563 if (status != PJ_SUCCESS) {
Note: See TracChangeset
for help on using the changeset viewer.