diff mtctest/sock_conn.c @ 21:cc0e1c6e33c3

themwi-test-mtc utility written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 28 Jun 2022 18:25:28 -0800
parents
children c08d81fa8117
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mtctest/sock_conn.c	Tue Jun 28 18:25:28 2022 -0800
@@ -0,0 +1,61 @@
+/*
+ * In this module we implement our connection to the MNCC daemon's
+ * mtcall socket.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include "../include/mncc.h"
+
+static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket";
+
+int mtc_socket;
+
+connect_mtc_socket()
+{
+	struct sockaddr_un sa;
+	unsigned sa_len;
+	int rc;
+
+	mtc_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+	if (mtc_socket < 0) {
+		perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)");
+		exit(1);
+	}
+	fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len);
+	rc = connect(mtc_socket, (struct sockaddr *) &sa, sa_len);
+	if (rc < 0) {
+		perror(mtcall_socket_pathname);
+		exit(1);
+	}
+	return(0);
+}
+
+void
+mtc_socket_select()
+{
+	union mncc_msg msg;
+	int rc;
+
+	rc = recv(mtc_socket, &msg, sizeof msg, 0);
+	if (rc < 0) {
+		perror("read from socket");
+		exit(1);
+	}
+	if (rc < 4) {
+		fprintf(stderr, "short read from socket: %d bytes", rc);
+		exit(1);
+	}
+	msg_from_mncc(&msg, rc);
+}
+
+send_mncc_to_gsm(msg, msglen)
+	union mncc_msg *msg;
+	unsigned msglen;
+{
+	return send(mtc_socket, msg, msglen, 0);
+}