FreeCalypso > hg > themwi-system-sw
comparison 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 |
comparison
equal
deleted
inserted
replaced
20:b13acb024fc6 | 21:cc0e1c6e33c3 |
---|---|
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", 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 } |