6#include <netlink/cli/utils.h>
7#include <netlink/cli/addr.h>
8#include <netlink/cli/link.h>
10#include <linux/netlink.h>
14static void print_usage(
void)
17"Usage: nl-addr-add [OPTION]... [ADDRESS]\n"
20" --replace Replace the address if it exists.\n"
21" -q, --quiet Do not print informal notifications.\n"
22" -h, --help Show this help.\n"
23" -v, --version Show versioning information.\n"
26" -a, --local=ADDR Address to be considered local.\n"
27" -d, --dev=DEV Device the address should be assigned to.\n"
28" --family=FAMILY Address family (normally autodetected).\n"
29" --broadcast=ADDR Broadcast address of network (IPv4).\n"
30" --peer=ADDR Peer address (IPv4).\n"
31" --label=STRING Additional address label (IPv4).\n"
32" --scope=SCOPE Scope of local address (IPv4).\n"
33" --preferred=TIME Preferred lifetime (IPv6).\n"
34" --valid=TIME Valid lifetime (IPv6).\n"
40int main(
int argc,
char *argv[])
43 struct rtnl_addr *addr;
44 struct nl_cache *link_cache;
49 int err, nlflags = NLM_F_CREATE;
51 sock = nl_cli_alloc_socket();
52 nl_cli_connect(sock, NETLINK_ROUTE);
53 link_cache = nl_cli_link_alloc_cache(sock);
54 addr = nl_cli_addr_alloc();
68 static struct option long_opts[] = {
69 {
"replace", 0, 0, ARG_REPLACE },
70 {
"quiet", 0, 0,
'q' },
71 {
"help", 0, 0,
'h' },
72 {
"version", 0, 0,
'v' },
73 {
"local", 1, 0,
'a' },
75 {
"family", 1, 0, ARG_FAMILY },
76 {
"label", 1, 0, ARG_LABEL },
77 {
"peer", 1, 0, ARG_PEER },
78 {
"scope", 1, 0, ARG_SCOPE },
79 {
"broadcast", 1, 0, ARG_BROADCAST },
80 {
"preferred", 1, 0, ARG_PREFERRED },
81 {
"valid", 1, 0, ARG_VALID },
85 c = getopt_long(argc, argv,
"qhva:d:", long_opts, &optidx);
90 case '?': exit(NLE_INVAL);
91 case ARG_REPLACE: nlflags |= NLM_F_REPLACE;
break;
92 case 'q': quiet = 1;
break;
93 case 'h': print_usage();
break;
94 case 'v': nl_cli_print_version();
break;
95 case 'a': nl_cli_addr_parse_local(addr, optarg);
break;
96 case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg);
break;
97 case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg);
break;
98 case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg);
break;
99 case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg);
break;
100 case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg);
break;
101 case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg);
break;
102 case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg);
break;
103 case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg);
break;
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_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request addition of new address.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.