+ * g_socket_get_ttl:
+ * @socket: a #GSocket.
+ *
+ * Gets the unicast time-to-live setting on @socket; see
+ * g_socket_set_ttl() for more details.
+ *
+ * Returns: the time-to-live setting on @socket
+ *
+ * Since: 2.32
+ */
+guint
+g_socket_get_ttl (GSocket *socket)
+{
+ GError *error = NULL;
+ gint value;
+
+ g_return_val_if_fail (G_IS_SOCKET (socket), 0);
+
+ if (socket->priv->family == G_SOCKET_FAMILY_IPV4)
+ {
+ g_socket_get_option (socket, IPPROTO_IP, IP_TTL,
+ &value, &error);
+ }
+ else if (socket->priv->family == G_SOCKET_FAMILY_IPV6)
+ {
+ g_socket_get_option (socket, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
+ &value, &error);
+ }
+ else
+ g_return_val_if_reached (0);
+
+ if (error)
+ {
+ g_warning ("error getting unicast ttl: %s", error->message);
+ g_error_free (error);
+ return 0;
+ }
+
+ return value;
+}
+
+/**
+ * g_socket_set_ttl:
+ * @socket: a #GSocket.
+ * @ttl: the time-to-live value for all unicast packets on @socket
+ *
+ * Sets the time-to-live for outgoing unicast packets on @socket.
+ * By default the platform-specific default value is used.
+ *
+ * Since: 2.32
+ */
+void
+g_socket_set_ttl (GSocket *socket,
+ guint ttl)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (G_IS_SOCKET (socket));
+
+ if (socket->priv->family == G_SOCKET_FAMILY_IPV4)
+ {
+ g_socket_set_option (socket, IPPROTO_IP, IP_TTL,
+ ttl, &error);
+ }
+ else if (socket->priv->family == G_SOCKET_FAMILY_IPV6)
+ {
+ g_socket_set_option (socket, IPPROTO_IP, IP_TTL,
+ ttl, NULL);
+ g_socket_set_option (socket, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
+ ttl, &error);
+ }
+ else
+ g_return_if_reached ();
+
+ if (error)
+ {
+ g_warning ("error setting unicast ttl: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ g_object_notify (G_OBJECT (socket), "ttl");
+}
+
+/**
+ * g_socket_get_broadcast:
+ * @socket: a #GSocket.
+ *
+ * Gets the broadcast setting on @socket; if %TRUE,
+ * it is possible to send packets to broadcast
+ * addresses.
+ *
+ * Returns: the broadcast setting on @socket
+ *
+ * Since: 2.32
+ */
+gboolean
+g_socket_get_broadcast (GSocket *socket)
+{
+ GError *error = NULL;
+ gint value;
+
+ g_return_val_if_fail (G_IS_SOCKET (socket), FALSE);
+
+ if (!g_socket_get_option (socket, SOL_SOCKET, SO_BROADCAST,
+ &value, &error))
+ {
+ g_warning ("error getting broadcast: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return !!value;
+}
+
+/**
+ * g_socket_set_broadcast:
+ * @socket: a #GSocket.
+ * @broadcast: whether @socket should allow sending to broadcast
+ * addresses
+ *
+ * Sets whether @socket should allow sending to broadcast addresses.
+ * This is %FALSE by default.
+ *
+ * Since: 2.32
+ */
+void
+g_socket_set_broadcast (GSocket *socket,
+ gboolean broadcast)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (G_IS_SOCKET (socket));
+
+ broadcast = !!broadcast;
+
+ if (!g_socket_set_option (socket, SOL_SOCKET, SO_BROADCAST,
+ broadcast, &error))
+ {
+ g_warning ("error setting broadcast: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ g_object_notify (G_OBJECT (socket), "broadcast");
+}
+
+/**
+ * g_socket_get_multicast_loopback:
+ * @socket: a #GSocket.
+ *
+ * Gets the multicast loopback setting on @socket; if %TRUE (the
+ * default), outgoing multicast packets will be looped back to
+ * multicast listeners on the same host.
+ *
+ * Returns: the multicast loopback setting on @socket
+ *
+ * Since: 2.32
+ */
+gboolean
+g_socket_get_multicast_loopback (GSocket *socket)
+{
+ GError *error = NULL;
+ gint value;
+
+ g_return_val_if_fail (G_IS_SOCKET (socket), FALSE);
+
+ if (socket->priv->family == G_SOCKET_FAMILY_IPV4)
+ {
+ g_socket_get_option (socket, IPPROTO_IP, IP_MULTICAST_LOOP,
+ &value, &error);
+ }
+ else if (socket->priv->family == G_SOCKET_FAMILY_IPV6)
+ {
+ g_socket_get_option (socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+ &value, &error);
+ }
+ else
+ g_return_val_if_reached (FALSE);
+
+ if (error)
+ {
+ g_warning ("error getting multicast loopback: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return !!value;
+}
+
+/**
+ * g_socket_set_multicast_loopback:
+ * @socket: a #GSocket.
+ * @loopback: whether @socket should receive messages sent to its
+ * multicast groups from the local host
+ *
+ * Sets whether outgoing multicast packets will be received by sockets
+ * listening on that multicast address on the same host. This is %TRUE
+ * by default.
+ *
+ * Since: 2.32
+ */
+void
+g_socket_set_multicast_loopback (GSocket *socket,
+ gboolean loopback)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (G_IS_SOCKET (socket));
+
+ loopback = !!loopback;
+
+ if (socket->priv->family == G_SOCKET_FAMILY_IPV4)
+ {
+ g_socket_set_option (socket, IPPROTO_IP, IP_MULTICAST_LOOP,
+ loopback, &error);
+ }
+ else if (socket->priv->family == G_SOCKET_FAMILY_IPV6)
+ {
+ g_socket_set_option (socket, IPPROTO_IP, IP_MULTICAST_LOOP,
+ loopback, NULL);
+ g_socket_set_option (socket, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+ loopback, &error);
+ }
+ else
+ g_return_if_reached ();
+
+ if (error)
+ {
+ g_warning ("error setting multicast loopback: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ g_object_notify (G_OBJECT (socket), "multicast-loopback");
+}
+
+/**
+ * g_socket_get_multicast_ttl:
+ * @socket: a #GSocket.
+ *
+ * Gets the multicast time-to-live setting on @socket; see
+ * g_socket_set_multicast_ttl() for more details.
+ *
+ * Returns: the multicast time-to-live setting on @socket
+ *
+ * Since: 2.32
+ */
+guint
+g_socket_get_multicast_ttl (GSocket *socket)
+{
+ GError *error = NULL;
+ gint value;
+
+ g_return_val_if_fail (G_IS_SOCKET (socket), 0);
+
+ if (socket->priv->family == G_SOCKET_FAMILY_IPV4)
+ {
+ g_socket_get_option (socket, IPPROTO_IP, IP_MULTICAST_TTL,
+ &value, &error);
+ }
+ else if (socket->priv->family == G_SOCKET_FAMILY_IPV6)
+ {
+ g_socket_get_option (socket, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+ &value, &error);
+ }
+ else
+ g_return_val_if_reached (FALSE);
+
+ if (error)
+ {
+ g_warning ("error getting multicast ttl: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return value;
+}
+
+/**
+ * g_socket_set_multicast_ttl:
+ * @socket: a #GSocket.
+ * @ttl: the time-to-live value for all multicast datagrams on @socket
+ *
+ * Sets the time-to-live for outgoing multicast datagrams on @socket.
+ * By default, this is 1, meaning that multicast packets will not leave
+ * the local network.
+ *
+ * Since: 2.32
+ */
+void
+g_socket_set_multicast_ttl (GSocket *socket,
+ guint ttl)
+{
+ GError *error = NULL;
+
+ g_return_if_fail (G_IS_SOCKET (socket));
+
+ if (socket->priv->family == G_SOCKET_FAMILY_IPV4)
+ {
+ g_socket_set_option (socket, IPPROTO_IP, IP_MULTICAST_TTL,
+ ttl, &error);
+ }
+ else if (socket->priv->family == G_SOCKET_FAMILY_IPV6)
+ {
+ g_socket_set_option (socket, IPPROTO_IP, IP_MULTICAST_TTL,
+ ttl, NULL);
+ g_socket_set_option (socket, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
+ ttl, &error);
+ }
+ else
+ g_return_if_reached ();
+
+ if (error)
+ {
+ g_warning ("error setting multicast ttl: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ g_object_notify (G_OBJECT (socket), "multicast-ttl");
+}
+
+/**