FreeCalypso > hg > themwi-system-sw
diff sip-manual-out/main.c @ 71:d74b545a3c2a
sip-manual-out: new test program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 20 Sep 2022 10:14:18 -0800 |
parents | |
children | 51e2f72dc5ab |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sip-manual-out/main.c Tue Sep 20 10:14:18 2022 -0800 @@ -0,0 +1,106 @@ +/* + * This is the main module for sip-manual-out test program. + */ + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/socket.h> +#include <sys/errno.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <unistd.h> +#include "../libsip/out_msg.h" +#include "../libsip/sdp.h" + +extern int sip_socket; +extern struct in_addr sip_bind_ip, sip_dest_ip; +extern unsigned sip_bind_port, sip_dest_port; +extern char sip_dest_domain[]; +extern struct sockaddr_in dummy_rtp_endp; + +struct sockaddr_in sip_dest_sin; +char from_uri[128], to_uri[128], call_id[128]; +struct timeval cur_event_time; + +send_invite_req() +{ + struct sip_msg_out msg; + struct sdp_gen sdp; + int rc; + + rc = start_request_out_msg(&msg, "INVITE", to_uri); + if (rc < 0) { +msg_size_err: fprintf(stderr, "composing INVITE req: msg size error\n"); + exit(1); + } + rc = add_req_boilerplate(&msg, "1 INVITE"); + if (rc < 0) + goto msg_size_err; + rc = add_contact_header(&msg); + if (rc < 0) + goto msg_size_err; + rc = out_msg_add_header(&msg, "Content-Type", "application/sdp"); + if (rc < 0) + goto msg_size_err; + bzero(&sdp, sizeof sdp); + sdp.conn_ip = dummy_rtp_endp.sin_addr; + sdp.conn_port = ntohs(dummy_rtp_endp.sin_port); + sdp.codec_mask = SDP_CODEC_MASK_BOTH; + sdp.session_id = sdp.conn_port << 16; + sdp.owner_ip = sip_bind_ip; + rc = out_msg_finish_sdp(&msg, &sdp); + if (rc < 0) + goto msg_size_err; + sip_tx_packet(&msg, &sip_dest_sin); +} + +main(argc, argv) + char **argv; +{ + fd_set fds; + int rc; + + if (argc < 4 || argc > 5) { + fprintf(stderr, + "usage: %s dest-conf from-num to-num [logfile]\n", + argv[0]); + exit(1); + } + read_config_file(argv[1]); + open_sip_udp_socket(); + obtain_dummy_rtp(); + sip_dest_sin.sin_family = AF_INET; + sip_dest_sin.sin_addr = sip_dest_ip; + sip_dest_sin.sin_port = htons(sip_dest_port); + sprintf(from_uri, "sip:%s@%s", argv[2], inet_ntoa(sip_bind_ip)); + sprintf(to_uri, "sip:%s@%s", argv[3], sip_dest_domain); + if (argv[4]) { + rc = open_sip_log_file(argv[4]); + if (rc < 0) + exit(1); /* error msg already printed */ + } + gettimeofday(&cur_event_time, 0); + sprintf(call_id, "%08u_%u@%s", + (unsigned)(cur_event_time.tv_sec % 100000000), + ntohs(dummy_rtp_endp.sin_port), inet_ntoa(sip_bind_ip)); + send_invite_req(); + /* main select loop */ + for (;;) { + FD_ZERO(&fds); + FD_SET(sip_socket, &fds); + rc = select(sip_socket+1, &fds, 0, 0, 0); + if (rc < 0) { + if (errno == EINTR) + continue; + perror("select"); + exit(1); + } + gettimeofday(&cur_event_time, 0); + if (FD_ISSET(sip_socket, &fds)) + sip_socket_select(); + } +}