Subversion Repositories shark

Rev

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