6#include <netlink/cli/utils.h>
7#include <netlink/cli/addr.h>
8#include <netlink/cli/link.h>
10#include <linux/netlink.h>
12static struct nl_sock *sock;
13static int interactive = 0, default_yes = 0, quiet = 0;
14static int deleted = 0;
16static void print_usage(
void)
19"Usage: nl-addr-delete [OPTION]... [ADDRESS]\n"
22" -i, --interactive Run interactively.\n"
23" --yes Set default answer to yes.\n"
24" -q, --quiet Do not print informal notifications.\n"
25" -h, --help Show this help.\n"
26" -v, --version Show versioning information.\n"
29" -a, --local=ADDR Local address.\n"
30" -d, --dev=DEV Associated network device.\n"
31" --family=FAMILY Family of local address.\n"
32" --label=STRING Address label (IPv4).\n"
33" --peer=ADDR Peer address (IPv4).\n"
34" --scope=SCOPE Address scope (IPv4).\n"
35" --broadcast=ADDR Broadcast address of network (IPv4).\n"
36" --valid-lifetime=TS Valid lifetime before route expires (IPv6).\n"
37" --preferred=TIME Preferred lifetime (IPv6).\n"
38" --valid=TIME Valid lifetime (IPv6).\n"
44static void delete_cb(
struct nl_object *obj,
void *arg)
46 struct rtnl_addr *addr = nl_object_priv(obj);
53 if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
68int main(
int argc,
char *argv[])
70 struct rtnl_addr *addr;
71 struct nl_cache *link_cache, *addr_cache;
73 sock = nl_cli_alloc_socket();
74 nl_cli_connect(sock, NETLINK_ROUTE);
75 link_cache = nl_cli_link_alloc_cache(sock);
76 addr_cache = nl_cli_addr_alloc_cache(sock);
77 addr = nl_cli_addr_alloc();
91 static struct option long_opts[] = {
92 {
"interactive", 0, 0,
'i' },
93 {
"yes", 0, 0, ARG_YES },
94 {
"quiet", 0, 0,
'q' },
95 {
"help", 0, 0,
'h' },
96 {
"version", 0, 0,
'v' },
97 {
"local", 1, 0,
'a' },
99 {
"family", 1, 0, ARG_FAMILY },
100 {
"label", 1, 0, ARG_LABEL },
101 {
"peer", 1, 0, ARG_PEER },
102 {
"scope", 1, 0, ARG_SCOPE },
103 {
"broadcast", 1, 0, ARG_BROADCAST },
104 {
"preferred", 1, 0, ARG_PREFERRED },
105 {
"valid", 1, 0, ARG_VALID },
109 c = getopt_long(argc, argv,
"iqhva:d:", long_opts, &optidx);
114 case 'i': interactive = 1;
break;
115 case ARG_YES: default_yes = 1;
break;
116 case 'q': quiet = 1;
break;
117 case 'h': print_usage();
break;
118 case 'v': nl_cli_print_version();
break;
119 case 'a': nl_cli_addr_parse_local(addr, optarg);
break;
120 case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg);
break;
121 case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg);
break;
122 case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg);
break;
123 case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg);
break;
124 case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg);
break;
125 case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg);
break;
126 case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg);
break;
127 case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg);
break;
134 printf(
"Deleted %d addresses\n", deleted);
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
int rtnl_addr_delete(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request deletion of an address.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.