comparison rvinterf/lowlevel/pktfwd.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This rvinterf module handles the forwarding of target->host packets
3 * to clients connected via the local socket interface.
4 */
5
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <strings.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include "../include/pktmux.h"
13 #include "../include/localsock.h"
14 #include "client.h"
15
16 extern u_char rxpkt[];
17 extern size_t rxpkt_len;
18
19 extern struct client *client_head;
20
21 forward_pkt_to_client(cli)
22 struct client *cli;
23 {
24 int len1;
25 u_char hdr[3];
26
27 len1 = rxpkt_len + 1;
28 hdr[0] = len1 >> 8;
29 hdr[1] = len1 & 0xFF;
30 hdr[2] = RVI2CLI_PKT_FROM_TARGET;
31 write(cli->fd, hdr, 3);
32 write(cli->fd, rxpkt, rxpkt_len);
33 }
34
35 forward_rv_trace()
36 {
37 u32 useid;
38 struct client *cli;
39 int i, match;
40
41 useid = rxpkt[1] << 24 | rxpkt[2] << 16 | rxpkt[3] << 8 | rxpkt[4];
42 for (cli = client_head; cli; cli = cli->next) {
43 match = 0;
44 for (i = 0; i < cli->int_rvt_count; i++)
45 if ((useid & cli->int_rvt_mask[i]) ==
46 cli->int_rvt_match[i]) {
47 match = 1;
48 break;
49 }
50 if (match)
51 forward_pkt_to_client(cli);
52 }
53 }
54
55 forward_nonrvt_pkt()
56 {
57 struct client *cli;
58
59 for (cli = client_head; cli; cli = cli->next)
60 if (cli->int_proto[rxpkt[0] - 0x12])
61 forward_pkt_to_client(cli);
62 }