GIO Reference Manual: GInetAddressMask

## GInetAddressMask GInetAddressMask — An IPv4/IPv6 address mask |

## Synopsis

                        GInetAddressMask;
    GInetAddressMask *  g_inet_address_mask_new             (GInetAddress *addr,
                                                             guint length,
                                                             GError **error);
    GInetAddressMask *  g_inet_address_mask_new_from_string (const gchar *mask_string,
                                                             GError **error);
    gchar *             g_inet_address_mask_to_string       (GInetAddressMask *mask);
    GSocketFamily       g_inet_address_mask_get_family      (GInetAddressMask *mask);
    GInetAddress *      g_inet_address_mask_get_address     (GInetAddressMask *mask);
    guint               g_inet_address_mask_get_length      (GInetAddressMask *mask);
    gboolean            g_inet_address_mask_matches         (GInetAddressMask *mask,
                                                             GInetAddress *address);
    gboolean            g_inet_address_mask_equal           (GInetAddressMask *mask,
                                                             GInetAddressMask *mask2);

## Description

GInetAddressMask represents a range of IPv4 or IPv6 addresses described by a base address and a length indicating how many bits of the base address are relevant for matching purposes. These are often given in string form. Eg, "10.0.0.0/8", or "fe80::/10".

## Details

### GInetAddressMask

    typedef struct {
      GObject parent_instance;
    } GInetAddressMask;

A combination of an IPv4 or IPv6 base address and a length, representing a range of IP addresses.

Since 2.32

### g_inet_address_mask_new ()

    GInetAddressMask *  g_inet_address_mask_new             (GInetAddress *addr,
                                                             guint length,
                                                             GError **error);

Creates a new GInetAddressMask representing all addresses whose first `length` bits match `addr`.

`addr` : | a GInetAddress
`length` : | number of bits of `addr` to use
`error` : | return location for GError, or `NULL`
Returns : | a new GInetAddressMask, or `NULL` on error

Since 2.32

### g_inet_address_mask_new_from_string ()

    GInetAddressMask *  g_inet_address_mask_new_from_string (const gchar *mask_string,
                                                             GError **error);

Parses `mask_string` as an IP address and (optional) length, and creates a new GInetAddressMask. The length, if present, is delimited by a "/". If it is not present, then the length is assumed to be the full length of the address.

`mask_string` : | an IP address or address/length string
`error` : | return location for GError, or `NULL`
Returns : | a new GInetAddressMask corresponding to `string`, or `NULL` on error.

Since 2.32

### g_inet_address_mask_to_string ()

    gchar *             g_inet_address_mask_to_string       (GInetAddressMask *mask);

Converts `mask` back to its corresponding string form.

`mask` : | a GInetAddressMask
Returns : | a string corresponding to `mask`.

Since 2.32

### g_inet_address_mask_get_family ()

    GSocketFamily       g_inet_address_mask_get_family      (GInetAddressMask *mask);

Gets the GSocketFamily of `mask`'s address

`mask` : | a GInetAddressMask
Returns : | the GSocketFamily of `mask`'s address

Since 2.32

### g_inet_address_mask_get_address ()

    GInetAddress *      g_inet_address_mask_get_address     (GInetAddressMask *mask);

Gets `mask`'s base address

`mask` : | a GInetAddressMask
Returns : | `mask`'s base address. [transfer none]

Since 2.32

### g_inet_address_mask_get_length ()

    guint               g_inet_address_mask_get_length      (GInetAddressMask *mask);

Gets `mask`'s length

`mask` : | a GInetAddressMask
Returns : | `mask`'s length

Since 2.32

### g_inet_address_mask_matches ()

    gboolean            g_inet_address_mask_matches         (GInetAddressMask *mask,
                                                             GInetAddress *address);

Tests if `address` falls within the range described by `mask`.

`mask` : | a GInetAddressMask
`address` : | a GInetAddress
Returns : | whether `address` falls within the range described by `mask`.

Since 2.32

### g_inet_address_mask_equal ()

    gboolean            g_inet_address_mask_equal           (GInetAddressMask *mask,
                                                             GInetAddressMask *mask2);

Tests if `mask` and `mask2` are the same mask.

`mask` : | a GInetAddressMask
`mask2` : | another GInetAddressMask
Returns : | whether `mask` and `mask2` are the same mask

Since 2.32