24 #include <netlink/cli/utils.h>
40 lval = strtoul(arg, &endptr, 0);
41 if (endptr == arg || lval == ULONG_MAX)
42 nl_cli_fatal(EINVAL,
"Unable to parse \"%s\", not a number.",
45 return (uint32_t) lval;
48 void nl_cli_print_version(
void)
50 printf(
"libnl tools version %s\n", LIBNL_VERSION);
52 "Copyright (C) 2003-2010 Thomas Graf <tgraf@redhat.com>\n"
54 "This program comes with ABSOLUTELY NO WARRANTY. This is free \n"
55 "software, and you are welcome to redistribute it under certain\n"
56 "conditions. See the GNU General Public License for details.\n"
75 fprintf(stderr,
"Error: ");
79 vfprintf(stderr, fmt, ap);
81 fprintf(stderr,
"\n");
83 fprintf(stderr,
"%s\n", strerror_r(err, buf,
sizeof(buf)));
88 int nl_cli_connect(
struct nl_sock *sk,
int protocol)
93 nl_cli_fatal(err,
"Unable to connect netlink socket: %s",
99 struct nl_sock *nl_cli_alloc_socket(
void)
101 struct nl_sock *sock;
104 nl_cli_fatal(ENOBUFS,
"Unable to allocate netlink socket");
109 struct nl_addr *nl_cli_addr_parse(
const char *str,
int family)
111 struct nl_addr *addr;
116 str, nl_geterror(err));
121 int nl_cli_parse_dumptype(
const char *str)
123 if (!strcasecmp(str,
"brief"))
125 else if (!strcasecmp(str,
"details") || !strcasecmp(str,
"detailed"))
127 else if (!strcasecmp(str,
"stats"))
130 nl_cli_fatal(EINVAL,
"Invalid dump type \"%s\".\n", str);
135 int nl_cli_confirm(
struct nl_object *obj,
struct nl_dump_params *params,
141 char buf[32] = { 0 };
144 printf(
"Delete? (%c/%c) ",
145 default_yes ?
'Y' :
'y',
146 default_yes ?
'n' :
'N');
148 if (!fgets(buf,
sizeof(buf), stdin)) {
149 fprintf(stderr,
"Error while reading\n.");
153 switch ((answer = tolower(buf[0]))) {
155 answer = default_yes ?
'y' :
'n';
158 return answer ==
'y';
161 fprintf(stderr,
"Invalid input, try again.\n");
168 struct nl_cache *nl_cli_alloc_cache(
struct nl_sock *sock,
const char *name,
169 int (*ac)(
struct nl_sock *,
struct nl_cache **))
171 struct nl_cache *cache;
174 if ((err = ac(sock, &cache)) < 0)
176 name, nl_geterror(err));
183 void nl_cli_load_module(
const char *prefix,
const char *name)
185 char path[FILENAME_MAX+1];
188 snprintf(path,
sizeof(path),
"%s/%s/%s.so",
189 PKGLIBDIR, prefix, name);
191 if (!(handle = dlopen(path, RTLD_NOW)))
192 nl_cli_fatal(ENOENT,
"Unable to load module \"%s\": %s\n",