Skip to content

Commit

Permalink
vnc-server: Attempting binding to IPv6 first.
Browse files Browse the repository at this point in the history
This fixes issue #266.

* src/vnc-server.c (vnc_server_start): Bind to IPv6 address before the
IPv4 one.

Suggested-by: Bruno Victal <[email protected]>
  • Loading branch information
Apteryks authored and robert-ancell committed Jan 16, 2024
1 parent 1ade713 commit 197a334
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/vnc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,10 @@ vnc_server_start (VNCServer *server)

g_return_val_if_fail (server != NULL, FALSE);

g_autoptr(GError) ipv4_error = NULL;
priv->socket = open_tcp_socket (G_SOCKET_FAMILY_IPV4, priv->port, priv->listen_address, &ipv4_error);
if (ipv4_error)
g_warning ("Failed to create IPv4 VNC socket: %s", ipv4_error->message);

if (priv->socket)
{
GSource *source = g_socket_create_source (priv->socket, G_IO_IN, NULL);
g_source_set_callback (source, (GSourceFunc) read_cb, server, NULL);
g_source_attach (source, NULL);
}

// Bind to IPv6 first, as this implies binding to 0.0.0.0 in the
// Linux kernel default configuration, which would otherwise cause
// IPv6 clients to fail with "Error binding to address [::]:5900:
// Address already in use" (#266).
g_autoptr(GError) ipv6_error = NULL;
priv->socket6 = open_tcp_socket (G_SOCKET_FAMILY_IPV6, priv->port, priv->listen_address, &ipv6_error);
if (ipv6_error)
Expand All @@ -150,6 +142,18 @@ vnc_server_start (VNCServer *server)
g_source_attach (source, NULL);
}

g_autoptr(GError) ipv4_error = NULL;
priv->socket = open_tcp_socket (G_SOCKET_FAMILY_IPV4, priv->port, priv->listen_address, &ipv4_error);
if (ipv4_error)
g_warning ("Failed to create IPv4 VNC socket: %s", ipv4_error->message);

if (priv->socket)
{
GSource *source = g_socket_create_source (priv->socket, G_IO_IN, NULL);
g_source_set_callback (source, (GSourceFunc) read_cb, server, NULL);
g_source_attach (source, NULL);
}

if (!priv->socket && !priv->socket6)
return FALSE;

Expand Down

0 comments on commit 197a334

Please sign in to comment.