view sip-manual-out/dummy_rtp.c @ 118:a4450ae8fd09

sip-manual-out UAC: use the new CSeq parsing function
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 29 Sep 2022 13:03:27 -0800
parents d74b545a3c2a
children
line wrap: on
line source

/*
 * In this module we implement the code that connects to themwi-mgw
 * and obtains a dummy PSTN-side RTP endpoint.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../include/tmgw_ctrl.h"
#include "../include/tmgw_const.h"

struct sockaddr_in dummy_rtp_endp;

static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket";

obtain_dummy_rtp()
{
	struct sockaddr_un sa;
	unsigned sa_len;
	int fd, rc;
	struct tmgw_ctrl_req req;
	struct tmgw_ctrl_resp resp;

	fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
	if (fd < 0) {
		perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)");
		exit(1);
	}
	fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len);
	rc = connect(fd, (struct sockaddr *) &sa, sa_len);
	if (rc < 0) {
		perror(tmgw_socket_pathname);
		exit(1);
	}
	bzero(&req, sizeof req);
	req.opcode = TMGW_CTRL_OP_CRCX;
	req.ep_id = TMGW_EP_TYPE_DUMMY_PSTN;
	rc = send(fd, &req, sizeof req, 0);
	if (rc < 0) {
		perror("send to TMGW socket");
		exit(1);
	}
	rc = recv(fd, &resp, sizeof resp, 0);
	if (rc < 0) {
		perror("recv from TMGW socket");
		exit(1);
	}
	if (rc != sizeof resp) {
		fprintf(stderr,
	"error: response packet from TMGW has wrong length (%d bytes)\n",
			rc);
		exit(1);
	}
	if (resp.res != TMGW_RESP_OK) {
		fprintf(stderr, "TMGW CRCX returned error %u\n", resp.res);
		exit(1);
	}
	bcopy(&resp.pstn_addr, &dummy_rtp_endp, sizeof(struct sockaddr_in));
	return(0);
}