Hacker News new | ask | show | jobs
by kortilla 2008 days ago
What is the use-case of a decimal representation of a v6 address or a 32-bit int representation of an ipv4 address?

I’ve never had someone tell me, “see if you can ping 143267841”. I’ve worked in networking for coming up on 30 years now and just haven’t found the use.

6 comments

I suspect it's actually the other way around. On the wire, a v4 address is four bytes. uint_32 is the natural type for this. So when we start looking at cidr scopes, /24 means the first 24 bits of those 32. "The first 24 bits of 4 bytes" sounds wrong to me, "the first 24 bits of 32 bits" sounds logical.

So as I see it - 143267841 (or 0x88A1801) is the address, and quad-dotted decimal is a (slightly more) human-readable representation of it.

>32-bit int representation of an ipv4 address

Internally, I would imagine that almost every IPv4 stack uses 32bit ints to represent an address. Its not that crazy to think this would leak out somewhere.

I've written (un)parsers where we would just treat IPv4 addresses as integers because A) that is how they were treated in the binary data and B) given what we were doing with the data, we didn't actually care about the IPv4 field.

Serialization for non human readable code. Usually IPv4 addresses are stored as int32 in databases or memory
Perhaps rather "ideally" than "usually." I have worked on several codebases that wasted gigabytes of memory / traffic on this.
Ugh. I would hate to see the code to enumerate a network, or calculate masks, or determine broadcast addresses without using unsigned ints.
I had, unfortunately. Bitwise operations are scary for some people, so they prefer working with 4 ints or worse, using a string
> 4 ints or worse, using a string

Or worse, in one case I've had to deal with both (plus another surprise twist):

    public class IP {
        byte[] value 
        // if true value is a variable-length ASCII dotted octet,
        // if false it is length 4 - with LSB in value[0].
        bool isString
    }
IPC at least. If you want to pass an IP address (whose natural native representation is a uint32) from program to program as text, having to format it as dotted decimal would be just unnecessary and inconvenient.
Not the answer you're expecting I guess, but I've used it to bypass some anti-XSS filters.
There is no use case. It's a meaningless outcome of the fact that `strtoul` is involved somewhere.