Blame libs/gst/net/gstnetutils.c

Packit a6ee4b
/* GStreamer
Packit a6ee4b
 * Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
Packit a6ee4b
 * Copyright (C) 2017 Robert Rosengren <robertr@axis.com>
Packit a6ee4b
 *
Packit a6ee4b
 * This library is free software; you can redistribute it and/or
Packit a6ee4b
 * modify it under the terms of the GNU Library General Public
Packit a6ee4b
 * License as published by the Free Software Foundation; either
Packit a6ee4b
 * version 2 of the License, or (at your option) any later version.
Packit a6ee4b
 *
Packit a6ee4b
 * This library is distributed in the hope that it will be useful,
Packit a6ee4b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a6ee4b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a6ee4b
 * Library General Public License for more details.
Packit a6ee4b
 *
Packit a6ee4b
 * You should have received a copy of the GNU Library General Public
Packit a6ee4b
 * License along with this library; if not, write to the
Packit a6ee4b
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit a6ee4b
 * Boston, MA 02110-1301, USA.
Packit a6ee4b
 */
Packit a6ee4b
Packit a6ee4b
#ifdef HAVE_CONFIG_H
Packit a6ee4b
#include "config.h"
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#include "gstnetutils.h"
Packit a6ee4b
#include <gst/gstinfo.h>
Packit a6ee4b
#include <errno.h>
Packit a6ee4b
Packit a6ee4b
#ifdef HAVE_SYS_SOCKET_H
Packit a6ee4b
#include <sys/socket.h>
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
#ifndef G_OS_WIN32
Packit a6ee4b
#include <netinet/in.h>
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
/**
Packit a6ee4b
 * gst_net_time_packet_util_set_dscp:
Packit a6ee4b
 * @socket: Socket to configure
Packit a6ee4b
 * @qos_dscp: QoS DSCP value
Packit a6ee4b
 *
Packit a6ee4b
 * Configures IP_TOS value of socket, i.e. sets QoS DSCP.
Packit a6ee4b
 *
Packit a6ee4b
 * Returns: TRUE if successful, FALSE in case an error occurred.
Packit a6ee4b
 */
Packit a6ee4b
gboolean
Packit a6ee4b
gst_net_utils_set_socket_dscp (GSocket * socket, gint qos_dscp)
Packit a6ee4b
{
Packit a6ee4b
  gboolean ret = FALSE;
Packit a6ee4b
Packit a6ee4b
#ifdef IP_TOS
Packit a6ee4b
  gint tos, fd;
Packit a6ee4b
  fd = g_socket_get_fd (socket);
Packit a6ee4b
Packit a6ee4b
  /* Extract and shift 6 bits of DSFIELD */
Packit a6ee4b
  tos = (qos_dscp & 0x3f) << 2;
Packit a6ee4b
Packit a6ee4b
  if (setsockopt (fd, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0) {
Packit a6ee4b
    GST_ERROR ("could not set TOS: %s", g_strerror (errno));
Packit a6ee4b
  } else {
Packit a6ee4b
    ret = TRUE;
Packit a6ee4b
  }
Packit a6ee4b
#endif
Packit a6ee4b
Packit a6ee4b
  return ret;
Packit a6ee4b
}