diff sip-in/mgw_sock.c @ 47:62f39c7cee15

themwi-sip-in skeleton started
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Sep 2022 20:33:56 -0800
parents
children 02761f1ae5e5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip-in/mgw_sock.c	Tue Sep 06 20:33:56 2022 -0800
@@ -0,0 +1,57 @@
+/*
+ * In this module we implement our local socket interface to themwi-mgw.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include "../include/tmgw_ctrl.h"
+
+static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket";
+
+int mgw_socket;
+
+open_tmgw_socket()
+{
+	struct sockaddr_un sa;
+	unsigned sa_len;
+	int rc;
+
+	mgw_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (mgw_socket < 0) {
+		syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m");
+		return(-1);
+	}
+	fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len);
+	rc = connect(mgw_socket, (struct sockaddr *) &sa, sa_len);
+	if (rc < 0) {
+		syslog(LOG_ERR, "connect to %s: %m", tmgw_socket_pathname);
+		return(-1);
+	}
+	update_max_fd(mgw_socket);
+	return(0);
+}
+
+void
+mgw_socket_select()
+{
+	struct tmgw_ctrl_resp msg;
+	int rc;
+
+	rc = recv(mgw_socket, &msg, sizeof msg, 0);
+	if (rc < 0) {
+		syslog(LOG_CRIT, "error reading from TMGW socket: %m");
+		exit(1);
+	}
+	if (rc != sizeof(struct tmgw_ctrl_resp)) {
+		syslog(LOG_CRIT,
+			"response packet from TMGW has wrong length: %d bytes",
+			rc);
+		exit(1);
+	}
+	/* processing to be implemented */
+}