summaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorThomas Graf <tgr@lsx.localdomain>2008-05-22 22:02:02 (GMT)
committerThomas Graf <tgr@lsx.localdomain>2008-05-22 22:02:02 (GMT)
commit10cf5a586c149fdb7e2639000dbfae5e6f8522a5 (patch)
tree399a15d767fd15b85c92be2e70b748645eeb983e /src/utils.c
parent337fbd24cad1f5cf9c8b4287a75f2c69f088adce (diff)
downloadlibnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.zip
libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.tar.gz
libnl-10cf5a586c149fdb7e2639000dbfae5e6f8522a5.tar.bz2
New set of libnl tools
Converts all tools to the API changes and improves the useability by introducing regular options and long options.
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c80
1 files changed, 14 insertions, 66 deletions
diff --git a/src/utils.c b/src/utils.c
index f7fd648..95c9329 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -13,6 +13,18 @@
#include <stdlib.h>
+uint32_t parse_u32(const char *arg)
+{
+ unsigned long lval;
+ char *endptr;
+
+ lval = strtoul(arg, &endptr, 0);
+ if (endptr == arg || lval == ULONG_MAX)
+ fatal(EINVAL, "Unable to parse \"%s\", not a number.", arg);
+
+ return (uint32_t) lval;
+}
+
void nlt_print_version(void)
{
printf("libnl tools version %s\n", LIBNL_VERSION);
@@ -112,8 +124,8 @@ int nlt_confirm(struct nl_object *obj, struct nl_dump_params *params,
return answer == 'y';
}
-static struct nl_cache *alloc_cache(struct nl_sock *sock, const char *name,
- int (*ac)(struct nl_sock *, struct nl_cache **))
+struct nl_cache *alloc_cache(struct nl_sock *sock, const char *name,
+ int (*ac)(struct nl_sock *, struct nl_cache **))
{
struct nl_cache *cache;
int err;
@@ -127,67 +139,3 @@ static struct nl_cache *alloc_cache(struct nl_sock *sock, const char *name,
return cache;
}
-struct nl_cache *nlt_alloc_link_cache(struct nl_sock *sk)
-{
- return alloc_cache(sk, "link", rtnl_link_alloc_cache);
-}
-
-struct nl_cache *nlt_alloc_addr_cache(struct nl_sock *sk)
-{
- return alloc_cache(sk, "address", rtnl_addr_alloc_cache);
-}
-
-struct rtnl_addr *nlt_alloc_addr(void)
-{
- struct rtnl_addr *addr;
-
- addr = rtnl_addr_alloc();
- if (!addr)
- fatal(ENOMEM, "Unable to allocate address object");
-
- return addr;
-}
-
-struct nl_cache *nltool_alloc_neigh_cache(struct nl_sock *sk)
-{
- return alloc_cache(sk, "neighbour", rtnl_neigh_alloc_cache);
-}
-
-struct nl_cache *nltool_alloc_neightbl_cache(struct nl_sock *sk)
-{
- return alloc_cache(sk, "neighbour table", rtnl_neightbl_alloc_cache);
-}
-
-struct nl_cache *nltool_alloc_route_cache(struct nl_sock *sk, int flags)
-{
- struct nl_cache *cache;
- int err;
-
- if ((err = rtnl_route_alloc_cache(sk, AF_UNSPEC, flags, &cache)) < 0)
- fatal(err, "Unable to allocate route cache: %s\n",
- nl_geterror(err));
-
- nl_cache_mngt_provide(cache);
-
- return cache;
-}
-
-struct nl_cache *nltool_alloc_rule_cache(struct nl_sock *sk)
-{
- struct nl_cache *cache;
- int err;
-
- if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0)
- fatal(err, "Unable to allocate routing rule cache: %s\n",
- nl_geterror(err));
-
- nl_cache_mngt_provide(cache);
-
- return cache;
-}
-
-struct nl_cache *nltool_alloc_qdisc_cache(struct nl_sock *sk)
-{
- return alloc_cache(sk, "queueing disciplines", rtnl_qdisc_alloc_cache);
-}
-