FreeCalypso > hg > themwi-system-sw
annotate mtctest/sock_conn.c @ 243:59a166c50d0e
themwi-mncc: convert to libnumdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 19:13:26 -0800 |
parents | c08d81fa8117 |
children |
rev | line source |
---|---|
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement our connection to the MNCC daemon's |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * mtcall socket. |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/socket.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/un.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdint.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../include/mncc.h" |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static char mtcall_socket_pathname[] = "/var/gsm/mtcall_socket"; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 int mtc_socket; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 connect_mtc_socket() |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 struct sockaddr_un sa; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned sa_len; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int rc; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 mtc_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (mtc_socket < 0) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 perror("socket(AF_UNIX, SOCK_SEQPACKET, 0)"); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fill_sockaddr_un(mtcall_socket_pathname, &sa, &sa_len); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rc = connect(mtc_socket, (struct sockaddr *) &sa, sa_len); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (rc < 0) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 perror(mtcall_socket_pathname); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(0); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 void |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 mtc_socket_select() |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 union mncc_msg msg; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int rc; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 rc = recv(mtc_socket, &msg, sizeof msg, 0); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (rc < 0) { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 perror("read from socket"); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (rc < 4) { |
26
c08d81fa8117
themwi-test-mtc: missed newline at the end of error message
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
50 fprintf(stderr, "short read from socket: %d bytes\n", rc); |
21
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 msg_from_mncc(&msg, rc); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 send_mncc_to_gsm(msg, msglen) |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 union mncc_msg *msg; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 unsigned msglen; |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 return send(mtc_socket, msg, msglen, 0); |
cc0e1c6e33c3
themwi-test-mtc utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |