//gcc -o test -Wall $(pkg-config --cflags --libs gio-2.0) test-case.c
#include <gio/gio.h>

int main(int argc, char **argv)
{
    g_type_init();

//replace with a link local address on your machine, look in ifconfig,
//pick an ipv6 address starting with  fe80, and append %interface_name
    const char *address = "fe80::0000:00ff:fe00:0000%em1";
    GSocketConnectable *addr;
    GSocketAddressEnumerator *enumerator;
    GSocketAddress *sockaddr;
    GError *error = NULL;

    addr = g_network_address_new(address, 5555);
    enumerator = g_socket_connectable_enumerate (addr);
    g_object_unref (addr);

    /* g_socket_address_enumerator_next loses ipv6 scope_id: it first
     * goes through:
#0  _g_resolver_addresses_from_addrinfo (
    hostname=0x8af710 "fe80::f2de:f1ff:fe41:2ef7%em1", res=0x8aca60,
    gai_retval=0, error=0x7fffe9175a98) at gresolver.c:931
#1  0x00007ffff431fc41 in do_lookup_by_name (req=0x7fdc90,
    error=0x7fffe9175a98) at gthreadedresolver.c:378
#2  0x00007ffff431fa13 in resolve_sync (gtr=0x87b240, req=0x7fdc90,
    error=0x7fffe9175a98) at gthreadedresolver.c:322
#3  0x00007ffff431fcd2 in lookup_by_name (resolver=0x87b240,
    hostname=0x8af710 "fe80::f2de:f1ff:fe41:2ef7%em1", cancellable=0x0,
    error=0x7fffe9175a98) at gthreadedresolver.c:395
#4  0x00007ffff4304bbf in g_resolver_lookup_by_name (resolver=0x87b240,
    hostname=0x8af710 "fe80::f2de:f1ff:fe41:2ef7%em1", cancellable=0x0,
    error=0x7fffe9175a98) at gresolver.c:357
#5  0x00007ffff42fc60b in g_network_address_address_enumerator_next (
    enumerator=0x8ad0c0, cancellable=0x0, error=0x7fffe9175a98)
    at gnetworkaddress.c:827
#6  0x00007ffff431282c in g_socket_address_enumerator_next (
    enumerator=0x8ad0c0, cancellable=0x0, error=0x7fffe9175a98)
    at gsocketaddressenumerator.c:85
     *
     * _g_resolver_addresses_from_addrinfo first generates a GInetSocketAddress
     * through g_socket_address_new_from_native(). At this point the scope id
     * information is present. Right after that,  _g_resolver_addresses_from_addrinfo
     * only keeps a reference on the GInetAddress it contains (obtained from
     * g_inet_socket_address_get_address). GInetAddress cannot store the scope
     * id so it's lost.
     *
     * After calling g_resolver_lookup_by_name(), g_network_address_address_enumerator_next()
     * calls g_network_address_set_addresses() which iterates over the GInetAddress
     * generated by the call to g_resolver_lookup_by_name() and creates
     * GInetSocketAddress from them using g_inet_socket_address_new(). However,
     * the scope id information is no longer available :-/
     */
    while ((sockaddr = g_socket_address_enumerator_next(enumerator, NULL, &error))) {
        g_assert(g_inet_socket_address_get_scope_id(G_INET_SOCKET_ADDRESS(sockaddr)) != 0);
    }
    if (error) {
        g_warning("%s", error->message);
        g_clear_error(&error);
    }
    g_object_unref(enumerator);

    return 0;
}
