## InfIpAddress

InfIpAddress — IPv4 and IPv6 addresses

## Stability Level

Unstable, unless otherwise indicated

## Functions

InfIpAddress * | inf_ip_address_new_raw4 ()
InfIpAddress * | inf_ip_address_new_loopback4 ()
InfIpAddress * | inf_ip_address_new_raw6 ()
InfIpAddress * | inf_ip_address_new_loopback6 ()
InfIpAddress * | inf_ip_address_new_from_string ()
InfIpAddress * | inf_ip_address_copy ()
void | inf_ip_address_free ()
InfIpAddressFamily | inf_ip_address_get_family ()
gconstpointer | inf_ip_address_get_raw ()
gchar * | inf_ip_address_to_string ()
int | inf_ip_address_collate ()

## Types and Values

| InfIpAddress
enum | InfIpAddressFamily

## Object Hierarchy

        GBoxed
        ╰── InfIpAddress
        GEnum
        ╰── InfIpAddressFamily

## Includes

    #include <libinfinity/common/inf-ip-address.h>

## Description

A InfIpAddress represents an IPv4 or an IPv6 network address. Use `inf_ip_address_get_family()` to find out the type of a specific address.

## Functions

### inf_ip_address_new_raw4 ()

    InfIpAddress *
    inf_ip_address_new_raw4 (guint32 address);

Creates a new IPv4 address.

[constructor]

#### Parameters

address | An IPv4 address in network byte order. |

#### Returns

A new InfIpAddress.

[transfer full]

### inf_ip_address_new_loopback4 ()

    InfIpAddress *
    inf_ip_address_new_loopback4 (void);

Creates a new IPv4 address that contains the local host's IP address ("127.0.0.1").

[constructor]

#### Returns

A new InfIpAddress.

[transfer full]

### inf_ip_address_new_raw6 ()

    InfIpAddress *
    inf_ip_address_new_raw6 (const guint8 address[16]);

Creates a new IPv6 address.

[constructor]

#### Parameters

address | An IPv6 address in network bype order. |

#### Returns

A new InfIpAddress.

[transfer full]

### inf_ip_address_new_loopback6 ()

    InfIpAddress *
    inf_ip_address_new_loopback6 (void);

Creates a new IPv6 address that contains the local host's IP address ("::1").

[constructor]

#### Returns

A new InfIpAddress.

[transfer full]

### inf_ip_address_new_from_string ()

    InfIpAddress *
    inf_ip_address_new_from_string (const gchar *str);

Creates a new IP address (either IPv4 or IPv6) from the given string.

[constructor]

#### Parameters

str | A string containing an IPv4 or IPv6 address in standard dots notation. |

#### Returns

A new InfIpAddress, or `NULL`.

[transfer full]

### inf_ip_address_copy ()

    InfIpAddress *
    inf_ip_address_copy (const InfIpAddress *address);

Creates a new InfIpAddress that contains the same address as `address` .

#### Parameters

address | A InfIpAddress. |

#### Returns

A new InfIpAddress.

### inf_ip_address_free ()

    void
    inf_ip_address_free (InfIpAddress *address);

Frees `address` .

#### Parameters

address | A InfIpAddress. |

### inf_ip_address_get_family ()

    InfIpAddressFamily
    inf_ip_address_get_family (const InfIpAddress *address);

Returns the address family of `address` .

#### Parameters

address | A InfIpAddress. |

#### Returns

A InfIpAddressFamily.

### inf_ip_address_get_raw ()

    gconstpointer
    inf_ip_address_get_raw (const InfIpAddress *address);

Returns either 32 bit (IPv4) or 128 bit (IPv6) raw address data in host byte order of `address` .

#### Parameters

address | A InfIpAddress. |

#### Returns

The raw address.

[transfer none]

### inf_ip_address_to_string ()

    gchar *
    inf_ip_address_to_string (const InfIpAddress *address);

Returns a string representation of `address` in standard dots format (like "192.168.0.1" or "::1").

#### Parameters

address | A InfIpAddress. |

#### Returns

A newly-allocated string. Free with `g_free()`.

[transfer full]

### inf_ip_address_collate ()

    int
    inf_ip_address_collate (const InfIpAddress *address1,
                            const InfIpAddress *address2);

Compares the two addresses for sorting.

#### Parameters

address1 | First address. |
address2 | Second address. |

#### Returns

-1 if `address1` compares before, 0 if it compares equal or 1 if it compares after `address` .

## Types and Values

### InfIpAddress

    typedef struct _InfIpAddress InfIpAddress;

InfIpAddress is an opaque data type. You should only access it via the public API functions.

### enum InfIpAddressFamily

This enumeration specifies different types of IP addresses.

#### Members

INF_IP_ADDRESS_IPV4 | This specifies an IPv4 address. |
INF_IP_ADDRESS_IPV6 | This specifies an IPv6 address. |

## See Also

InfTcpConnection