FreeCalypso > hg > themwi-interim
comparison mncc/mncc_sock.c @ 2:053f04687106
mncc: initial import from old ThemWi
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 08 Jun 2024 23:12:12 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:b161dbfffdaa | 2:053f04687106 |
---|---|
1 /* | |
2 * In this module we implement low-level handling | |
3 * of the main MNCC socket that connects to OsmoMSC. | |
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 <syslog.h> | |
13 #include "../include/mncc.h" | |
14 | |
15 static char mncc_socket_pathname[] = "/var/gsm/mncc_socket"; | |
16 | |
17 int mncc_socket; | |
18 | |
19 open_mncc_socket() | |
20 { | |
21 struct sockaddr_un sa; | |
22 unsigned sa_len; | |
23 int rc; | |
24 | |
25 mncc_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); | |
26 if (mncc_socket < 0) { | |
27 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m"); | |
28 return(-1); | |
29 } | |
30 fill_sockaddr_un(mncc_socket_pathname, &sa, &sa_len); | |
31 rc = connect(mncc_socket, (struct sockaddr *) &sa, sa_len); | |
32 if (rc < 0) { | |
33 syslog(LOG_ERR, "connect to %s: %m", mncc_socket_pathname); | |
34 return(-1); | |
35 } | |
36 update_max_fd(mncc_socket); | |
37 return(0); | |
38 } | |
39 | |
40 void | |
41 mncc_socket_select() | |
42 { | |
43 union mncc_msg msg; | |
44 int rc; | |
45 | |
46 rc = recv(mncc_socket, &msg, sizeof msg, 0); | |
47 if (rc < 0) { | |
48 syslog(LOG_CRIT, "error reading from MNCC socket: %m"); | |
49 exit(1); | |
50 } | |
51 if (rc < 4) { | |
52 syslog(LOG_CRIT, "short read from MNCC socket: %d bytes", rc); | |
53 exit(1); | |
54 } | |
55 mncc_msg_from_gsm(&msg, rc); | |
56 } | |
57 | |
58 send_mncc_to_gsm(msg, msglen) | |
59 union mncc_msg *msg; | |
60 unsigned msglen; | |
61 { | |
62 return send(mncc_socket, msg, msglen, 0); | |
63 } |