-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstream.c
More file actions
79 lines (74 loc) · 2.79 KB
/
Copy pathstream.c
File metadata and controls
79 lines (74 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (C) 2015-2016 Julien Chavanton
*
* This file is part of Disruptor, a network impairment server.
*
* Disruptor is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* Disruptor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
#include <string.h>
#include "include/scenario.h"
#include "include/disruptor.h"
#include "include/stream.h"
struct disrupt_stream_s * stream_get(struct disrupt_stream_s * stream, uint32_t src_ip, uint16_t src_port, uint32_t dst_ip, uint16_t dst_port){
while(stream != NULL){
if( stream->socket.src_ip==src_ip && stream->socket.src_port==src_port && stream->socket.src_ip==src_ip && stream->socket.dst_port==dst_port){
return stream;
}
if(stream->next==NULL)
return NULL;
stream=stream->next;
}
return NULL;
}
struct disrupt_stream_s * stream_add(struct disrupt_stream_s * stream, uint32_t src_ip, uint16_t src_port, uint32_t dst_ip, uint16_t dst_port){
struct disrupt_stream_s * stream_new;
stream_new = (struct disrupt_stream_s *) malloc(sizeof(struct disrupt_stream_s));
memset(stream_new, 0, sizeof(struct disrupt_stream_s));
if(!stream_new){
log_error("stream_add: can not allocate memory\n");
return NULL;
}
/* initialize the stream */
struct timeval t;
gettimeofday(&t,NULL);
stream_new->start = t;
stream_new->socket.src_ip = src_ip;
stream_new->socket.src_port = src_port;
stream_new->socket.dst_ip = dst_ip;
stream_new->socket.dst_port = dst_port;
if(!stream) {
stream_new->id=1;
return stream_new;
}
stream->previous=stream_new;
stream_new->next=stream;
stream_new->id=stream_new->next->id+1;
return stream_new;
}
void stream_print(struct disrupt_stream_s * stream){
while(stream != NULL){
log_info("active stream[%d]: src ip:port[%d.%d.%d.%d:%d] dest ip:port[%d.%d.%d.%d:%d] start[%"PRId64"]", stream->id,
(stream->socket.src_ip)&0xFF,(stream->socket.src_ip>>8)&0xFF,(stream->socket.src_ip>>16)&0xFF,(stream->socket.src_ip>>24)&0xFF,
ntohs(stream->socket.src_port),
(stream->socket.dst_ip)&0xFF,(stream->socket.dst_ip>>8)&0xFF,(stream->socket.dst_ip>>16)&0xFF,(stream->socket.dst_ip>>24)&0xFF,
ntohs(stream->socket.dst_port),
(int64_t)stream->start.tv_sec
);
if(stream->next==NULL)
return;
stream=stream->next;
}
}