view smsc-daemon/send_mt.c @ 22:7bfe3e21eaae default tip

top Makefile: add ctrl-client
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 17 Dec 2023 08:53:35 +0000
parents d9db8661d9f3
children
line wrap: on
line source

/*
 * This module holds the code for the local socket: receiving MT-forwardSM.req
 * messages from proto-smsc-sendmt and forwarding them to our GSUP connection.
 */

#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>

#include <osmocom/core/msgb.h>
#include <osmocom/core/socket.h>
#include <osmocom/core/select.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>

#include <osmocom/gsupclient/gsup_client.h>

#include "logging.h"

extern struct osmo_gsup_client *g_gc;

static struct osmo_fd socket_ofd;

static int localsock_cb(struct osmo_fd *bfd, unsigned int what)
{
	struct msgb *msg;
	int rc;

	msg = osmo_gsup_client_msgb_alloc();
	rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0);
	if (rc <= 0) {
		LOGP(DMAIN, LOGL_ERROR,
		     "recv from local socket returned %d\n", rc);
		return -1;
	}
	msgb_put(msg, rc);
	LOGP(DMAIN, LOGL_INFO,
	     "forwarding msg of %d bytes from local socket\n", rc);
	osmo_gsup_client_send(g_gc, msg);
	return 0;
}

void setup_local_socket(const char *pathname)
{
	int rc;

	socket_ofd.cb = localsock_cb;
	rc = osmo_sock_unix_init_ofd(&socket_ofd, SOCK_DGRAM, 0, pathname,
				     OSMO_SOCK_F_BIND);
	if (rc < 0) {
		fprintf(stderr, "error: unable to set up local socket\n");
		exit(1);
	}
}