[ds6] Info on address notation

Mauro Tortonesi mtortonesi at ing.unife.it
Mon Jul 14 12:57:36 CEST 2003


On Sun, 13 Jul 2003, Stefano Guandalini wrote:

> Sorry if my question is very simple but I am a newby.
>
> I'm taking a look to linux include files to start developing an app that
> supports ipv6. It's a daemon that have to talk to some terminals that check
> entrance in buildings.
>
> I have some doubts with the string notation of addresses; counting the maximum
> lenght that an ipv6 address can be, I think I need a 39 characters string but
> in /usr/include/netinet/in.h I see:
>
> #define INET_ADDRSTRLEN 16
> #define INET6_ADDRSTRLEN 46
>
> I suppose that the second value is to declare a char[].
>
> Am I right?

yes. the constants above are respectively meant to be used in the
declaration of a buffer which should contain the string notation of
IPv4 and IPv6 addresses (not hostnames!).

> Why 46 chars?

because of ipv4-compatible addresses. in fact the following:

0000:0000:0000:0000:0000:0000:111.222.111.222
         1         2         3         4    4
         0         0         0         0    5

is a valid IPv6 address. see RFC3513.


BTW: you should try to use getnameinfo instead of inet_ntop to get the
     string representation of an IP (both v6 and v4) address.

BTW2: you may find these documents helpful:

http://www.kame.net/newsletter/19980604/
http://jungla.dit.upm.es/~ecastro/IPv6-web/ipv6.html

-- 
Aequam memento rebus in arduis servare mentem...

Mauro Tortonesi                 mtortonesi at ing.unife.it
                                mauro at deepspace6.net
                                mauro at ferrara.linux.it
Deep Space 6 - IPv6 with Linux  http://www.deepspace6.net
Ferrara Linux User Group        http://www.ferrara.linux.it




More information about the ds6 mailing list