GInetAddress: GIO Reference Manual

## GInetAddress GInetAddress — An IPv4/IPv6 address |

## Functions

GInetAddress * | g_inet_address_new_from_string ()
GInetAddress * | g_inet_address_new_from_bytes ()
GInetAddress * | g_inet_address_new_any ()
GInetAddress * | g_inet_address_new_loopback ()
gboolean | g_inet_address_equal ()
const guint8 * | g_inet_address_to_bytes ()
gsize | g_inet_address_get_native_size ()
gchar * | g_inet_address_to_string ()
GSocketFamily | g_inet_address_get_family ()
gboolean | g_inet_address_get_is_any ()
gboolean | g_inet_address_get_is_loopback ()
gboolean | g_inet_address_get_is_link_local ()
gboolean | g_inet_address_get_is_site_local ()
gboolean | g_inet_address_get_is_multicast ()
gboolean | g_inet_address_get_is_mc_link_local ()
gboolean | g_inet_address_get_is_mc_node_local ()
gboolean | g_inet_address_get_is_mc_site_local ()
gboolean | g_inet_address_get_is_mc_org_local ()
gboolean | g_inet_address_get_is_mc_global ()

## Properties

gpointer | bytes | Read / Write / Construct Only
GSocketFamily | family | Read / Write / Construct Only
gboolean | is-any | Read
gboolean | is-link-local | Read
gboolean | is-loopback | Read
gboolean | is-mc-global | Read
gboolean | is-mc-link-local | Read
gboolean | is-mc-node-local | Read
gboolean | is-mc-org-local | Read
gboolean | is-mc-site-local | Read
gboolean | is-multicast | Read
gboolean | is-site-local | Read

## Types and Values

| GInetAddress

## Object Hierarchy

        GObject
        ╰── GInetAddress

## Includes

    #include <gio/gio.h>

## Description

GInetAddress represents an IPv4 or IPv6 internet address. Use `g_resolver_lookup_by_name()` or `g_resolver_lookup_by_name_async()` to look up the GInetAddress for a hostname. Use `g_resolver_lookup_by_address()` or `g_resolver_lookup_by_address_async()` to look up the hostname for a GInetAddress.

To actually connect to a remote host, you will need a GInetSocketAddress (which includes a GInetAddress as well as a port number).

## Functions

### g_inet_address_new_from_string ()

    GInetAddress *
    g_inet_address_new_from_string (const gchar *string);

Parses `string` as an IP address and creates a new GInetAddress.

#### Parameters

string | a string representation of an IP address |

#### Returns

a new GInetAddress corresponding to `string` , or `NULL` if `string` could not be parsed. Free the returned object with `g_object_unref()`.

Since: 2.22

### g_inet_address_new_from_bytes ()

    GInetAddress *
    g_inet_address_new_from_bytes (const guint8 *bytes,
                                   GSocketFamily family);

Creates a new GInetAddress from the given `family` and `bytes` . `bytes` should be 4 bytes for `G_SOCKET_FAMILY_IPV4` and 16 bytes for `G_SOCKET_FAMILY_IPV6`.

#### Parameters

bytes | raw address data. | [array][element-type guint8]
family | the address family of `bytes` |

#### Returns

a new GInetAddress corresponding to `family` and `bytes` . Free the returned object with `g_object_unref()`.

Since: 2.22

### g_inet_address_new_any ()

    GInetAddress *
    g_inet_address_new_any (GSocketFamily family);

Creates a GInetAddress for the "any" address (unassigned/"don't care") for `family` .

#### Parameters

family | the address family |

#### Returns

a new GInetAddress corresponding to the "any" address for `family` . Free the returned object with `g_object_unref()`.

Since: 2.22

### g_inet_address_new_loopback ()

    GInetAddress *
    g_inet_address_new_loopback (GSocketFamily family);

Creates a GInetAddress for the loopback address for `family` .

#### Parameters

family | the address family |

#### Returns

a new GInetAddress corresponding to the loopback address for `family` . Free the returned object with `g_object_unref()`.

Since: 2.22

### g_inet_address_equal ()

    gboolean
    g_inet_address_equal (GInetAddress *address,
                          GInetAddress *other_address);

Checks if two GInetAddress instances are equal, e.g. the same address.

#### Parameters

address | A GInetAddress. |
other_address | Another GInetAddress. |

#### Returns

`TRUE` if `address` and `other_address` are equal, `FALSE` otherwise.

Since: 2.30

### g_inet_address_to_bytes ()

    const guint8 *
    g_inet_address_to_bytes (GInetAddress *address);

Gets the raw binary address data from `address` .

[skip]

#### Parameters

address | a GInetAddress |

#### Returns

a pointer to an internal array of the bytes in `address` , which should not be modified, stored, or freed. The size of this array can be gotten with `g_inet_address_get_native_size()`.

Since: 2.22

### g_inet_address_get_native_size ()

    gsize
    g_inet_address_get_native_size (GInetAddress *address);

Gets the size of the native raw binary address for `address` . This is the size of the data that you get from `g_inet_address_to_bytes()`.

#### Parameters

address | a GInetAddress |

#### Returns

the number of bytes used for the native version of `address` .

Since: 2.22

### g_inet_address_to_string ()

    gchar *
    g_inet_address_to_string (GInetAddress *address);

Converts `address` to string form.

#### Parameters

address | a GInetAddress |

#### Returns

a representation of `address` as a string, which should be freed after use.

Since: 2.22

### g_inet_address_get_family ()

    GSocketFamily
    g_inet_address_get_family (GInetAddress *address);

Gets `address` 's family

#### Parameters

address | a GInetAddress |

#### Returns

`address` 's family

Since: 2.22

### g_inet_address_get_is_any ()

    gboolean
    g_inet_address_get_is_any (GInetAddress *address);

Tests whether `address` is the "any" address for its family.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is the "any" address for its family.

Since: 2.22

### g_inet_address_get_is_loopback ()

    gboolean
    g_inet_address_get_is_loopback (GInetAddress *address);

Tests whether `address` is the loopback address for its family.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is the loopback address for its family.

Since: 2.22

### g_inet_address_get_is_link_local ()

    gboolean
    g_inet_address_get_is_link_local (GInetAddress *address);

Tests whether `address` is a link-local address (that is, if it identifies a host on a local network that is not connected to the Internet).

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a link-local address.

Since: 2.22

### g_inet_address_get_is_site_local ()

    gboolean
    g_inet_address_get_is_site_local (GInetAddress *address);

Tests whether `address` is a site-local address such as 10.0.0.1 (that is, the address identifies a host on a local network that can not be reached directly from the Internet, but which may have outgoing Internet connectivity via a NAT or firewall).

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a site-local address.

Since: 2.22

### g_inet_address_get_is_multicast ()

    gboolean
    g_inet_address_get_is_multicast (GInetAddress *address);

Tests whether `address` is a multicast address.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a multicast address.

Since: 2.22

### g_inet_address_get_is_mc_link_local ()

    gboolean
    g_inet_address_get_is_mc_link_local (GInetAddress *address);

Tests whether `address` is a link-local multicast address.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a link-local multicast address.

Since: 2.22

### g_inet_address_get_is_mc_node_local ()

    gboolean
    g_inet_address_get_is_mc_node_local (GInetAddress *address);

Tests whether `address` is a node-local multicast address.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a node-local multicast address.

Since: 2.22

### g_inet_address_get_is_mc_site_local ()

    gboolean
    g_inet_address_get_is_mc_site_local (GInetAddress *address);

Tests whether `address` is a site-local multicast address.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a site-local multicast address.

Since: 2.22

### g_inet_address_get_is_mc_org_local ()

    gboolean
    g_inet_address_get_is_mc_org_local (GInetAddress *address);

Tests whether `address` is an organization-local multicast address.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is an organization-local multicast address.

Since: 2.22

### g_inet_address_get_is_mc_global ()

    gboolean
    g_inet_address_get_is_mc_global (GInetAddress *address);

Tests whether `address` is a global multicast address.

#### Parameters

address | a GInetAddress |

#### Returns

`TRUE` if `address` is a global multicast address.

Since: 2.22

## Types and Values

### GInetAddress

    typedef struct _GInetAddress GInetAddress;

An IPv4 or IPv6 internet address.

## Property Details

### The `“bytes”` property

      “bytes”                    gpointer

The raw address data.

Flags: Read / Write / Construct Only

### The `“family”` property

      “family”                   GSocketFamily

The address family (IPv4 or IPv6).

Flags: Read / Write / Construct Only

Default value: G_SOCKET_FAMILY_INVALID

### The `“is-any”` property

      “is-any”                   gboolean

Whether this is the "any" address for its family. See `g_inet_address_get_is_any()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-link-local”` property

      “is-link-local”            gboolean

Whether this is a link-local address. See `g_inet_address_get_is_link_local()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-loopback”` property

      “is-loopback”              gboolean

Whether this is the loopback address for its family. See `g_inet_address_get_is_loopback()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-mc-global”` property

      “is-mc-global”             gboolean

Whether this is a global multicast address. See `g_inet_address_get_is_mc_global()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-mc-link-local”` property

      “is-mc-link-local”         gboolean

Whether this is a link-local multicast address. See `g_inet_address_get_is_mc_link_local()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-mc-node-local”` property

      “is-mc-node-local”         gboolean

Whether this is a node-local multicast address. See `g_inet_address_get_is_mc_node_local()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-mc-org-local”` property

      “is-mc-org-local”          gboolean

Whether this is an organization-local multicast address. See `g_inet_address_get_is_mc_org_local()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-mc-site-local”` property

      “is-mc-site-local”         gboolean

Whether this is a site-local multicast address. See `g_inet_address_get_is_mc_site_local()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-multicast”` property

      “is-multicast”             gboolean

Whether this is a multicast address. See `g_inet_address_get_is_multicast()`.

Flags: Read

Default value: FALSE

Since: 2.22

### The `“is-site-local”` property

      “is-site-local”            gboolean

Whether this is a site-local address. See `g_inet_address_get_is_loopback()`.

Flags: Read

Default value: FALSE

Since: 2.22