in reply to comparing two ip addresses.

An interesting concept, but I'm not sure that ip-addresses support the idea of "greater than" or "lower than".

One can check if they are equal or not and whether they belong to the same interval or not, but it is my feeling that saying that an ip address is "greater than" another ip address has no physical reality behind it.

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: comparing two ip addresses.
by shmem (Chancellor) on Sep 16, 2006 at 09:52 UTC
    IP-addresses are numbers, and as such, they can be compared in terms of greater or lesser. And it makes sense. It happens to be that the lowest ip address in a given range is the network address, the highest is the broadcast address. How would you say that avoiding the words low and high, greater and lesser?

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      your statement about IP addresses whilst true in general, is not technically correct. you can actually choose any address you like for the network and broadcast, as long as all the devices on this net know the same.
      also...as the other monks said...ip adresses are not lower or higher, when you are talking about IP addressing...they're either equal or not equal. although we may consider them in those terms (higher/lower) for purposes of sorting.
      the hardest line to type correctly is: stty erase ^H
Re^2: comparing two ip addresses.
by ikegami (Patriarch) on Sep 16, 2006 at 09:34 UTC
    I was going to say as much in my post, then I realized there are two reasons to do comparisons: 1) To provide a consistent display order, and 2) To sort the start and end addresses of a range before iterating over said range. The OP is clearly doing the second, based on the names of his variables.
Re^2: comparing two ip addresses.
by jdporter (Paladin) on Sep 16, 2006 at 15:19 UTC

    It's useful for sorting, which is useful for grouping.

    We're building the house of the future together.