view utils/rtp-alloc-test.c @ 185:857d78c58f56

rtp-alloc-test program written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 Mar 2023 00:14:20 -0800
parents
children 068fce34e565
line wrap: on
line source

/*
 * 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);
}