6#include <netlink/cli/utils.h> 
    7#include <netlink/cli/route.h> 
    8#include <netlink/cli/link.h> 
   10#include <linux/rtnetlink.h> 
   12static void print_usage(
void)
 
   14        printf(
"Usage: nl-route-get <addr>\n");
 
   18static void parse_cb(
struct nl_object *obj, 
void *arg)
 
   29static int cb(
struct nl_msg *msg, 
void *arg)
 
   33        if ((err = nl_msg_parse(msg, &parse_cb, NULL)) < 0)
 
   34                nl_cli_fatal(err, 
"Unable to parse object: %s", nl_geterror(err));
 
   39int main(
int argc, 
char *argv[])
 
   45        if (argc < 2 || !strcmp(argv[1], 
"-h"))
 
   48        sock = nl_cli_alloc_socket();
 
   49        nl_cli_connect(sock, NETLINK_ROUTE);
 
   50        nl_cli_link_alloc_cache(sock);
 
   51        nl_cli_route_alloc_cache(sock, 0);
 
   53        dst = nl_cli_addr_parse(argv[1], AF_INET);
 
   65                if (
nlmsg_append(m, &rmsg, 
sizeof(rmsg), NLMSG_ALIGNTO) < 0)
 
int nl_addr_get_family(const struct nl_addr *addr)
Return address family.
 
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.
 
@ NL_CB_VALID
Message is valid.
 
@ NL_CB_CUSTOM
Customized handler specified by the user.
 
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.
 
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
 
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
 
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 nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
 
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.
 
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
 
FILE * dp_fd
File descriptor the dumping output should go to.