summaryrefslogtreecommitdiffstats
path: root/net_rx.c
diff options
context:
space:
mode:
authorJames <31272717+gpd-pocket-hacker@users.noreply.github.com>2020-10-31 18:25:41 +0000
committerJames <31272717+gpd-pocket-hacker@users.noreply.github.com>2020-10-31 19:32:32 +0000
commitc3606b0b60e37f5af9e7b71a9e19c3f8097b4a61 (patch)
tree9866aac3d1c354fb6f042d640b4fa470ee8809d3 /net_rx.c
parent232cf21c35c79458969fd661d18ca779c5418c2e (diff)
downloadgalaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.gz
galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.tar.bz2
galaxy_tools-c3606b0b60e37f5af9e7b71a9e19c3f8097b4a61.zip
split out rx and add syslog support
Diffstat (limited to 'net_rx.c')
-rw-r--r--net_rx.c70
1 files changed, 14 insertions, 56 deletions
diff --git a/net_rx.c b/net_rx.c
index a3d95e4..1ea0993 100644
--- a/net_rx.c
+++ b/net_rx.c
@@ -5,68 +5,18 @@
#include <termios.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <syslog.h>
#include "util.h"
#include "sia.h"
-
-
-
-
-void msg (char *account, char *event, char *ascii)
-{
- printf ("%s %64s %s\n", account, event, ascii);
-}
-
-
-static int new_block (int fd, SIA_Block *b)
-{
- static int have_ascii_messages = 0; /*SIA level 3 doesn't have ascii, SIA level 4 does */
-
- static char account[SIA_MAX_DATA_LENGTH + 1];
- static char event[SIA_MAX_DATA_LENGTH + 1];
- static char ascii[SIA_MAX_DATA_LENGTH + 1];
-
- unsigned len = sia_data_length (b);
-
- if (sia_ack_if_needed (fd, b))
- return -1;
-
- switch (b->function) {
- case SIA_FN_ACCOUNT_ID:
- memcpy (account, b->data, len);
- account[len] = 0;
- break;
-
- case SIA_FN_NEW_EVENT:
- case SIA_FN_OLD_EVENT:
- memcpy (event, b->data, len);
- event[len] = 0;
-
- if (!have_ascii_messages) msg (account, event, "");
-
- break;
-
- case SIA_FN_ASCII:
- have_ascii_messages = 1;
- memcpy (ascii, b->data, len);
- ascii[len] = 0;
-
- msg (account, event, ascii);
- break;
- }
-
- return 0;
-}
-
-static void periodic_task (void)
-{
-}
+extern int new_block (int fd, SIA_Block *b, int log);
+extern void periodic_task (void);
static int usage (const char *name)
{
fprintf (stderr, "Usage:\n");
- fprintf (stderr, "%s [ -p listen_port ]\n\n", name);
+ fprintf (stderr, "%s [ -l ] [ -p listen_port ]\n\n", name);
fprintf (stderr, "listen_port defaults to 10002\n");
return 1;
@@ -83,22 +33,30 @@ int main (int argc, char *argv[])
int afd = -1;
SIA_Block b;
struct timeval tv = {0};
+ int log = 0;
unsigned char buf[SIA_MAX_BLOCK_LENGTH];
unsigned ptr = 0;
- while ((opt = getopt (argc, argv, "p:")) != -1) {
+ while ((opt = getopt (argc, argv, "p:l")) != -1) {
switch (opt) {
case 'p':
port = atoi (optarg);
break;
+ case 'l':
+ log++;
+ break;
+
default: /* '?' */
return usage (argv[0]);
}
}
+ if (log)
+ openlog ("net_rx", 0, LOG_USER);
+
fd = open_tcp_server (port);
if (fd < 0) {
@@ -159,7 +117,7 @@ int main (int argc, char *argv[])
break;
default: /*Valid block */
- new_block (afd, &b);
+ new_block (afd, &b, log);
ptr = 0;
break;
}