diff rvinterf/lowlevel/localsock.c @ 178:7ab6b29e76bb

rvinterf: forwarding of Rx packets to clients implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 23 Nov 2013 22:15:16 +0000
parents fef035264dd4
children ec040f521cc2
line wrap: on
line diff
--- a/rvinterf/lowlevel/localsock.c	Sat Nov 23 20:15:02 2013 +0000
+++ b/rvinterf/lowlevel/localsock.c	Sat Nov 23 22:15:16 2013 +0000
@@ -110,6 +110,22 @@
 	return(0);
 }
 
+send_local_msg_to_client(cli, msg)
+	struct client *cli;
+	char *msg;
+{
+	int len, len1;
+	u_char hdr[3];
+
+	len = strlen(msg);
+	len1 = len + 1;
+	hdr[0] = len1 >> 8;
+	hdr[1] = len1 & 0xFF;
+	hdr[2] = RVI2CLI_LOCAL_CMD_RESP;
+	write(cli->fd, hdr, 3);
+	write(cli->fd, msg, len);
+}
+
 void
 handle_client_select(cli)
 	struct client *cli;
@@ -129,11 +145,12 @@
 	/* got the thing, process it */
 	if (cli->rx_state) {
 		prep_for_length_rx(cli);
-		/* process_msg_from_client(cli); */
+		process_msg_from_client(cli);
 	} else {
-		cli->rx_msglen = *(u_short *)cli->rx_buf;
+		cli->rx_msglen = cli->rx_buf[0] << 8 | cli->rx_buf[1];
 		if (cli->rx_msglen < 1 || cli->rx_msglen > LOCALSOCK_MAX_MSG) {
-			/* TODO: report invalid length to the client */
+			send_local_msg_to_client(cli,
+					"-Invalid length, closing socket");
 			goto close_socket;
 		}
 		prep_for_message_rx(cli);