LATER... ei_kerberos_kdc_session_key ...
[wireshark-sm.git] / ui / rtp_stream_id.c
blob3c7c33ad11bd229de181294af2bdcdc8c9b51f03
1 /* rtp_stream_id.c
2 * RTP stream id functions for Wireshark
4 * Copyright 2003, Alcatel Business Systems
5 * By Lars Ruoff <lars.ruoff@gmx.net>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <stdlib.h>
17 #include <string.h>
19 #include "file.h"
21 #include "ui/rtp_stream_id.h"
22 #include "epan/dissectors/packet-rtp.h"
24 /****************************************************************************/
25 /* rtpstream id functions */
26 /****************************************************************************/
28 /****************************************************************************/
29 /* deep copy of id */
30 void rtpstream_id_copy(const rtpstream_id_t *src, rtpstream_id_t *dest)
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;
39 /****************************************************************************/
40 /* deep copy of id from packet_info */
41 void rtpstream_id_copy_pinfo(const packet_info *pinfo, rtpstream_id_t *dest, bool swap_src_dst)
43 if (!swap_src_dst)
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;
50 else
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;
59 /****************************************************************************/
60 /* shallow copy from packet_info to id */
61 void rtpstream_id_copy_pinfo_shallow(const packet_info *pinfo, rtpstream_id_t *dest, bool swap_src_dst)
63 if (!swap_src_dst)
65 copy_address_shallow(&(dest->src_addr), &(pinfo->src));
66 dest->src_port=pinfo->srcport;
67 copy_address_shallow(&(dest->dst_addr), &(pinfo->dst));
68 dest->dst_port=pinfo->destport;
70 else
72 copy_address_shallow(&(dest->src_addr), &(pinfo->dst));
73 dest->src_port=pinfo->destport;
74 copy_address_shallow(&(dest->dst_addr), &(pinfo->src));
75 dest->dst_port=pinfo->srcport;
78 /****************************************************************************/
79 /* free memory allocated for id */
80 void rtpstream_id_free(rtpstream_id_t *id)
82 free_address(&(id->src_addr));
83 free_address(&(id->dst_addr));
84 memset(id, 0, sizeof(*id));
87 /****************************************************************************/
88 /* convert rtpstream_id_t to hash */
89 unsigned rtpstream_id_to_hash(const rtpstream_id_t *id)
91 unsigned hash = 0;
93 if (!id) { return 0; }
94 /* XOR of: */
95 /* SRC PORT | DST_PORT */
96 /* SSRC */
97 /* SRC ADDR */
98 /* DST ADDR */
99 hash ^= id->src_port | id->dst_port << 16;
100 hash ^= id->ssrc;
101 hash = add_address_to_hash(hash, &id->src_addr);
102 hash = add_address_to_hash(hash, &id->dst_addr);
104 return hash;
107 /****************************************************************************/
108 /* compare two ids by flags */
109 bool rtpstream_id_equal(const rtpstream_id_t *id1, const rtpstream_id_t *id2, unsigned flags)
111 if (addresses_equal(&(id1->src_addr), &(id2->src_addr))
112 && id1->src_port == id2->src_port
113 && addresses_equal(&(id1->dst_addr), &(id2->dst_addr))
114 && id1->dst_port == id2->dst_port)
116 bool equal = true;
118 if ((flags & RTPSTREAM_ID_EQUAL_SSRC)
119 && id1->ssrc != id2->ssrc)
121 equal = false;
124 return equal;
127 return false;
130 /****************************************************************************/
131 /* compare an rtpstream id address and ports with pinfo */
132 bool rtpstream_id_equal_pinfo(const rtpstream_id_t *id, const packet_info *pinfo, bool swap_src_dst)
134 if (!swap_src_dst) {
135 if (addresses_equal(&(id->src_addr), &(pinfo->src))
136 && id->src_port == pinfo->srcport
137 && addresses_equal(&(id->dst_addr), &(pinfo->dst))
138 && id->dst_port == pinfo->destport)
140 return true;
142 } else {
143 if (addresses_equal(&(id->src_addr), &(pinfo->dst))
144 && id->src_port == pinfo->destport
145 && addresses_equal(&(id->dst_addr), &(pinfo->src))
146 && id->dst_port == pinfo->srcport)
148 return true;
152 return false;
154 /****************************************************************************/
155 /* compare two ids, one in pinfo */
156 bool rtpstream_id_equal_pinfo_rtp_info(const rtpstream_id_t *id, const packet_info *pinfo, const struct _rtp_info *rtp_info)
158 if (addresses_equal(&(id->src_addr), &(pinfo->src))
159 && id->src_port == pinfo->srcport
160 && addresses_equal(&(id->dst_addr), &(pinfo->dst))
161 && id->dst_port == pinfo->destport
162 && id->ssrc == rtp_info->info_sync_src)
164 return true;
167 return false;
170 /****************************************************************************/
171 /* convert packet_info and _rtp_info to hash */
172 unsigned pinfo_rtp_info_to_hash(const packet_info *pinfo, const struct _rtp_info *rtp_info)
174 unsigned hash = 0;
176 if (!pinfo || !rtp_info) { return 0; }
177 /* XOR of: */
178 /* SRC PORT | DST_PORT */
179 /* SSRC */
180 /* SRC ADDR */
181 /* DST ADDR */
182 hash ^= pinfo->srcport | pinfo->destport << 16;
183 hash ^= rtp_info->info_sync_src;
184 hash = add_address_to_hash(hash, &pinfo->src);
185 hash = add_address_to_hash(hash, &pinfo->dst);
187 return hash;