Adding support for IPv6 in IPv4 client/server apps – sin6_flowinfo and sin6_scope_id fields?

The best way to go is to use getaddrinfo().

Pseudo code:

struct addrinfo *restrict hints = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM };
struct addrinfo * res, r;
if (0 == getaddrinfo("foo.bar.baz", "http", &hints, &res)) {
    for (r=res; r; r=r->ai_next) {
        sock = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
        connect(sock, r->ai_addr, r->ai_addrlen);
        if error: continue
        break
    }
}
freeaddrinfo(res);

This will take the worry about sin6_scope_id from you; which is normally 0, except if you have link-local addresses like fe80::1234:56ff:fe78:9abc%eth2. This eth2 is converted to the correct scope ID.

sin6_flowinfo is obsolete (AFAIK) and thus set to 0 in your resulting struct addrinfo‘s ai_addr.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)