Reply to post: Re: Compatibility

OK, this time it's for real: The last available IPv4 address block has gone

Nanashi

Re: Compatibility

> I, for example, want to know if two addresses are the same. With IPv4 I look at them, do strcmp or simple 32 bit integer arithmetic; with IPv6 I have do do a massively complex normalisation step first then line them up on paper and use my fingers.

It's interesting how wrong this actually is. Here's a list of v4 addresses -- every single one of these refers to the exact same IP:

10.24.42

10.24.0.42

10.24.052

10.24.0.052

10.24.0x2a

10.24.0.0x2a

10.030.42

10.030.0.42

10.030.052

10.030.0.052

10.030.0x2a

10.030.0.0x2a

10.0x1a.42

10.0x1a.0.42

10.0x1a.052

10.0x1a.0.052

10.0x1a.0x2a

10.0x1a.0.0x2a

10.1572906

10.06000052

10.0x18002a

012.24.42

012.24.0.42

012.24.052

012.24.0.052

012.24.0x2a

012.24.0.0x2a

012.030.42

012.030.0.42

012.030.052

012.030.0.052

012.030.0x2a

012.030.0.0x2a

012.0x1a.42

012.0x1a.0.42

012.0x1a.052

012.0x1a.0.052

012.0x1a.0x2a

012.0x1a.0.0x2a

012.1572906

012.06000052

012.0x18002a

0xa.24.42

0xa.24.0.42

0xa.24.052

0xa.24.0.052

0xa.24.0x2a

0xa.24.0.0x2a

0xa.030.42

0xa.030.0.42

0xa.030.052

0xa.030.0.052

0xa.030.0x2a

0xa.030.0.0x2a

0xa.0x1a.42

0xa.0x1a.0.42

0xa.0x1a.052

0xa.0x1a.0.052

0xa.0x1a.0x2a

0xa.0x1a.0.0x2a

0xa.1572906

0xa.06000052

0xa.0x18002a

169345066

01206000052

0xa18002a

strcmp() ain't gonna help you here. v6 is pretty simple in comparison; here's a roughly equivalent address and its variations:

2001:db8:420:24::42

2001:db8:420:24:0::42

2001:db8:420:24::0:42

2001:db8:420:24::0:0:42

2001:db8:420:24:0::0:42

2001:db8:420:24:0:0::42

2001:db8:420:24:0:0:0:42

That's pretty short, and it's a lot easier to compare in your head too. (For instance, how many of you noticed that I made a mistake in my v4 list above? Some of those addresses aren't equivalent! Even now that I've straight up told you, how many of you can spot the mistake easily?)

In case anybody is wondering, the "massively complex normalisation step" that Adam referred to consists of calling getaddrinfo() on the address. That's, er, basically it.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2019