24 #include <netlink/cli/utils.h> 47 lval = strtoul(arg, &endptr, 0);
48 if (endptr == arg || lval == ULONG_MAX)
49 nl_cli_fatal(EINVAL,
"Unable to parse \"%s\", not a number.",
52 return (uint32_t) lval;
55 void nl_cli_print_version(
void)
57 printf(
"libnl tools version %s\n", LIBNL_VERSION);
59 "Copyright (C) 2003-2010 Thomas Graf <tgraf@redhat.com>\n" 61 "This program comes with ABSOLUTELY NO WARRANTY. This is free \n" 62 "software, and you are welcome to redistribute it under certain\n" 63 "conditions. See the GNU General Public License for details.\n" 81 fprintf(stderr,
"Error: ");
85 vfprintf(stderr, fmt, ap);
87 fprintf(stderr,
"\n");
90 #ifdef HAVE_STRERROR_L 91 locale_t loc = newlocale(LC_MESSAGES_MASK,
"", (locale_t)0);
92 if (loc == (locale_t)0) {
94 loc = newlocale(LC_MESSAGES_MASK,
95 "POSIX", (locale_t)0);
96 if (loc == (locale_t)0)
97 buf =
"newlocale() failed";
99 if (loc != (locale_t)0)
100 buf = strerror_l(err, loc);
104 fprintf(stderr,
"%s\n", buf);
105 #ifdef HAVE_STRERROR_L 106 if (loc != (locale_t)0)
114 int nl_cli_connect(
struct nl_sock *sk,
int protocol)
119 nl_cli_fatal(err,
"Unable to connect netlink socket: %s",
125 struct nl_sock *nl_cli_alloc_socket(
void)
127 struct nl_sock *sock;
130 nl_cli_fatal(ENOBUFS,
"Unable to allocate netlink socket");
135 struct nl_addr *nl_cli_addr_parse(
const char *str,
int family)
137 struct nl_addr *addr;
142 str, nl_geterror(err));
147 int nl_cli_parse_dumptype(
const char *str)
149 if (!strcasecmp(str,
"brief"))
151 else if (!strcasecmp(str,
"details") || !strcasecmp(str,
"detailed"))
153 else if (!strcasecmp(str,
"stats"))
156 nl_cli_fatal(EINVAL,
"Invalid dump type \"%s\".\n", str);
161 int nl_cli_confirm(
struct nl_object *obj,
struct nl_dump_params *params,
167 char buf[32] = { 0 };
170 printf(
"Delete? (%c/%c) ",
171 default_yes ?
'Y' :
'y',
172 default_yes ?
'n' :
'N');
174 if (!fgets(buf,
sizeof(buf), stdin)) {
175 fprintf(stderr,
"Error while reading\n.");
179 switch ((answer = tolower(buf[0]))) {
181 answer = default_yes ?
'y' :
'n';
185 return answer ==
'y';
188 fprintf(stderr,
"Invalid input, try again.\n");
195 struct nl_cache *nl_cli_alloc_cache(
struct nl_sock *sock,
const char *name,
196 int (*ac)(
struct nl_sock *,
struct nl_cache **))
198 struct nl_cache *cache;
201 if ((err = ac(sock, &cache)) < 0)
203 name, nl_geterror(err));
210 struct nl_cache *nl_cli_alloc_cache_flags(
struct nl_sock *sock,
211 const char *name,
unsigned int flags,
212 int (*ac)(
struct nl_sock *,
struct nl_cache **,
215 struct nl_cache *cache;
218 if ((err = ac(sock, &cache, flags)) < 0)
220 name, nl_geterror(err));
227 void nl_cli_load_module(
const char *prefix,
const char *name)
229 char path[FILENAME_MAX+1];
231 snprintf(path,
sizeof(path),
"%s/%s/%s.so",
232 PKGLIBDIR, prefix, name);
238 if (!(handle = dlopen(path, RTLD_NOW))) {
239 nl_cli_fatal(ENOENT,
"Unable to load module \"%s\": %s\n",
244 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.