You are viewing a single thread.
View all comments View context
11 points

And dupe check. 0.0.0.0 and 000.000.000.000 may both be valid, but they resolve the same

permalink
report
parent
reply
6 points

Fuck that, if for whatever reason I’m writing an IP validator by hand I’m disallowing leading zeros. Parsers are very inconsistent, some will parse 010 as 10, others as 0o10 == 8 (you can try that right now with a POSIX ping). Talk about a footgun.

permalink
report
parent
reply
6 points

some will parse 010 as 10, others as 0o10 == 8

…and that’s me in the fetal position, thanks.

permalink
report
parent
reply
3 points
*

Definitely, tho if you store it as a u32 that is fixed magically. Because 1.2.3.4 and 1.02.003.04 both map to the same number.

What I mean by storing it as a u32 is to convert it to a number, similar to how the IP gets sent over the wire, so for v4:

octet[3] | octet[2] << 8 | octet[1] << 16 | octet[0] << 24

or in more human terms:

(fourth octet) + (third octet * 256) + (second octet * 256^2) + (first octet * 256^3)
permalink
report
parent
reply
1 point
Deleted by creator
permalink
report
parent
reply
2 points

True enough for database or dictionary storage, but a lot of times things get implemented in arrays where you still wind up with two copies of the same uint32.

permalink
report
parent
reply
2 points

Because 1.2.3.4 and 1.02.003.04 both map to the same number.

But 10.20.30.40 and 010.020.030.040 map to different numbers. It’s often best to reject IPv4 addresses with leading zeroes to avoid the decimal vs. octal ambiguity.

permalink
report
parent
reply
2 points

I don’t know why anyone would write their IPs in octal, but fair point

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 6.4K

    Monthly active users

  • 988

    Posts

  • 38K

    Comments