changeset 225:243ed87880a1

smpp-send: implement sending via local socket
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 12:52:33 -0800
parents 62184b971c8e
children 28441920fb35
files smpp-send/Makefile smpp-send/build_pdu.c smpp-send/sock_send.c
diffstat 3 files changed, 42 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/smpp-send/Makefile	Sat Aug 05 12:27:36 2023 -0800
+++ b/smpp-send/Makefile	Sat Aug 05 12:52:33 2023 -0800
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	smpp-send
-OBJS=	build_pdu.o hexdump.o input.o main.o msg_cmd.o settings.o
+OBJS=	build_pdu.o hexdump.o input.o main.o msg_cmd.o settings.o sock_send.o
 LIBS=	../libutil/libutil.a
 INSTBIN=/usr/local/bin
 
--- a/smpp-send/build_pdu.c	Sat Aug 05 12:27:36 2023 -0800
+++ b/smpp-send/build_pdu.c	Sat Aug 05 12:52:33 2023 -0800
@@ -16,6 +16,7 @@
 extern u_char prio_flag, reg_deliv, replace_flag;
 
 extern int input_lineno;
+extern char *trx_socket;
 
 void
 build_submit_sm(payload, payload_len, udhi)
@@ -86,5 +87,8 @@
 	pdu[2] = pdu_len >> 8;
 	pdu[3] = pdu_len;
 	/* local datagram socket output to be implemented */
-	hex_dump_output(pdu, pdu_len);
+	if (trx_socket)
+		send_pdu_via_socket(pdu, pdu_len);
+	else
+		hex_dump_output(pdu, pdu_len);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/smpp-send/sock_send.c	Sat Aug 05 12:52:33 2023 -0800
@@ -0,0 +1,36 @@
+/*
+ * This module implements local datagram socket transmission of the constructed
+ * submit_sm PDU to our smpp-trx-sa daemon process.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+extern char *trx_socket;
+
+void
+send_pdu_via_socket(pdu, pdulen)
+	u_char *pdu;
+	unsigned pdulen;
+{
+	struct sockaddr_un sa;
+	unsigned sa_len;
+	int lsock, rc;
+
+	lsock = socket(AF_UNIX, SOCK_DGRAM, 0);
+	if (lsock < 0) {
+		perror("socket(AF_UNIX, SOCK_DGRAM, 0)");
+		exit(1);
+	}
+	fill_sockaddr_un(trx_socket, &sa, &sa_len);
+	rc = sendto(lsock, pdu, pdulen, 0, (struct sockaddr *) &sa, sa_len);
+	if (rc != pdulen) {
+		perror("send via local socket");
+		exit(1);
+	}
+	close(lsock);
+}