# HG changeset patch # User Mychaela Falconia # Date 1678608860 28800 # Node ID 857d78c58f56a42a4f229fa8e829c13890a2a45d # Parent f8c40090a0a89f49d50b5caa6cceb9d5c5f4acb6 rtp-alloc-test program written diff -r f8c40090a0a8 -r 857d78c58f56 .hgignore --- 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$ diff -r f8c40090a0a8 -r 857d78c58f56 Makefile --- 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}" diff -r f8c40090a0a8 -r 857d78c58f56 utils/Makefile --- 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 diff -r f8c40090a0a8 -r 857d78c58f56 utils/rtp-alloc-test.c --- /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 +#include +#include +#include +#include +#include +#include +#include +#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); +}