gnetworkaddress: Add g_network_address_new_loopback() constructor

This is a convenience method for creating a GNetworkAddress which is
guaranteed to return IPv4 and IPv6 loopback addresses. The program
cannot guarantee that 'localhost' will resolve to both types of
address, so programs which wish to connect to a local service over
either IPv4 or IPv6 must currently manually create an IPv4 and another
IPv6 socket, and detect which of the two are working. This new API
allows the existing GSocketConnectable machinery to be used to
automate that.

Based on a patch from Philip Withnall.

https://bugzilla.gnome.org/show_bug.cgi?id=732317
This commit is contained in:
Dan Winship
2014-11-23 12:53:03 -05:00
parent 296c710c64
commit 64f9bf96fd
4 changed files with 182 additions and 2 deletions

View File

@@ -57,6 +57,8 @@ GType g_network_address_get_type (void) G_GNUC_CONST;
GLIB_AVAILABLE_IN_ALL
GSocketConnectable *g_network_address_new (const gchar *hostname,
guint16 port);
GLIB_AVAILABLE_IN_2_44
GSocketConnectable *g_network_address_new_loopback (guint16 port);
GLIB_AVAILABLE_IN_ALL
GSocketConnectable *g_network_address_parse (const gchar *host_and_port,
guint16 default_port,