annotate utils/sip-out-test.c @ 62:75b7a7b61824

sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 17 Sep 2022 18:43:08 -0800
parents ffb563a17f23
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program is a contraption for testing manually constructed
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * outgoing SIP calls to BulkVS.
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/time.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/errno.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <netinet/in.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <arpa/inet.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdio.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <unistd.h>
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #define MAX_SIP_TX_PACKET 1472
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 static struct in_addr local_ip, remote_ip;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static unsigned local_sip_port, local_rtp_port, remote_port;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static char *invite_filename, *log_filename;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 static char invite_packet[MAX_SIP_TX_PACKET];
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static unsigned invite_packet_len;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static FILE *logF;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 static struct timeval curtime;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 static void
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 read_invite_file()
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 FILE *inf;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 char linebuf[128], *cp, *dp;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 int lineno;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 unsigned size_accum, linelen;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 inf = fopen(invite_filename, "r");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (!inf) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 perror(invite_filename);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 size_accum = 0;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 dp = invite_packet;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 for (lineno = 1; fgets(linebuf, sizeof(linebuf), inf); lineno++) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 cp = index(linebuf, '\n');
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (!cp) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 "%s line %d: too long or missing newline\n",
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 invite_filename, lineno);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 *cp = '\0';
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 linelen = cp - linebuf;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (size_accum + linelen + 2 > MAX_SIP_TX_PACKET) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fprintf(stderr, "%s line %d: packet overflow\n",
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 invite_filename, lineno);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 bcopy(linebuf, dp, linelen);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 dp += linelen;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 *dp++ = '\r';
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *dp++ = '\n';
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 size_accum += linelen + 2;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 fclose(inf);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (!size_accum) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 fprintf(stderr, "error: %s is empty\n", invite_filename);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 invite_packet_len = size_accum;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 static void
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 log_common(msg, msglen, sin, dir, outf)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 char *msg, *dir;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 unsigned msglen;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 struct sockaddr_in *sin;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 FILE *outf;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 unsigned sec, ms;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 sec = curtime.tv_sec % 86400;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 ms = curtime.tv_usec / 1000;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fprintf(outf, "Msg %s %s:%u %u bytes %02u:%02u:%02u.%03u\n", dir,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), msglen,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 sec / 3600, (sec / 60) % 60, sec % 60, ms);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 fwrite(msg, 1, msglen, outf);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 putc('\n', outf);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 fflush(outf);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 static void
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 log_sip_msg_rx(msg, msglen, sin)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 char *msg;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 unsigned msglen;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 struct sockaddr_in *sin;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 log_common(msg, msglen, sin, "from", stdout);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (logF)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 log_common(msg, msglen, sin, "from", logF);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 static void
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 log_sip_msg_tx(msg, msglen, sin)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 char *msg;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 unsigned msglen;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 struct sockaddr_in *sin;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 log_common(msg, msglen, sin, "to", stdout);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 if (logF)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 log_common(msg, msglen, sin, "to", logF);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 main(argc, argv)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 char **argv;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 struct sockaddr_in sin_local, sin_rtp, sin_rtcp, sin_remote, sin_rx;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 int sock_sip, sock_rtp, sock_rtcp, max_fd;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 socklen_t addrlen;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 fd_set fds;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 char recv_buf[4096];
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 int rc;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 /* grok command line arguments */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (argc < 7 || argc > 8) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 fprintf(stderr,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 "usage: %s local-ip local-sip local-rtp remote-ip remote-sip inv-file [logfile]\n",
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 argv[0]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 local_ip.s_addr = inet_addr(argv[1]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (local_ip.s_addr == INADDR_NONE) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 fprintf(stderr, "error: invalid IP address \"%s\"\n", argv[1]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 local_sip_port = atoi(argv[2]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 local_rtp_port = atoi(argv[3]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 remote_ip.s_addr = inet_addr(argv[4]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (remote_ip.s_addr == INADDR_NONE) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 fprintf(stderr, "error: invalid IP address \"%s\"\n", argv[4]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 remote_port = atoi(argv[5]);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 invite_filename = argv[6];
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 log_filename = argv[7];
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 /* fill sin structures */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 sin_local.sin_family = AF_INET;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 sin_local.sin_addr = local_ip;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 sin_local.sin_port = htons(local_sip_port);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 sin_rtp.sin_family = AF_INET;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 sin_rtp.sin_addr = local_ip;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 sin_rtp.sin_port = htons(local_rtp_port);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 sin_rtcp.sin_family = AF_INET;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 sin_rtcp.sin_addr = local_ip;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 sin_rtcp.sin_port = htons(local_rtp_port+1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 sin_remote.sin_family = AF_INET;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 sin_remote.sin_addr = remote_ip;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 sin_remote.sin_port = htons(remote_port);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 /* create and bind sockets */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 sock_sip = socket(AF_INET, SOCK_DGRAM, 0);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 if (sock_sip < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 perror("socket");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 rc = bind(sock_sip, (struct sockaddr *) &sin_local,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 sizeof(struct sockaddr_in));
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 perror("bind");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 sock_rtp = socket(AF_INET, SOCK_DGRAM, 0);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (sock_rtp < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 perror("socket");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 rc = bind(sock_rtp, (struct sockaddr *) &sin_rtp,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 sizeof(struct sockaddr_in));
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 perror("bind");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 sock_rtcp = socket(AF_INET, SOCK_DGRAM, 0);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 if (sock_rtcp < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 perror("socket");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 rc = bind(sock_rtcp, (struct sockaddr *) &sin_rtcp,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 sizeof(struct sockaddr_in));
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 perror("bind");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 /* read the INVITE packet */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 read_invite_file();
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 /* open the log file, if we have one */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (log_filename) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 logF = fopen(log_filename, "a");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 if (!logF) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 perror(log_filename);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 /* now get down to business */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 max_fd = sock_sip;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 if (sock_rtp > max_fd)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 max_fd = sock_rtp;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 if (sock_rtcp > max_fd)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 max_fd = sock_rtcp;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 addrlen = sizeof(struct sockaddr_in);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 rc = sendto(sock_sip, invite_packet, invite_packet_len, 0,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 (struct sockaddr *) &sin_remote, addrlen);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 perror("sendto");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 gettimeofday(&curtime, 0);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 log_sip_msg_tx(invite_packet, invite_packet_len, &sin_remote);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 /* main select loop */
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 for (;;) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 FD_ZERO(&fds);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 FD_SET(sock_sip, &fds);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 FD_SET(sock_rtp, &fds);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 FD_SET(sock_rtcp, &fds);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 rc = select(max_fd+1, &fds, 0, 0, 0);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 if (errno == EINTR)
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 continue;
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 perror("select");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 gettimeofday(&curtime, 0);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 if (FD_ISSET(sock_sip, &fds)) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 addrlen = sizeof(struct sockaddr_in);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 rc = recvfrom(sock_sip, recv_buf, sizeof recv_buf, 0,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 (struct sockaddr *) &sin_rx, &addrlen);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 perror("recvfrom");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 log_sip_msg_rx(recv_buf, rc, &sin_rx);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 if (FD_ISSET(sock_rtp, &fds)) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 addrlen = sizeof(struct sockaddr_in);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 rc = recvfrom(sock_rtp, recv_buf, sizeof recv_buf, 0,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 (struct sockaddr *) &sin_rx, &addrlen);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 perror("recvfrom");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 if (FD_ISSET(sock_rtcp, &fds)) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 addrlen = sizeof(struct sockaddr_in);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 rc = recvfrom(sock_rtp, recv_buf, sizeof recv_buf, 0,
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 (struct sockaddr *) &sin_rx, &addrlen);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 if (rc < 0) {
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 perror("recvfrom");
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 exit(1);
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 }
ffb563a17f23 wrote sip-out-test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 }