InfIpAddress

InfIpAddress — IPv4 and IPv6 addresses

Stability Level

Unstable, unless otherwise indicated

Synopsis


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


                    InfIpAddress;
enum                InfIpAddressFamily;
InfIpAddress*       inf_ip_address_new_raw4             (guint32 address);
InfIpAddress*       inf_ip_address_new_loopback4        (void);
InfIpAddress*       inf_ip_address_new_raw6             (const guint8 address[16]);
InfIpAddress*       inf_ip_address_new_loopback6        (void);
InfIpAddress*       inf_ip_address_new_from_string      (const gchar *str);
InfIpAddress*       inf_ip_address_copy                 (const InfIpAddress *address);
void                inf_ip_address_free                 (InfIpAddress *address);
InfIpAddressFamily  inf_ip_address_get_family           (const InfIpAddress *address);
gconstpointer       inf_ip_address_get_raw              (const InfIpAddress *address);
gchar*              inf_ip_address_to_string            (const InfIpAddress *address);
int                 inf_ip_address_collate              (const InfIpAddress *address1,
                                                         const InfIpAddress *address2);

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.

Details

InfIpAddress

typedef struct _InfIpAddress InfIpAddress;

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


enum InfIpAddressFamily

typedef enum _InfIpAddressFamily {
  INF_IP_ADDRESS_IPV4,
  INF_IP_ADDRESS_IPV6
} InfIpAddressFamily;

This enumeration specifies different types of IP addresses.

INF_IP_ADDRESS_IPV4

This specifies an IPv4 address.

INF_IP_ADDRESS_IPV6

This specifies an IPv6 address.

inf_ip_address_new_raw4 ()

InfIpAddress*       inf_ip_address_new_raw4             (guint32 address);

Creates a new IPv4 address.

address :

An IPv4 address in network byte order.

Returns :

A new InfIpAddress.

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").

Returns :

A new InfIpAddress.

inf_ip_address_new_raw6 ()

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

Creates a new IPv6 address.

address :

An IPv6 address in network bype order.

Returns :

A new InfIpAddress.

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").

Returns :

A new InfIpAddress.

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.

str :

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

Returns :

A new InfIpAddress, or NULL.

inf_ip_address_copy ()

InfIpAddress*       inf_ip_address_copy                 (const InfIpAddress *address);

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

address :

A InfIpAddress.

Returns :

A new InfIpAddress.

inf_ip_address_free ()

void                inf_ip_address_free                 (InfIpAddress *address);

Frees address.

address :

A InfIpAddress.

inf_ip_address_get_family ()

InfIpAddressFamily  inf_ip_address_get_family           (const InfIpAddress *address);

Returns the address family of address.

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.

address :

A InfIpAddress.

Returns :

The raw address.

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").

address :

A InfIpAddress.

Returns :

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

inf_ip_address_collate ()

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

Compares the two addresses for sorting.

address1 :

First address.

address2 :

Second address.

Returns :

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

See Also

InfTcpConnection