Subversion Repositories shark

Rev

Rev 365 | 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
 
71
  if (net_init(&m) == 1) {
72
    return 0;
73
  } else {
74
    return -1;
75
  }
76
 
365 giacomo 77
  ip_str2addr(local_ip,&(local.s_addr));
78
  local.s_port = TRACER_PORT;
79
  socket = udp_bind(&local, NULL);
80
 
81
  ip_str2addr(target_ip,&(target.s_addr));
82
  target.s_port = TRACER_PORT;
83
 
84
  TracerOutputType = TRACER_UDP_OUTPUT;
85
  TracerUDPInit = 1;
86
 
87
  ll_frestore(f);
88
 
89
  return 0;
90
 
91
}
92
 
364 giacomo 93
int send_udp_event(void *p, int size) {
94
 
95
  static BYTE pkt[UDP_MAXSIZE];
96
  static BYTE *current = pkt;
97
  static int total_pkt_size = 0;
98
  static int events_number = 0;
99
  static int packet_number = 0;
100
 
101
  struct tracer_udp_header head = {"TRACER-V1.0",0,0,0};
102
  struct tracer_udp_header *phead = (struct tracer_udp_header *)(pkt);
103
 
104
  if (total_pkt_size + size < UDP_MAXSIZE) {
105
 
106
    if (total_pkt_size == 0) {
107
 
108
      memcpy(pkt,&head,sizeof(struct tracer_udp_header));
109
 
110
      current = pkt;
111
      current += sizeof(struct tracer_udp_header);
112
 
113
      total_pkt_size += sizeof(struct tracer_udp_header);
114
      phead->total_size = total_pkt_size;
115
 
116
      packet_number++;
117
      phead->pkt_number = packet_number;
118
 
119
    }
120
 
121
    events_number++;
122
    phead->number_of_events = events_number;
123
 
124
    total_pkt_size += size;
125
    phead->total_size = total_pkt_size;
126
 
127
    //Copy the event
128
    memcpy(current,p,size);
129
    current += size;
130
 
131
    return 0;
132
 
133
  } else {
134
 
365 giacomo 135
    udp_sendto(socket, pkt, total_pkt_size, &target);
364 giacomo 136
 
137
    events_number = 0;
138
    total_pkt_size = 0;
139
    current = pkt;
140
 
141
    send_udp_event(p,size);
142
 
365 giacomo 143
    return 0;    
364 giacomo 144
 
145
  }
146
 
147
  return -1;
148
 
149
}