comparison 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
comparison
equal deleted inserted replaced
177:fef035264dd4 178:7ab6b29e76bb
108 client_head = newcli; 108 client_head = newcli;
109 prep_for_length_rx(newcli); 109 prep_for_length_rx(newcli);
110 return(0); 110 return(0);
111 } 111 }
112 112
113 send_local_msg_to_client(cli, msg)
114 struct client *cli;
115 char *msg;
116 {
117 int len, len1;
118 u_char hdr[3];
119
120 len = strlen(msg);
121 len1 = len + 1;
122 hdr[0] = len1 >> 8;
123 hdr[1] = len1 & 0xFF;
124 hdr[2] = RVI2CLI_LOCAL_CMD_RESP;
125 write(cli->fd, hdr, 3);
126 write(cli->fd, msg, len);
127 }
128
113 void 129 void
114 handle_client_select(cli) 130 handle_client_select(cli)
115 struct client *cli; 131 struct client *cli;
116 { 132 {
117 int cc; 133 int cc;
127 if (cli->rx_left) 143 if (cli->rx_left)
128 return; 144 return;
129 /* got the thing, process it */ 145 /* got the thing, process it */
130 if (cli->rx_state) { 146 if (cli->rx_state) {
131 prep_for_length_rx(cli); 147 prep_for_length_rx(cli);
132 /* process_msg_from_client(cli); */ 148 process_msg_from_client(cli);
133 } else { 149 } else {
134 cli->rx_msglen = *(u_short *)cli->rx_buf; 150 cli->rx_msglen = cli->rx_buf[0] << 8 | cli->rx_buf[1];
135 if (cli->rx_msglen < 1 || cli->rx_msglen > LOCALSOCK_MAX_MSG) { 151 if (cli->rx_msglen < 1 || cli->rx_msglen > LOCALSOCK_MAX_MSG) {
136 /* TODO: report invalid length to the client */ 152 send_local_msg_to_client(cli,
153 "-Invalid length, closing socket");
137 goto close_socket; 154 goto close_socket;
138 } 155 }
139 prep_for_message_rx(cli); 156 prep_for_message_rx(cli);
140 } 157 }
141 } 158 }