[sr-dev] IPv4 and IPv6 binary comparison
Daniel-Constantin Mierla
daniel at kamailio.org
Thu Apr 28 12:05:37 CEST 2011
On 4/28/11 11:53 AM, Iñaki Baz Castillo wrote:
> 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).
yes, that was the point to compare network addresses with mask,
otherwise '==' can be used for string comparisons, no matter what it is
inside, ip address, username, a.s.o.
Cheers,
Daniel
>
> Obviously under IPv6 binary comparison is needed (this is what my
> function does).
>
>
More information about the sr-dev
mailing list