[sr-dev] IPv4 and IPv6 binary comparison

Daniel-Constantin Mierla daniel at kamailio.org
Thu Apr 28 11:35:23 CEST 2011



On 4/28/11 11:27 AM, Iñaki Baz Castillo wrote:
> 2011/4/28 Henning Westerholt<henning.westerholt at 1und1.de>:
>> Hello,
>>
>> i like to also not see much more of this small utility modules, in the end its
>> just a text operation, as you've said.
> Ok. I'm coding it right now in a new module but just for testing
> purposes (which is easier than modify existing core parts).
>
>
>> Another question, have you thought about extending the existing "equals"
>> operator that it works also for IPv6 address? Just like for IPv4 addresses
>> where it already understands network masks, e.g.:
>>
>> if ($si == 192.168.1.1/32) {..}
>> if ($si == 192.168.1.1) {..}
>>
>> it could do this binary comparison inside as well for v6.
> Interesting. However, in case the second argument is a pv (i.e.
> retrieved from a DB) "equal" operator would not work as expected, am I
> right?
As mentioned in previous email, not even the above syntax should work as 
expected -- it would be a surprise, maybe due to ser enhancements. But a 
pseudo-variable in the left side implies string or integer comparison. 
But for sure when it is a PV in the right side, then it is not working.

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.

Cheers,
Daniel

> This is the reason I'm coding a function "compare_ips" which allow
> IPv4, IPv6, IPv6-reference (string or pv).
>
> Maybe another function could be created:   is_ip_in(IP, NETWORK)
>



More information about the sr-dev mailing list