12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/route.h>
14 #include <netlink/cli/link.h>
16 static void print_usage(
void)
18 printf(
"Usage: nl-route-get <addr>\n");
22 static void parse_cb(
struct nl_object *obj,
void *arg)
33 static int cb(
struct nl_msg *msg,
void *arg)
37 if ((err = nl_msg_parse(msg, &parse_cb, NULL)) < 0)
38 nl_cli_fatal(err,
"Unable to parse object: %s", nl_geterror(err));
43 int main(
int argc,
char *argv[])
49 if (argc < 2 || !strcmp(argv[1],
"-h"))
52 sock = nl_cli_alloc_socket();
53 nl_cli_connect(sock, NETLINK_ROUTE);
54 nl_cli_link_alloc_cache(sock);
55 nl_cli_route_alloc_cache(sock, 0);
57 dst = nl_cli_addr_parse(argv[1], AF_INET);
69 if (
nlmsg_append(m, &rmsg,
sizeof(rmsg), NLMSG_ALIGNTO) < 0)
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
FILE * dp_fd
File descriptor the dumping output should go to.
unsigned int nl_addr_get_prefixlen(const struct nl_addr *addr)
Return prefix length of abstract address object.
int nla_put_addr(struct nl_msg *msg, int attrtype, struct nl_addr *addr)
Add abstract address as unspecific attribute to netlink message.
Customized handler specified by the user.
Dump all attributes but no statistics.
int nl_socket_modify_cb(struct nl_sock *sk, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Modify the callback handler associated with the socket.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
int nl_recvmsgs_default(struct nl_sock *sk)
Receive a set of message from a netlink socket using handlers in nl_sock.
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
int nl_addr_get_family(const struct nl_addr *addr)
Return address family.