changeset 185:857d78c58f56

rtp-alloc-test program written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 Mar 2023 00:14:20 -0800
parents f8c40090a0a8
children 068fce34e565
files .hgignore Makefile utils/Makefile utils/rtp-alloc-test.c
diffstat 4 files changed, 70 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Mar 11 23:48:14 2023 -0800
+++ b/.hgignore	Sun Mar 12 00:14:20 2023 -0800
@@ -16,6 +16,7 @@
 
 ^sip-out/themwi-sip-out$
 
+^utils/rtp-alloc-test$
 ^utils/sip-out-test$
 ^utils/sip-rx-test$
 ^utils/sip-udp-dump$
--- a/Makefile	Sat Mar 11 23:48:14 2023 -0800
+++ b/Makefile	Sun Mar 12 00:14:20 2023 -0800
@@ -14,7 +14,7 @@
 sip-in:		libnumdb libsip libutil
 sip-manual-out:	libsip libutil
 sip-out:	liboutrt libsip libutil
-utils:		libnumdb libsip libutil
+utils:		libnumdb librtpalloc libsip libutil
 
 ${SUBDIR}: FRC
 	cd $@; ${MAKE} ${MFLAGS} CC=${CC} CFLAGS="${CFLAGS}"
--- a/utils/Makefile	Sat Mar 11 23:48:14 2023 -0800
+++ b/utils/Makefile	Sun Mar 12 00:14:20 2023 -0800
@@ -3,12 +3,17 @@
 PROGS=	sip-out-test sip-rx-test sip-udp-dump themwi-check-own \
 	themwi-dump-numdb themwi-short-dial themwi-update-numdb \
 	themwi-update-outrt
+NOINST=	rtp-alloc-test
 LIBNUMDB=../libnumdb/libnumdb.a
+LIBRTPA=../librtpalloc/librtpalloc.a
 LIBSIP=	../libsip/libsip.a
 LIBUTIL=../libutil/libutil.a
 INSTBIN=/usr/local/bin
 
-all:	${PROGS}
+all:	${PROGS} ${NOINST}
+
+rtp-alloc-test:	rtp-alloc-test.o ${LIBRTPA} ${LIBUTIL}
+	${CC} ${CFLAGS} -o $@ $@.o ${LIBRTPA} ${LIBUTIL}
 
 sip-out-test:	sip-out-test.c
 	${CC} ${CFLAGS} -o $@ $@.c
@@ -38,4 +43,4 @@
 	install -c -o bin -g bin -m 755 ${PROGS} ${INSTBIN}
 
 clean:
-	rm -f *.o ${PROGS} errs
+	rm -f *.o ${PROGS} ${NOINST} errs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/rtp-alloc-test.c	Sun Mar 12 00:14:20 2023 -0800
@@ -0,0 +1,61 @@
+/*
+ * This program exercises the path of obtaining an RTP endpoint from
+ * themwi-rtp-mgr via rtp_alloc_simple(), serving as a test for
+ * the themwi-rtp-mgr daemon and for both upper and lower layers of
+ * librtpalloc.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../include/tmgw_const.h"
+#include "../librtpalloc/rtp_alloc_simple.h"
+
+static void
+print_ip_port(desc, sin)
+	char *desc;
+	struct sockaddr_in *sin;
+{
+	printf("%s IP %s port %u\n", inet_ntoa(sin->sin_addr),
+		ntohs(sin->sin_port));
+}
+
+main(argc, argv)
+	char **argv;
+{
+	int ep_type, rc;
+	struct rtp_alloc_simple res;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s ep-type\n", argv[0]);
+		exit(1);
+	}
+	if (!strcmp(argv[1], "gsm"))
+		ep_type = TMGW_EP_TYPE_GSM_ONLY;
+	else if (!strcmp(argv[1], "pstn"))
+		ep_type = TMGW_EP_TYPE_PSTN_ONLY;
+	else if (!strcmp(argv[1], "gateway"))
+		ep_type = TMGW_EP_TYPE_GATEWAY;
+	else {
+		fprintf(stderr, "error: unknown endpoint type \"%s\"\n",
+			argv[1]);
+		exit(1);
+	}
+	rc = rtp_alloc_simple(ep_type, &res);
+	if (rc < 0)
+		exit(1);	/* error msg already printed */
+	if (ep_type & TMGW_EP_HAS_GSM_SOCK) {
+		print_ip_port("GSM", &res.gsm_addr);
+		printf("GSM fd %d %d\n", res.gsm_rtp_fd, res.gsm_rtcp_fd);
+	}
+	if (ep_type & TMGW_EP_HAS_PSTN_SOCK) {
+		print_ip_port("PSTN", &res.pstn_addr);
+		printf("PSTN fd %d %d\n", res.pstn_rtp_fd, res.pstn_rtcp_fd);
+	}
+	exit(0);
+}