Changeset 4148
- Timestamp:
- May 31, 2012 12:21:59 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/sipecho.c
r4000 r4148 42 42 43 43 /* Settings */ 44 #define AF pj_AF_INET() /* Change to pj_AF_INET6() for IPv6.45 * PJ_HAS_IPV6 must be enabled and46 * your system must support IPv6. */47 #define SIP_PORT 5060 /* Listening SIP port */48 44 #define MAX_CALLS 8 49 45 … … 79 75 static pj_bool_t on_rx_request( pjsip_rx_data *rdata ); 80 76 77 /* Globals */ 78 static int sip_af; 79 static int sip_port = 5060; 80 static pj_bool_t sip_tcp; 81 81 82 82 /* This is a PJSIP module to be registered by application to handle … … 239 239 pj_status_t status; 240 240 241 pj_log_set_level(5);242 243 status = pj_init();244 CHECK_STATUS();245 246 241 pj_log_set_level(3); 247 242 … … 256 251 257 252 pj_log_set_level(4); 258 pj_sockaddr_init(AF, &addr, NULL, (pj_uint16_t)SIP_PORT); 259 if (AF == pj_AF_INET()) { 260 status = pjsip_udp_transport_start( app.sip_endpt, &addr.ipv4, NULL, 261 1, NULL); 262 } else if (AF == pj_AF_INET6()) { 263 status = pjsip_udp_transport_start6(app.sip_endpt, &addr.ipv6, NULL, 264 1, NULL); 253 pj_sockaddr_init((pj_uint16_t)sip_af, &addr, NULL, (pj_uint16_t)sip_port); 254 if (sip_af == pj_AF_INET()) { 255 if (sip_tcp) { 256 status = pjsip_tcp_transport_start( app.sip_endpt, &addr.ipv4, 1, 257 NULL); 258 } else { 259 status = pjsip_udp_transport_start( app.sip_endpt, &addr.ipv4, 260 NULL, 1, NULL); 261 } 262 } else if (sip_af == pj_AF_INET6()) { 263 status = pjsip_udp_transport_start6(app.sip_endpt, &addr.ipv6, 264 NULL, 1, NULL); 265 265 } else { 266 266 status = PJ_EAFNOTSUP; … … 489 489 490 490 /* Generate Contact URI */ 491 status = pj_gethostip( AF, &hostaddr);491 status = pj_gethostip(sip_af, &hostaddr); 492 492 if (status != PJ_SUCCESS) { 493 493 app_perror(THIS_FILE, "Unable to retrieve local host IP", status); … … 495 495 } 496 496 pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2); 497 pj_ansi_sprintf(temp, "<sip:sipecho@%s:%d>", hostip, SIP_PORT);497 pj_ansi_sprintf(temp, "<sip:sipecho@%s:%d>", hostip, sip_port); 498 498 local_uri = pj_str(temp); 499 499 … … 542 542 543 543 544 static void usage() 545 { 546 printf("\nUsage: sipecho OPTIONS\n"); 547 printf("\n"); 548 printf("where OPTIONS:\n"); 549 printf(" --local-port, -p PORT Bind to port PORT.\n"); 550 printf(" --tcp, -t Listen to TCP instead.\n"); 551 printf(" --ipv6, -6 Use IPv6 instead.\n"); 552 printf(" --help, -h Show this help page.\n"); 553 } 554 544 555 /* main() 545 556 * … … 549 560 int main(int argc, char *argv[]) 550 561 { 562 struct pj_getopt_option long_options[] = { 563 { "local-port", 1, 0, 'p' }, 564 { "tcp", 0, 0, 't' }, 565 { "ipv6", 0, 0, '6' }, 566 { "help", 0, 0, 'h' } 567 }; 568 int c, option_index; 569 570 pj_log_set_level(5); 571 572 pj_init(); 573 574 sip_af = pj_AF_INET(); 575 576 pj_optind = 0; 577 while ((c = pj_getopt_long(argc, argv, "p:t6h", long_options, 578 &option_index)) != -1) 579 { 580 switch (c) { 581 case 'p': 582 sip_port = atoi(pj_optarg); 583 break; 584 case 't': 585 sip_tcp = PJ_TRUE; 586 break; 587 case 'h': 588 usage(); 589 return 0; 590 case '6': 591 sip_af = pj_AF_INET6(); 592 break; 593 default: 594 PJ_LOG(1,(THIS_FILE, 595 "Argument \"%s\" is not valid. Use --help to see help", 596 argv[pj_optind-1])); 597 return -1; 598 } 599 } 600 551 601 if (init_stack()) 552 602 goto on_error; 553 603 554 604 /* If URL is specified, then make call immediately. */ 555 if ( argc > 1) {605 if (pj_optind != argc) { 556 606 pj_sockaddr hostaddr; 557 607 char hostip[PJ_INET6_ADDRSTRLEN+2]; 558 608 char temp[80]; 559 609 call_t *call; 560 pj_str_t dst_uri = pj_str(argv[ 1]);610 pj_str_t dst_uri = pj_str(argv[pj_optind]); 561 611 pj_str_t local_uri; 562 612 pjsip_dialog *dlg; … … 564 614 pjsip_tx_data *tdata; 565 615 566 if (pj_gethostip( AF, &hostaddr) != PJ_SUCCESS) {616 if (pj_gethostip(sip_af, &hostaddr) != PJ_SUCCESS) { 567 617 PJ_LOG(1,(THIS_FILE, "Unable to retrieve local host IP")); 568 618 goto on_error; … … 571 621 572 622 pj_ansi_sprintf(temp, "<sip:sipecho@%s:%d>", 573 hostip, SIP_PORT);623 hostip, sip_port); 574 624 local_uri = pj_str(temp); 575 625
Note: See TracChangeset
for help on using the changeset viewer.