### Function

# Gio NetworkAddress parse

since: 2.22

#### Declaration

    GSocketConnectable*
    g_network_address_parse (
      const gchar* host_and_port,
      guint16 default_port,
      GError** error
    )

#### Description

Creates a new `GSocketConnectable` for connecting to the given `hostname` and `port`. May fail and return `NULL` in case parsing `host_and_port` fails.

`host_and_port` may be in any of a number of recognised formats; an IPv6 address, an IPv4 address, or a domain name (in which case a DNS lookup is performed). Quoting with [] is supported for all address types. A port override may be specified in the usual way with a colon.

If no port is specified in `host_and_port` then `default_port` will be used as the port number to connect to.

In general, `host_and_port` is expected to be provided by the user (allowing them to give the hostname, and a port override if necessary) and `default_port` is expected to be provided by the application.

(The port component of `host_and_port` can also be specified as a service name rather than as a numeric port, but this functionality is deprecated, because it depends on the contents of /etc/services, which is generally quite sparse on platforms other than Linux.)

Available since: 2.22

#### Parameters

`host_and_port`

  Type: `const gchar*`

  The hostname and optionally a port.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`default_port`

  Type: `guint16`

  The default port if not in `host_and_port`.

`error`

  Type: `GError **`

  The return location for a recoverable error.

  The argument can be `NULL`.
  If the return location is not `NULL`, then you must initialize it to a `NULL` `GError*`.
  The argument will be left initialized to `NULL` by the function if there are no errors.
  In case of error, the argument will be set to a newly allocated `GError`; the caller will take ownership of the data, and be responsible for freeing it.

#### Return value

Type: `GNetworkAddress`

The new `GNetworkAddress`, or `NULL` on error.

The caller of the function takes ownership of the data, and is responsible for freeing it.