tests: add regression tests for Follow TCP Stream
[metze/wireshark/wip.git] / ui / rtp_stream_id.c
1 /* rtp_stream_id.c
2  * RTP stream id functions for Wireshark
3  *
4  * Copyright 2003, Alcatel Business Systems
5  * By Lars Ruoff <lars.ruoff@gmx.net>
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * SPDX-License-Identifier: GPL-2.0-or-later
12  */
13
14 #include "config.h"
15
16 #include <stdlib.h>
17 #include <string.h>
18
19 #include "file.h"
20
21 #include "ui/rtp_stream_id.h"
22 #include "epan/dissectors/packet-rtp.h"
23
24 /****************************************************************************/
25 /* rtpstream id functions */
26 /****************************************************************************/
27
28 /****************************************************************************/
29 /* deep copy of id */
30 void rtpstream_id_copy(const rtpstream_id_t *src, rtpstream_id_t *dest)
31 {
32     copy_address(&(dest->src_addr), &(src->src_addr));
33     dest->src_port=src->src_port;
34     copy_address(&(dest->dst_addr), &(src->dst_addr));
35     dest->dst_port=src->dst_port;
36     dest->ssrc=src->ssrc;
37 }
38
39 /****************************************************************************/
40 /* deep copy of id from packet_info */
41 void rtpstream_id_copy_pinfo(const packet_info *pinfo, rtpstream_id_t *dest, gboolean swap_src_dst)
42 {
43         if (!swap_src_dst)
44         {
45                 copy_address(&(dest->src_addr), &(pinfo->src));
46                 dest->src_port=pinfo->srcport;
47                 copy_address(&(dest->dst_addr), &(pinfo->dst));
48                 dest->dst_port=pinfo->destport;
49         }
50         else
51         {
52                 copy_address(&(dest->src_addr), &(pinfo->dst));
53                 dest->src_port=pinfo->destport;
54                 copy_address(&(dest->dst_addr), &(pinfo->src));
55                 dest->dst_port=pinfo->srcport;
56         }
57 }
58
59 /****************************************************************************/
60 /* free memory allocated for id */
61 void rtpstream_id_free(rtpstream_id_t *id)
62 {
63         free_address(&(id->src_addr));
64         free_address(&(id->dst_addr));
65         memset(id, 0, sizeof(*id));
66 }
67
68 /****************************************************************************/
69 /* compare two ids by flags */
70 gboolean rtpstream_id_equal(const rtpstream_id_t *id1, const rtpstream_id_t *id2, guint flags)
71 {
72         if (addresses_equal(&(id1->src_addr), &(id2->src_addr))
73                 && id1->src_port == id2->src_port
74                 && addresses_equal(&(id1->dst_addr), &(id2->dst_addr))
75                 && id1->dst_port == id2->dst_port)
76         {
77                 gboolean equal = TRUE;
78
79                 if ((flags & RTPSTREAM_ID_EQUAL_SSRC)
80                         && id1->ssrc != id2->ssrc)
81                 {
82                         equal = FALSE;
83                 }
84
85                 return equal;
86         }
87
88         return FALSE;
89 }
90
91 /****************************************************************************/
92 /* compare two ids, one in pinfo */
93 gboolean rtpstream_id_equal_pinfo_rtp_info(const rtpstream_id_t *id, const packet_info *pinfo, const struct _rtp_info *rtp_info)
94 {
95         if (addresses_equal(&(id->src_addr), &(pinfo->src))
96                 && id->src_port == pinfo->srcport
97                 && addresses_equal(&(id->dst_addr), &(pinfo->dst))
98                 && id->dst_port == pinfo->destport
99                 && id->ssrc == rtp_info->info_sync_src)
100         {
101                 return TRUE;
102         }
103
104         return FALSE;
105 }
106
107 /*
108  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
109  *
110  * Local variables:
111  * c-basic-offset: 4
112  * tab-width: 8
113  * indent-tabs-mode: nil
114  * End:
115  *
116  * vi: set shiftwidth=4 tabstop=8 expandtab:
117  * :indentSize=4:tabSize=8:noTabs=true:
118  */