forked from ossobv/rtpsniff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtpsniff.h
139 lines (117 loc) · 6.41 KB
/
rtpsniff.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef INCLUDED_RTPSNIFF_H
#define INCLUDED_RTPSNIFF_H
/* vim: set ts=8 sw=4 sts=4 et: */
/*======================================================================
Copyright (C) 2008,2009,2014 OSSO B.V. <[email protected]>
This file is part of RTPSniff.
RTPSniff 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 3 of the License, or (at your
option) any later version.
RTPSniff 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 RTPSniff. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#include "uthash.h"
#include <inttypes.h>
#include <pcap.h>
#include <sys/types.h>
/*----------------------------------------------------------------------------*
| Program: rtpsniff |
| |
| The program is divided in a couple of modules that could be replaced by |
| different implementations. These modules must implement the functions |
| listed below. For every module a remark is made about which other module |
| functions it calls. |
| |
| The `*_help` functions provide implementation specific information. |
| Everything is assumed to be single-threaded and non-reentrant, except for |
| the timer that uses a thread to call `out_write` at a specified |
| interval. |
*----------------------------------------------------------------------------*/
struct rtpstat_t;
struct memory_t {
/* Use two memory buffers. */
struct rtpstat_t *rtphash[2];
/* Of which the Nth is active (written to). */
volatile int active;
/* After a signal, a switch is requested. */
volatile int request_switch;
};
struct rtpstat_t {
/* Part of hash */
uint32_t src_ip;
uint32_t dst_ip;
uint16_t src_port;
uint16_t dst_port;
uint32_t ssrc;
/* Contents */
uint32_t packets; /* +1 for every packet seen */
/*uint32_t timestamp? */
uint16_t seq;
uint16_t gaps; /* +1 for every increment gap */
uint16_t missed; /* +N for every missed increment (probably lost) */
uint16_t late; /* +1 for every out-of-order sequence */
uint16_t jumps; /* +1 for every large jump */
UT_hash_handle hh;
};
#define HASH_FIRST src_ip
#define HASH_SIZE(rtpstat) \
((char*)&((rtpstat).packets) - (char*)&((rtpstat).HASH_FIRST))
/*----------------------------------------------------------------------------*
| Module: rtpsniff |
| |
| Does the user interface. |
| |
| Calls: any of the functions listed here (from the main thread) |
*----------------------------------------------------------------------------*/
void rtpsniff_help(); /* show help */
/*----------------------------------------------------------------------------*
| Module: sniff |
| |
| Does the sniffing of the ethernet packets. As `sniff_loop` is the main |
| (foreground) loop, it listens for the quit signals: HUP, INT, TERM and |
| QUIT. |
| |
| Calls: (nothing.. manually adds to the memory) |
*----------------------------------------------------------------------------*/
void sniff_help(); /* show info */
int sniff_snaplen();
void sniff_loop(pcap_t *handle, struct memory_t *memory);
void sniff_release(struct rtpstat_t **memory);
/*----------------------------------------------------------------------------*
| Module: storage |
| |
| Stores the packet/byte count averages. You must call `out_open` and |
| `out_close` while single-threaded. |
| |
| Calls: (nothing) |
*----------------------------------------------------------------------------*/
void out_help();
int out_open();
void out_close();
void out_write(uint32_t unixtime_begin, uint32_t interval,
struct rtpstat_t *rtphash);
/*----------------------------------------------------------------------------*
| Module: timer |
| |
| Runs a thread that wakes up every interval. When waking up, it raises |
| SIGUSR1 to signal `sniff_loop` to begin writing to a different buffer so |
| it can safely give the current buffer to `out_write` for processing. |
| |
| Calls: `out_write` (from a thread) |
*----------------------------------------------------------------------------*/
void timer_help();
int timer_loop_bg(struct memory_t *memory);
void timer_loop_stop();
/*----------------------------------------------------------------------------*
| Utility functions that are not module specific. |
*----------------------------------------------------------------------------*/
int util_signal_set(int signum, void (*handler)(int));
#if !(_BSD_SOURCE || _XOPEN_SOURCE >= 500)
int usleep(unsigned usecs);
#endif /* !(_BSD_SOURCE || _XOPEN_SOURCE >= 500) */
#endif /* INCLUDED_RTPSNIFF_H */