mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 09:10:36 +00:00
sdp: add method to check for multicast addresses
Expose a previously internal method to check for multicast addresses. See #634093
This commit is contained in:
parent
36c9ba990a
commit
e0d4a48ae7
3 changed files with 45 additions and 18 deletions
|
@ -322,33 +322,56 @@ gst_sdp_message_free (GstSDPMessage * msg)
|
||||||
return GST_SDP_OK;
|
return GST_SDP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
/**
|
||||||
is_multicast_address (const gchar * host_name, guint * family)
|
* gst_sdp_address_is_multicast:
|
||||||
|
* @nettype: a network type
|
||||||
|
* @addrtype: an address type
|
||||||
|
* @addr: an address
|
||||||
|
*
|
||||||
|
* Check if the given @addr is a multicast address.
|
||||||
|
*
|
||||||
|
* Returns: TRUE when @addr is multicast.
|
||||||
|
*
|
||||||
|
* Since: 0.10.32
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_sdp_address_is_multicast (const gchar * nettype, const gchar * addrtype,
|
||||||
|
const gchar * addr)
|
||||||
{
|
{
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
struct addrinfo *ai;
|
struct addrinfo *ai;
|
||||||
struct addrinfo *res;
|
struct addrinfo *res;
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
|
|
||||||
|
g_return_val_if_fail (addr, FALSE);
|
||||||
|
|
||||||
|
/* we only support IN */
|
||||||
|
if (nettype && strcmp (nettype, "IN") != 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
memset (&hints, 0, sizeof (hints));
|
memset (&hints, 0, sizeof (hints));
|
||||||
hints.ai_socktype = SOCK_DGRAM;
|
hints.ai_socktype = SOCK_DGRAM;
|
||||||
|
|
||||||
g_return_val_if_fail (host_name, FALSE);
|
/* set the address type as a hint */
|
||||||
|
if (addrtype) {
|
||||||
|
if (!strcmp (addrtype, "IP4"))
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
else if (!strcmp (addrtype, "IP6"))
|
||||||
|
hints.ai_family = AF_INET6;
|
||||||
|
}
|
||||||
|
|
||||||
if (getaddrinfo (host_name, NULL, &hints, &res) < 0)
|
if (getaddrinfo (addr, NULL, &hints, &res) < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (ai = res; !ret && ai; ai = ai->ai_next) {
|
for (ai = res; !ret && ai; ai = ai->ai_next) {
|
||||||
if (ai->ai_family == AF_INET)
|
if (ai->ai_family == AF_INET)
|
||||||
ret =
|
ret =
|
||||||
IN_MULTICAST (ntohl (((struct sockaddr_in *) ai->ai_addr)->sin_addr.
|
IN_MULTICAST (ntohl (((struct sockaddr_in *) ai->ai_addr)->
|
||||||
s_addr));
|
sin_addr.s_addr));
|
||||||
else
|
else
|
||||||
ret =
|
ret =
|
||||||
IN6_IS_ADDR_MULTICAST (&((struct sockaddr_in6 *) ai->ai_addr)->
|
IN6_IS_ADDR_MULTICAST (&((struct sockaddr_in6 *) ai->
|
||||||
sin6_addr);
|
ai_addr)->sin6_addr);
|
||||||
if (ret && family)
|
|
||||||
*family = ai->ai_family;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo (res);
|
freeaddrinfo (res);
|
||||||
|
@ -408,12 +431,12 @@ gst_sdp_message_as_text (const GstSDPMessage * msg)
|
||||||
|
|
||||||
if (msg->connection.nettype && msg->connection.addrtype &&
|
if (msg->connection.nettype && msg->connection.addrtype &&
|
||||||
msg->connection.address) {
|
msg->connection.address) {
|
||||||
guint family;
|
|
||||||
|
|
||||||
g_string_append_printf (lines, "c=%s %s %s", msg->connection.nettype,
|
g_string_append_printf (lines, "c=%s %s %s", msg->connection.nettype,
|
||||||
msg->connection.addrtype, msg->connection.address);
|
msg->connection.addrtype, msg->connection.address);
|
||||||
if (is_multicast_address (msg->connection.address, &family)) {
|
if (gst_sdp_address_is_multicast (msg->connection.nettype,
|
||||||
if (family == AF_INET)
|
msg->connection.addrtype, msg->connection.address)) {
|
||||||
|
/* only add ttl for IP4 */
|
||||||
|
if (strcmp (msg->connection.addrtype, "IP4") == 0)
|
||||||
g_string_append_printf (lines, "/%u", msg->connection.ttl);
|
g_string_append_printf (lines, "/%u", msg->connection.ttl);
|
||||||
if (msg->connection.addr_number > 1)
|
if (msg->connection.addr_number > 1)
|
||||||
g_string_append_printf (lines, "/%u", msg->connection.addr_number);
|
g_string_append_printf (lines, "/%u", msg->connection.addr_number);
|
||||||
|
@ -1341,12 +1364,12 @@ gst_sdp_media_as_text (const GstSDPMedia * media)
|
||||||
const GstSDPConnection *conn = gst_sdp_media_get_connection (media, i);
|
const GstSDPConnection *conn = gst_sdp_media_get_connection (media, i);
|
||||||
|
|
||||||
if (conn->nettype && conn->addrtype && conn->address) {
|
if (conn->nettype && conn->addrtype && conn->address) {
|
||||||
guint family;
|
|
||||||
|
|
||||||
g_string_append_printf (lines, "c=%s %s %s", conn->nettype,
|
g_string_append_printf (lines, "c=%s %s %s", conn->nettype,
|
||||||
conn->addrtype, conn->address);
|
conn->addrtype, conn->address);
|
||||||
if (is_multicast_address (conn->address, &family)) {
|
if (gst_sdp_address_is_multicast (conn->nettype, conn->addrtype,
|
||||||
if (family == AF_INET)
|
conn->address)) {
|
||||||
|
/* only add ttl for IP4 multicast */
|
||||||
|
if (strcmp (conn->addrtype, "IP4") == 0)
|
||||||
g_string_append_printf (lines, "/%u", conn->ttl);
|
g_string_append_printf (lines, "/%u", conn->ttl);
|
||||||
if (conn->addr_number > 1)
|
if (conn->addr_number > 1)
|
||||||
g_string_append_printf (lines, "/%u", conn->addr_number);
|
g_string_append_printf (lines, "/%u", conn->addr_number);
|
||||||
|
|
|
@ -286,6 +286,9 @@ gchar* gst_sdp_message_as_text (const GstSDPMessage
|
||||||
GstSDPResult gst_sdp_message_parse_uri (const gchar *uri, GstSDPMessage *msg);
|
GstSDPResult gst_sdp_message_parse_uri (const gchar *uri, GstSDPMessage *msg);
|
||||||
gchar* gst_sdp_message_as_uri (const gchar *scheme, const GstSDPMessage *msg);
|
gchar* gst_sdp_message_as_uri (const gchar *scheme, const GstSDPMessage *msg);
|
||||||
|
|
||||||
|
/* utils */
|
||||||
|
gboolean gst_sdp_address_is_multicast (const gchar *nettype, const gchar *addrtype,
|
||||||
|
const gchar *addr);
|
||||||
/* v=.. */
|
/* v=.. */
|
||||||
const gchar* gst_sdp_message_get_version (const GstSDPMessage *msg);
|
const gchar* gst_sdp_message_get_version (const GstSDPMessage *msg);
|
||||||
GstSDPResult gst_sdp_message_set_version (GstSDPMessage *msg, const gchar *version);
|
GstSDPResult gst_sdp_message_set_version (GstSDPMessage *msg, const gchar *version);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
EXPORTS
|
EXPORTS
|
||||||
|
gst_sdp_address_is_multicast
|
||||||
gst_sdp_media_add_attribute
|
gst_sdp_media_add_attribute
|
||||||
gst_sdp_media_add_bandwidth
|
gst_sdp_media_add_bandwidth
|
||||||
gst_sdp_media_add_connection
|
gst_sdp_media_add_connection
|
||||||
|
|
Loading…
Reference in a new issue