Bif for a new function to calculates haversine distance between two geoip locations

Description

Merge request for:

topic/aashish/haversine

  1.  

    1. ## Calculates haversine distance between two geoip locations
      ##
      ##

    2. lat1, long1, lat2, long2
      ##

    3. Returns: distance in miles

    4. function haversine_distance%(lat1:double, long1:double, lat2:double, long2:double %): double

accompanying bro policy in base/utils/haversine_distance_ip.bro

module GLOBAL;

  1.  

    1. Returns the haversine distance between two IP addresses based on GeoIP

    2. database locations
      ##
      ##

    3. orig: the address of orig connection

    4. resp: the address of resp server

    5. Returns: the GeoIP distance between orig and resp in miles
      function haversine_distance_ip(orig: addr, resp: addr): double

Environment

None

Activity

Show:
Aashish Sharma
June 7, 2016, 6:48 PM

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.

Robin Sommer
June 7, 2016, 7:17 PM
Edited

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

Daniel Thayer
June 7, 2016, 8:10 PM

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).

Daniel Thayer
June 7, 2016, 8:19 PM

Aashish,
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).

Robin Sommer
June 7, 2016, 9:45 PM

ok, I leave it out then

Assignee

Robin Sommer

Reporter

Aashish Sharma

Labels

External issue ID

None

Components

Fix versions

Affects versions

Priority

Low
Configure