return 1;
}
+// Has Flag?
+
+static int Network_has_flag(lua_State* L) {
+ Network* self = luaL_checknetwork(L, 1);
+
+ // Fetch flag
+ int flag = luaL_checknumber(L, 2);
+
+ // Push result
+ lua_pushboolean(L, loc_network_has_flag(self->network, flag));
+
+ return 1;
+}
+
static const struct luaL_Reg Network_functions[] = {
{ "new", Network_new },
{ "get_asn", Network_get_asn },
- { "get_family", Network_get_family },
{ "get_country_code", Network_get_country_code },
+ { "get_family", Network_get_family },
+ { "has_flag", Network_has_flag },
{ "__gc", Network_gc },
{ "__tostring", Network_tostring },
{ NULL, NULL },
db = location.Database.open(ENV_TEST_DATABASE)
-- Perform a lookup
- network = db:lookup("81.3.27.32")
+ network1 = db:lookup("81.3.27.32")
- luaunit.assertEquals(network:get_family(), 2) -- AF_INET
- luaunit.assertEquals(network:get_country_code(), "DE")
- luaunit.assertEquals(network:get_asn(), 24679)
+ luaunit.assertEquals(network1:get_family(), 2) -- AF_INET
+ luaunit.assertEquals(network1:get_country_code(), "DE")
+ luaunit.assertEquals(network1:get_asn(), 24679)
+
+ -- Lookup something else
+ network2 = db:lookup("8.8.8.8")
+ luaunit.assertIsTrue(network2:has_flag(location.NETWORK_FLAG_ANYCAST))
+ luaunit.assertIsFalse(network2:has_flag(location.NETWORK_FLAG_DROP))
end
function test_network()