/** * Allocate address cache and fill in all configured addresses * @arg handle Netlink handle. * * Allocates a new address cache, initializes it properly and updates it * to include all addresses currently configured in the kernel. * * @note Free the memory after usage. * @return Newly allocated cache or NULL if an error occured. */ struct nl_cache *rtnl_addr_alloc_cache(struct nl_handle *handle) { struct nl_cache *cache; cache = nl_cache_alloc_from_ops(&rtnl_addr_ops); if (!cache) return NULL; if (nl_cache_update(handle, cache) < 0) { nl_cache_free(cache); return NULL; } return cache; }
/** * Build a neighbour cache including all neighbours currently configured in the kernel. * @arg handle netlink handle * * Allocates a new neighbour cache, initializes it properly and updates it * to include all neighbours currently configured in the kernel. * * @note The caller is responsible for destroying and freeing the * cache after using it. (nl_cache_destroy_and_free()) * @return The new cache or NULL if an error occured. */ struct nl_cache * rtnl_neigh_build_cache(struct nl_handle *handle) { struct nl_cache * cache = calloc(1, sizeof(*cache)); if (cache == NULL) return NULL; cache->c_type = RTNL_NEIGH; cache->c_type_size = sizeof(struct rtnl_neigh); cache->c_ops = &rtnl_neigh_ops; if (nl_cache_update(handle, cache) < 0) { free(cache); return NULL; } return cache; }