Definitive guide to understanding how to formulate an IPv6 address

笑着哭i 提交于 2019-12-03 05:48:43

In general, yes, your points are correct.

Are you sure you read the RFC? RFC 3513, section 2.2 has exactly what you are asking for. It's very well written, for an RFC. =) I can't help but point this out since it may be very helpful to future people reading this question.

Obviously this bit is a typo:

it is possible to use double colons syntax to represent one or more blocks with zeroes. 1:2::6:7 is equivalent to 1:2:3:4:5:6:7:8.

1:2::6:7 means 1:2:0:0:0:0:6:7.

I hadn't heard this before:

double colon may [not appear] within an ip4 dot address.

But I made a test program, and it seems to confirm it.

$ ./testipv6 0:0:0:0:0:0:192.168.0.1
0:0:0:0:0:0:192.168.0.1: OK

$ ./testipv6 0:0:0:0:0:0:192.168::1
0:0:0:0:0:0:192.168::1: ERROR

Otherwise I think everything you said is OK.


testipv6.c

#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>

int convert(const char *addr)
{
    struct in6_addr dst;

    return inet_pton(AF_INET6, addr, (void *)&dst);
}

int main(int argc, char **argv)
{
    if (argc == 1) {
        fprintf(stderr, "Usage: testipv6 <addr>\n");
        exit(2);
    }

    while (argc > 1) {
        argc--, argv++;
        const char *addr = argv[0];

        if (convert(addr)) {
            printf("%s: OK\n", addr);
        } else {
            printf("%s: ERROR\n", addr);
        }
    }
}

IPv6 addresses with zone ID has a unique notation though its not specific to the address itself. In a system with multiple IPv6 enabled interfaces the link local address has to be disambiguated in some way. Its done using the "%" notation.

FE80::AA%eth0 refers to the link local address reachable through the eth0 interface. It can be an interface index in some plaforms, FE80::AA%10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!