[sr-dev] IPv4 and IPv6 binary comparison

Iñaki Baz Castillo ibc at aliax.net
Wed Apr 27 12:50:51 CEST 2011


Hi, AFAIK SR doesn't provide a way to binary compare two IPv6 (correct
me if I'm wrong). About IPv4 comparison, I assume it's compared as a
string:

  if ($rd == "1.2.3.4")

so it works. But in case of IPv6 it would not work as the same IPv6
could take different (but equivalent) representations:

  "1080:0000:0000:0000:0008:0800:200C:417A"
  "1080:0:0:0:8:800:200C:417A"
  "1080::8:800:200C:417A"

I'd like to add a function to perform IPv6 binary comparison (as I've
already coded it in a personal project), could you please tell me in
which module should it take place? I mean something as:

--------------------------------------------------------------------------
  compare_ips(ip1, ip2)

  Returns 1 if both IP's are two equal IPv4 or two equal IPv6.
  Returns -1 if both IP's are valid but not equal.
  Returns -2 if at least one give IP is not a valid IPv4 or IPv6.

  Parameters:
  - ip1: An string of pv containing a IPv4 or IPv6 in text representation.
  - ip2: An string of pv containing a IPv4 or IPv6 in text representation.
--------------------------------------------------------------------------

Thanks.

-- 
Iñaki Baz Castillo
<ibc at aliax.net>



More information about the sr-dev mailing list