Merge request for:
## Calculates haversine distance between two geoip locations
lat1, long1, lat2, long2
Returns: distance in miles
function haversine_distance%(lat1:double, long1:double, lat2:double, long2:double %): double
accompanying bro policy in base/utils/haversine_distance_ip.bro
Returns the haversine distance between two IP addresses based on GeoIP
orig: the address of orig connection
resp: the address of resp server
Returns: the GeoIP distance between orig and resp in miles
function haversine_distance_ip(orig: addr, resp: addr): double
I was looking at it now and realize that instead of lat1 and lat2 in radians I was using lat1 and lat2 in degree later down in the formula - that was wrong.
I take thats what you identified ?
I have a local fix too, but I trust your code is much cleaner.
Daniel, what's the output for the berkeley/munich distance above for you? I'm wondering if that's stable enough across systems to include as a test case as well. I get 5848.082821
The Berkeley/Munich distance is actually in the test baseline: 5848.1 miles
I didn't include any tests of the haversine_distance_ip function (which converts IP
addrs to distance), because I wondered if the results would be consistent on different
systems and over time. My tests are for the haversine_distance function, which
takes lat./long. and computes distance (which should get the same result on any
system, as it doesn't use libgeoip at all).
Yes, you forgot to convert to radians. I also added a check to make sure that the results
from the lookup_location BIF actually contain lat./long. data (if not, then I'm just returning -1
from the haversine_distance_ip function).
ok, I leave it out then