[sr-dev] IPv4 and IPv6 binary comparison

Iñaki Baz Castillo ibc at aliax.net
Thu Apr 28 11:53:03 CEST 2011


2011/4/28 Daniel-Constantin Mierla <daniel at kamailio.org>:
> Btw, when was the idea that IP comparison is string comparison thrown here,
> I missed any email?!? To be sure the comparison is done right, then the
> string with the IPs have to be converted to binary and the results compared.

The point is that IPv4 comparisons are valid as a pure string
comparison. Note that being strict, the following IPv4 is not valid:

  "1.2.3.04"

See RFC 5954 "Essential Correction for IPv6 ABNF and URI Comparison in
RFC 3261":

     IPv4address   = dec-octet "." dec-octet "." dec-octet "." dec-octet
     dec-octet     = DIGIT                 ; 0-9
                    / %x31-39 DIGIT         ; 10-99
                    / "1" 2DIGIT            ; 100-199
                    / "2" %x30-34 DIGIT     ; 200-249
                    / "25" %x30-35          ; 250-255


So comparing two IPv4 as pure strings would work (except if you want
to perform network comparison with mask and so).

Obviously under IPv6 binary comparison is needed (this is what my
function does).


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



More information about the sr-dev mailing list