Subversion Repositories shark

Rev

Rev 365 | Go to most recent revision | Details | 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>
40
 
41
#define UDP_MAXSIZE 1400
42
 
43
struct tracer_udp_header {
44
  char id[12];
45
  unsigned int pkt_number;
46
  unsigned int number_of_events;
47
  unsigned int total_size;
48
};
49
 
50
int send_udp_event(void *p, int size) {
51
 
52
  static BYTE pkt[UDP_MAXSIZE];
53
  static BYTE *current = pkt;
54
  static int total_pkt_size = 0;
55
  static int events_number = 0;
56
  static int packet_number = 0;
57
 
58
  struct tracer_udp_header head = {"TRACER-V1.0",0,0,0};
59
  struct tracer_udp_header *phead = (struct tracer_udp_header *)(pkt);
60
 
61
  int err;
62
 
63
  if (total_pkt_size + size < UDP_MAXSIZE) {
64
 
65
    if (total_pkt_size == 0) {
66
 
67
      memcpy(pkt,&head,sizeof(struct tracer_udp_header));
68
 
69
      current = pkt;
70
      current += sizeof(struct tracer_udp_header);
71
 
72
      total_pkt_size += sizeof(struct tracer_udp_header);
73
      phead->total_size = total_pkt_size;
74
 
75
      packet_number++;
76
      phead->pkt_number = packet_number;
77
 
78
    }
79
 
80
    events_number++;
81
    phead->number_of_events = events_number;
82
 
83
    total_pkt_size += size;
84
    phead->total_size = total_pkt_size;
85
 
86
    //Copy the event
87
    memcpy(current,p,size);
88
    current += size;
89
 
90
    return 0;
91
 
92
  } else {
93
 
94
    //err = udp_sentto();
95
 
96
    events_number = 0;
97
    total_pkt_size = 0;
98
    current = pkt;
99
 
100
    send_udp_event(p,size);
101
 
102
    return err;    
103
 
104
  }
105
 
106
  return -1;
107
 
108
}