comparison sip-manual-out/dummy_rtp.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
comparison
equal deleted inserted replaced
70:47976db01894 71:d74b545a3c2a
1 /*
2 * In this module we implement the code that connects to themwi-mgw
3 * and obtains a dummy PSTN-side RTP endpoint.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <sys/un.h>
9 #include <netinet/in.h>
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <strings.h>
15 #include "../include/tmgw_ctrl.h"
16 #include "../include/tmgw_const.h"
17
18 struct sockaddr_in dummy_rtp_endp;
19
20 static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket";
21
22 obtain_dummy_rtp()
23 {
24 struct sockaddr_un sa;
25 unsigned sa_len;
26 int fd, rc;
27 struct tmgw_ctrl_req req;
28 struct tmgw_ctrl_resp resp;
29
30 fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
31 if (fd < 0) {
32 perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)");
33 exit(1);
34 }
35 fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len);
36 rc = connect(fd, (struct sockaddr *) &sa, sa_len);
37 if (rc < 0) {
38 perror(tmgw_socket_pathname);
39 exit(1);
40 }
41 bzero(&req, sizeof req);
42 req.opcode = TMGW_CTRL_OP_CRCX;
43 req.ep_id = TMGW_EP_TYPE_DUMMY_PSTN;
44 rc = send(fd, &req, sizeof req, 0);
45 if (rc < 0) {
46 perror("send to TMGW socket");
47 exit(1);
48 }
49 rc = recv(fd, &resp, sizeof resp, 0);
50 if (rc < 0) {
51 perror("recv from TMGW socket");
52 exit(1);
53 }
54 if (rc != sizeof resp) {
55 fprintf(stderr,
56 "error: response packet from TMGW has wrong length (%d bytes)\n",
57 rc);
58 exit(1);
59 }
60 if (resp.res != TMGW_RESP_OK) {
61 fprintf(stderr, "TMGW CRCX returned error %u\n", resp.res);
62 exit(1);
63 }
64 bcopy(&resp.pstn_addr, &dummy_rtp_endp, sizeof(struct sockaddr_in));
65 return(0);
66 }