FreeCalypso > hg > themwi-system-sw
comparison sip-in/mgw_sock.c @ 47:62f39c7cee15
themwi-sip-in skeleton started
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 06 Sep 2022 20:33:56 -0800 |
parents | |
children | 02761f1ae5e5 |
comparison
equal
deleted
inserted
replaced
46:5427b26525cd | 47:62f39c7cee15 |
---|---|
1 /* | |
2 * In this module we implement our local socket interface to themwi-mgw. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/socket.h> | |
7 #include <sys/un.h> | |
8 #include <stdio.h> | |
9 #include <stdint.h> | |
10 #include <stdlib.h> | |
11 #include <syslog.h> | |
12 #include "../include/tmgw_ctrl.h" | |
13 | |
14 static char tmgw_socket_pathname[] = "/var/gsm/tmgw_socket"; | |
15 | |
16 int mgw_socket; | |
17 | |
18 open_tmgw_socket() | |
19 { | |
20 struct sockaddr_un sa; | |
21 unsigned sa_len; | |
22 int rc; | |
23 | |
24 mgw_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); | |
25 if (mgw_socket < 0) { | |
26 syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m"); | |
27 return(-1); | |
28 } | |
29 fill_sockaddr_un(tmgw_socket_pathname, &sa, &sa_len); | |
30 rc = connect(mgw_socket, (struct sockaddr *) &sa, sa_len); | |
31 if (rc < 0) { | |
32 syslog(LOG_ERR, "connect to %s: %m", tmgw_socket_pathname); | |
33 return(-1); | |
34 } | |
35 update_max_fd(mgw_socket); | |
36 return(0); | |
37 } | |
38 | |
39 void | |
40 mgw_socket_select() | |
41 { | |
42 struct tmgw_ctrl_resp msg; | |
43 int rc; | |
44 | |
45 rc = recv(mgw_socket, &msg, sizeof msg, 0); | |
46 if (rc < 0) { | |
47 syslog(LOG_CRIT, "error reading from TMGW socket: %m"); | |
48 exit(1); | |
49 } | |
50 if (rc != sizeof(struct tmgw_ctrl_resp)) { | |
51 syslog(LOG_CRIT, | |
52 "response packet from TMGW has wrong length: %d bytes", | |
53 rc); | |
54 exit(1); | |
55 } | |
56 /* processing to be implemented */ | |
57 } |