FreeCalypso > hg > themwi-system-sw
comparison sip-manual-out/main.c @ 119:056616f7e8ab
sip-manual-out: convert command line to getopt style
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 29 Sep 2022 14:03:06 -0800 |
parents | 51e2f72dc5ab |
children | c62d0f28da6f |
comparison
equal
deleted
inserted
replaced
118:a4450ae8fd09 | 119:056616f7e8ab |
---|---|
56 if (rc < 0) | 56 if (rc < 0) |
57 goto msg_size_err; | 57 goto msg_size_err; |
58 sip_tx_packet(&msg, &sip_dest_sin); | 58 sip_tx_packet(&msg, &sip_dest_sin); |
59 } | 59 } |
60 | 60 |
61 static void | |
62 preliminary_proc(argc, argv) | |
63 char **argv; | |
64 { | |
65 extern int optind; | |
66 extern char *optarg; | |
67 char *logfile; | |
68 int opt, rc; | |
69 | |
70 logfile = 0; | |
71 while ((opt = getopt(argc, argv, "l:")) != EOF) { | |
72 switch (opt) { | |
73 case 'l': | |
74 logfile = optarg; | |
75 continue; | |
76 default: | |
77 usage: | |
78 fprintf(stderr, | |
79 "usage: %s [options] dest-conf from-num to-num\n", | |
80 argv[0]); | |
81 exit(1); | |
82 } | |
83 } | |
84 if (argc != optind + 3) | |
85 goto usage; | |
86 read_config_file(argv[optind]); | |
87 open_sip_udp_socket(); | |
88 obtain_dummy_rtp(); | |
89 sip_dest_sin.sin_family = AF_INET; | |
90 sip_dest_sin.sin_addr = sip_dest_ip; | |
91 sip_dest_sin.sin_port = htons(sip_dest_port); | |
92 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[optind+1], | |
93 inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port)); | |
94 sprintf(to_uri, "sip:%s@%s", argv[optind+2], sip_dest_domain); | |
95 if (logfile) { | |
96 rc = open_sip_log_file(logfile); | |
97 if (rc < 0) | |
98 exit(1); /* error msg already printed */ | |
99 } | |
100 } | |
101 | |
61 main(argc, argv) | 102 main(argc, argv) |
62 char **argv; | 103 char **argv; |
63 { | 104 { |
64 fd_set fds; | 105 fd_set fds; |
65 int rc; | 106 int rc; |
66 | 107 |
67 if (argc < 4 || argc > 5) { | 108 preliminary_proc(argc, argv); |
68 fprintf(stderr, | |
69 "usage: %s dest-conf from-num to-num [logfile]\n", | |
70 argv[0]); | |
71 exit(1); | |
72 } | |
73 read_config_file(argv[1]); | |
74 open_sip_udp_socket(); | |
75 obtain_dummy_rtp(); | |
76 sip_dest_sin.sin_family = AF_INET; | |
77 sip_dest_sin.sin_addr = sip_dest_ip; | |
78 sip_dest_sin.sin_port = htons(sip_dest_port); | |
79 sprintf(from_uri, "<sip:%s@%s>;tag=out%u", argv[2], | |
80 inet_ntoa(sip_bind_ip), ntohs(dummy_rtp_endp.sin_port)); | |
81 sprintf(to_uri, "sip:%s@%s", argv[3], sip_dest_domain); | |
82 if (argv[4]) { | |
83 rc = open_sip_log_file(argv[4]); | |
84 if (rc < 0) | |
85 exit(1); /* error msg already printed */ | |
86 } | |
87 gettimeofday(&cur_event_time, 0); | 109 gettimeofday(&cur_event_time, 0); |
88 sprintf(call_id, "%08u_%u@%s", | 110 sprintf(call_id, "%08u_%u@%s", |
89 (unsigned)(cur_event_time.tv_sec % 100000000), | 111 (unsigned)(cur_event_time.tv_sec % 100000000), |
90 ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); | 112 ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); |
91 send_invite_req(); | 113 send_invite_req(); |