comparison mtctest/sock_conn.c @ 5:e7b192a5dee5

mtctest: initial import from old ThemWi
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 00:58:38 +0000
parents
children
comparison
equal deleted inserted replaced
4:ce450869db09 5:e7b192a5dee5
1 /*
2 * In this module we implement our connection to the MNCC daemon's
3 * mtcall socket.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <sys/un.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include "../include/mncc.h"
13
14 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket";
15
16 int mtc_socket;
17
18 connect_mtc_socket()
19 {
20 struct sockaddr_un sa;
21 unsigned sa_len;
22 int rc;
23
24 mtc_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0);
25 if (mtc_socket < 0) {
26 perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)");
27 exit(1);
28 }
29 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len);
30 rc = connect(mtc_socket, (struct sockaddr *) &sa, sa_len);
31 if (rc < 0) {
32 perror(mtcall_socket_pathname);
33 exit(1);
34 }
35 return(0);
36 }
37
38 void
39 mtc_socket_select()
40 {
41 union mncc_msg msg;
42 int rc;
43
44 rc = recv(mtc_socket, &msg, sizeof msg, 0);
45 if (rc < 0) {
46 perror("read from socket");
47 exit(1);
48 }
49 if (rc < 4) {
50 fprintf(stderr, "short read from socket: %d bytes\n", rc);
51 exit(1);
52 }
53 msg_from_mncc(&msg, rc);
54 }
55
56 send_mncc_to_gsm(msg, msglen)
57 union mncc_msg *msg;
58 unsigned msglen;
59 {
60 return send(mtc_socket, msg, msglen, 0);
61 }