25 #include <netlink/cli/utils.h> 48 lval = strtoul(arg, &endptr, 0);
49 if (endptr == arg || lval == ULONG_MAX)
50 nl_cli_fatal(EINVAL,
"Unable to parse \"%s\", not a number.",
53 return (uint32_t) lval;
56 void nl_cli_print_version(
void)
58 printf(
"libnl tools version %s\n", LIBNL_VERSION);
60 "Copyright (C) 2003-2010 Thomas Graf <tgraf@redhat.com>\n" 62 "This program comes with ABSOLUTELY NO WARRANTY. This is free \n" 63 "software, and you are welcome to redistribute it under certain\n" 64 "conditions. See the GNU General Public License for details.\n" 82 fprintf(stderr,
"Error: ");
86 vfprintf(stderr, fmt, ap);
88 fprintf(stderr,
"\n");
91 #ifdef HAVE_STRERROR_L 92 locale_t loc = newlocale(LC_MESSAGES_MASK,
"", (locale_t)0);
93 if (loc == (locale_t)0) {
95 loc = newlocale(LC_MESSAGES_MASK,
96 "POSIX", (locale_t)0);
97 if (loc == (locale_t)0)
98 buf =
"newlocale() failed";
100 if (loc != (locale_t)0)
101 buf = strerror_l(err, loc);
105 fprintf(stderr,
"%s\n", buf);
106 #ifdef HAVE_STRERROR_L 107 if (loc != (locale_t)0)
115 int nl_cli_connect(
struct nl_sock *sk,
int protocol)
120 nl_cli_fatal(err,
"Unable to connect netlink socket: %s",
126 struct nl_sock *nl_cli_alloc_socket(
void)
128 struct nl_sock *sock;
131 nl_cli_fatal(ENOBUFS,
"Unable to allocate netlink socket");
136 struct nl_addr *nl_cli_addr_parse(
const char *str,
int family)
138 struct nl_addr *addr;
143 str, nl_geterror(err));
148 int nl_cli_parse_dumptype(
const char *str)
150 if (!strcasecmp(str,
"brief"))
152 else if (!strcasecmp(str,
"details") || !strcasecmp(str,
"detailed"))
154 else if (!strcasecmp(str,
"stats"))
157 nl_cli_fatal(EINVAL,
"Invalid dump type \"%s\".\n", str);
162 int nl_cli_confirm(
struct nl_object *obj,
struct nl_dump_params *params,
168 char buf[32] = { 0 };
171 printf(
"Delete? (%c/%c) ",
172 default_yes ?
'Y' :
'y',
173 default_yes ?
'n' :
'N');
175 if (!fgets(buf,
sizeof(buf), stdin)) {
176 fprintf(stderr,
"Error while reading\n.");
180 switch ((answer = tolower(buf[0]))) {
182 answer = default_yes ?
'y' :
'n';
186 return answer ==
'y';
189 fprintf(stderr,
"Invalid input, try again.\n");
196 struct nl_cache *nl_cli_alloc_cache(
struct nl_sock *sock,
const char *name,
197 int (*ac)(
struct nl_sock *,
struct nl_cache **))
199 struct nl_cache *cache;
202 if ((err = ac(sock, &cache)) < 0)
204 name, nl_geterror(err));
211 struct nl_cache *nl_cli_alloc_cache_flags(
struct nl_sock *sock,
212 const char *name,
unsigned int flags,
213 int (*ac)(
struct nl_sock *,
struct nl_cache **,
216 struct nl_cache *cache;
219 if ((err = ac(sock, &cache, flags)) < 0)
221 name, nl_geterror(err));
228 void nl_cli_load_module(
const char *prefix,
const char *name)
230 char path[FILENAME_MAX+1];
232 snprintf(path,
sizeof(path),
"%s/%s/%s.so",
233 PKGLIBDIR, prefix, name);
239 if (!(handle = dlopen(path, RTLD_NOW))) {
240 nl_cli_fatal(ENOENT,
"Unable to load module \"%s\": %s\n",
245 nl_cli_fatal(ENOTSUP,
"Unable to load module \"%s\": built without dynamic libraries support\n",
Dump object briefly on one line.
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
int nl_addr_parse(const char *addrstr, int hint, struct nl_addr **result)
Allocate abstract address based on character string.
Dump all attributes but no statistics.
struct nl_sock * nl_socket_alloc(void)
Allocate new netlink socket.
int nl_connect(struct nl_sock *sk, int protocol)
Create file descriptor and bind socket.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Dump all attributes including statistics.