2 * src/utils.c Utilities
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
16 int nltool_init(int argc, char *argv[])
21 int nltool_connect(struct nl_handle *nlh, int protocol)
25 err = nl_connect(nlh, protocol);
27 fprintf(stderr, "Unable to connect netlink socket%s\n",
33 struct nl_handle *nltool_alloc_handle(void)
35 return nl_handle_alloc();
38 struct nl_addr *nltool_addr_parse(const char *str)
42 addr = nl_addr_parse(str, AF_UNSPEC);
44 fprintf(stderr, "Unable to parse address \"%s\": %s\n",
50 int nltool_parse_dumptype(const char *str)
52 if (!strcasecmp(str, "brief"))
54 else if (!strcasecmp(str, "detailed"))
56 else if (!strcasecmp(str, "stats"))
58 else if (!strcasecmp(str, "xml"))
60 else if (!strcasecmp(str, "env"))
63 fprintf(stderr, "Invalid dump type \"%s\".\n", str);
68 struct nl_cache *nltool_alloc_link_cache(struct nl_handle *nlh)
70 struct nl_cache *cache;
72 cache = rtnl_link_alloc_cache(nlh);
74 fprintf(stderr, "Unable to retrieve link cache: %s\n",
77 nl_cache_mngt_provide(cache);
82 struct nl_cache *nltool_alloc_addr_cache(struct nl_handle *nlh)
84 struct nl_cache *cache;
86 cache = rtnl_addr_alloc_cache(nlh);
88 fprintf(stderr, "Unable to retrieve address cache: %s\n",
91 nl_cache_mngt_provide(cache);
96 struct nl_cache *nltool_alloc_neigh_cache(struct nl_handle *nlh)
98 struct nl_cache *cache;
100 cache = rtnl_neigh_alloc_cache(nlh);
102 fprintf(stderr, "Unable to retrieve neighbour cache: %s\n",
105 nl_cache_mngt_provide(cache);
110 struct nl_cache *nltool_alloc_neightbl_cache(struct nl_handle *nlh)
112 struct nl_cache *cache;
114 cache = rtnl_neightbl_alloc_cache(nlh);
116 fprintf(stderr, "Unable to retrieve neighbour table "
117 "cache: %s\n", nl_geterror());
119 nl_cache_mngt_provide(cache);
124 struct nl_cache *nltool_alloc_route_cache(struct nl_handle *nlh)
126 struct nl_cache *cache;
128 cache = rtnl_route_alloc_cache(nlh);
130 fprintf(stderr, "Unable to retrieve route cache: %s\n",
133 nl_cache_mngt_provide(cache);
138 struct nl_cache *nltool_alloc_rule_cache(struct nl_handle *nlh)
140 struct nl_cache *cache;
142 cache = rtnl_rule_alloc_cache(nlh);
144 fprintf(stderr, "Unable to retrieve rule cache: %s\n",
147 nl_cache_mngt_provide(cache);
152 struct nl_cache *nltool_alloc_qdisc_cache(struct nl_handle *nlh)
154 struct nl_cache *cache;
156 cache = rtnl_qdisc_alloc_cache(nlh);
158 fprintf(stderr, "Unable to retrieve qdisc cache: %s\n",
161 nl_cache_mngt_provide(cache);
166 struct nl_cache *nltool_alloc_genl_family_cache(struct nl_handle *nlh)
168 struct nl_cache *cache;
170 cache = genl_ctrl_alloc_cache(nlh);
172 fprintf(stderr, "Unable to retrieve genl family cache: %s\n",
175 nl_cache_mngt_provide(cache);