Rev 366 | Rev 369 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
364 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * Copyright (C) 2002 Paolo Gai |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | * |
||
36 | */ |
||
37 | |||
38 | #include <ll/sys/types.h> |
||
39 | #include <stdlib.h> |
||
365 | giacomo | 40 | #include <tracer.h> |
364 | giacomo | 41 | |
365 | giacomo | 42 | #include <drivers/udpip.h> |
43 | |||
364 | giacomo | 44 | #define UDP_MAXSIZE 1400 |
365 | giacomo | 45 | #define TRACER_PORT 100 |
364 | giacomo | 46 | |
365 | giacomo | 47 | int TracerUDPInit = 0; |
48 | UDP_ADDR target,local; |
||
49 | int socket; |
||
50 | |||
51 | extern int TracerOutputType; |
||
52 | |||
364 | giacomo | 53 | struct tracer_udp_header { |
54 | char id[12]; |
||
55 | unsigned int pkt_number; |
||
56 | unsigned int number_of_events; |
||
57 | unsigned int total_size; |
||
58 | }; |
||
59 | |||
366 | giacomo | 60 | int init_udp_tracer(char *local_ip, char *target_ip) { |
365 | giacomo | 61 | |
62 | SYS_FLAGS f; |
||
366 | giacomo | 63 | |
64 | struct net_model m = net_base; |
||
365 | giacomo | 65 | |
66 | f = ll_fsave(); |
||
67 | |||
366 | giacomo | 68 | net_setmode(m, TXTASK); |
69 | net_setudpip(m, local_ip, "255.255.255.255"); |
||
70 | |||
367 | giacomo | 71 | if (net_init(&m) != 1) |
366 | giacomo | 72 | return -1; |
73 | |||
365 | giacomo | 74 | ip_str2addr(local_ip,&(local.s_addr)); |
75 | local.s_port = TRACER_PORT; |
||
76 | socket = udp_bind(&local, NULL); |
||
77 | |||
78 | ip_str2addr(target_ip,&(target.s_addr)); |
||
79 | target.s_port = TRACER_PORT; |
||
80 | |||
81 | TracerOutputType = TRACER_UDP_OUTPUT; |
||
82 | TracerUDPInit = 1; |
||
83 | |||
84 | ll_frestore(f); |
||
85 | |||
86 | return 0; |
||
87 | |||
88 | } |
||
89 | |||
364 | giacomo | 90 | int send_udp_event(void *p, int size) { |
91 | |||
92 | static BYTE pkt[UDP_MAXSIZE]; |
||
93 | static BYTE *current = pkt; |
||
94 | static int total_pkt_size = 0; |
||
95 | static int events_number = 0; |
||
96 | static int packet_number = 0; |
||
97 | |||
98 | struct tracer_udp_header head = {"TRACER-V1.0",0,0,0}; |
||
99 | struct tracer_udp_header *phead = (struct tracer_udp_header *)(pkt); |
||
100 | |||
101 | if (total_pkt_size + size < UDP_MAXSIZE) { |
||
102 | |||
103 | if (total_pkt_size == 0) { |
||
104 | |||
105 | memcpy(pkt,&head,sizeof(struct tracer_udp_header)); |
||
106 | |||
107 | current = pkt; |
||
108 | current += sizeof(struct tracer_udp_header); |
||
109 | |||
110 | total_pkt_size += sizeof(struct tracer_udp_header); |
||
111 | phead->total_size = total_pkt_size; |
||
112 | |||
113 | packet_number++; |
||
114 | phead->pkt_number = packet_number; |
||
115 | |||
116 | } |
||
117 | |||
118 | events_number++; |
||
119 | phead->number_of_events = events_number; |
||
120 | |||
121 | total_pkt_size += size; |
||
122 | phead->total_size = total_pkt_size; |
||
123 | |||
124 | //Copy the event |
||
125 | memcpy(current,p,size); |
||
126 | current += size; |
||
127 | |||
128 | return 0; |
||
129 | |||
130 | } else { |
||
131 | |||
365 | giacomo | 132 | udp_sendto(socket, pkt, total_pkt_size, &target); |
364 | giacomo | 133 | |
134 | events_number = 0; |
||
135 | total_pkt_size = 0; |
||
136 | current = pkt; |
||
137 | |||
138 | send_udp_event(p,size); |
||
139 | |||
365 | giacomo | 140 | return 0; |
364 | giacomo | 141 | |
142 | } |
||
143 | |||
144 | return -1; |
||
145 | |||
146 | } |