annotate utils/rtp-alloc-test.c @ 241:d7c2a2c0b922

utils/Makefile: only using libnumdb2 now
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 15:42:49 -0800
parents 068fce34e565
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
185
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program exercises the path of obtaining an RTP endpoint from
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * themwi-rtp-mgr via rtp_alloc_simple(), serving as a test for
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * the themwi-rtp-mgr daemon and for both upper and lower layers of
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * librtpalloc.
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/types.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/socket.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <netinet/in.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <arpa/inet.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdio.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <stdlib.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <string.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <strings.h>
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/tmgw_const.h"
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../librtpalloc/rtp_alloc_simple.h"
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 static void
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 print_ip_port(desc, sin)
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 char *desc;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 struct sockaddr_in *sin;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
186
068fce34e565 rtp-alloc-test: fix segfault
Mychaela Falconia <falcon@freecalypso.org>
parents: 185
diff changeset
24 printf("%s IP %s port %u\n", desc, inet_ntoa(sin->sin_addr),
185
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ntohs(sin->sin_port));
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 main(argc, argv)
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 char **argv;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int ep_type, rc;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 struct rtp_alloc_simple res;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (argc != 2) {
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 fprintf(stderr, "usage: %s ep-type\n", argv[0]);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 exit(1);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!strcmp(argv[1], "gsm"))
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 ep_type = TMGW_EP_TYPE_GSM_ONLY;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 else if (!strcmp(argv[1], "pstn"))
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 ep_type = TMGW_EP_TYPE_PSTN_ONLY;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 else if (!strcmp(argv[1], "gateway"))
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 ep_type = TMGW_EP_TYPE_GATEWAY;
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 else {
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr, "error: unknown endpoint type \"%s\"\n",
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 argv[1]);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 exit(1);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 rc = rtp_alloc_simple(ep_type, &res);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rc < 0)
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1); /* error msg already printed */
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (ep_type & TMGW_EP_HAS_GSM_SOCK) {
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 print_ip_port("GSM", &res.gsm_addr);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 printf("GSM fd %d %d\n", res.gsm_rtp_fd, res.gsm_rtcp_fd);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (ep_type & TMGW_EP_HAS_PSTN_SOCK) {
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 print_ip_port("PSTN", &res.pstn_addr);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 printf("PSTN fd %d %d\n", res.pstn_rtp_fd, res.pstn_rtcp_fd);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 exit(0);
857d78c58f56 rtp-alloc-test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }