comparison smsc-daemon/send_mt.c @ 14:d9db8661d9f3

smsc-daemon: add local socket for sendmt
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Aug 2023 17:15:30 -0800
parents
children
comparison
equal deleted inserted replaced
13:2c35aad69fea 14:d9db8661d9f3
1 /*
2 * This module holds the code for the local socket: receiving MT-forwardSM.req
3 * messages from proto-smsc-sendmt and forwarding them to our GSUP connection.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <errno.h>
13
14 #include <osmocom/core/msgb.h>
15 #include <osmocom/core/socket.h>
16 #include <osmocom/core/select.h>
17 #include <osmocom/core/utils.h>
18 #include <osmocom/core/logging.h>
19
20 #include <osmocom/gsupclient/gsup_client.h>
21
22 #include "logging.h"
23
24 extern struct osmo_gsup_client *g_gc;
25
26 static struct osmo_fd socket_ofd;
27
28 static int localsock_cb(struct osmo_fd *bfd, unsigned int what)
29 {
30 struct msgb *msg;
31 int rc;
32
33 msg = osmo_gsup_client_msgb_alloc();
34 rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
35 if (rc <= 0) {
36 LOGP(DMAIN, LOGL_ERROR,
37 "recv from local socket returned %d\n", rc);
38 return -1;
39 }
40 msgb_put(msg, rc);
41 LOGP(DMAIN, LOGL_INFO,
42 "forwarding msg of %d bytes from local socket\n", rc);
43 osmo_gsup_client_send(g_gc, msg);
44 return 0;
45 }
46
47 void setup_local_socket(const char *pathname)
48 {
49 int rc;
50
51 socket_ofd.cb = localsock_cb;
52 rc = osmo_sock_unix_init_ofd(&socket_ofd, SOCK_DGRAM, 0, pathname,
53 OSMO_SOCK_F_BIND);
54 if (rc < 0) {
55 fprintf(stderr, "error: unable to set up local socket\n");
56 exit(1);
57 }
58 }