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
21 #include "ui/rtp_stream_id.h"
22 #include "epan/dissectors/packet-rtp.h"
24 /****************************************************************************/
25 /* rtpstream id functions */
26 /****************************************************************************/
28 /****************************************************************************/
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
;
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
)
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
;
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
)
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
;
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
)
93 if (!id
) { return 0; }
95 /* SRC PORT | DST_PORT */
99 hash
^= id
->src_port
| id
->dst_port
<< 16;
101 hash
= add_address_to_hash(hash
, &id
->src_addr
);
102 hash
= add_address_to_hash(hash
, &id
->dst_addr
);
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
)
118 if ((flags
& RTPSTREAM_ID_EQUAL_SSRC
)
119 && id1
->ssrc
!= id2
->ssrc
)
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
)
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
)
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
)
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
)
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
)
176 if (!pinfo
|| !rtp_info
) { return 0; }
178 /* SRC PORT | DST_PORT */
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
);