6#include <netlink/cli/utils.h> 
    7#include <netlink/cli/link.h> 
    8#include <netlink/cli/mdb.h> 
   10#include <linux/rtnetlink.h> 
   13        enum rtnetlink_groups gr_id;
 
   16        { RTNLGRP_LINK, 
"link" },
 
   17        { RTNLGRP_NOTIFY, 
"notify" },
 
   18        { RTNLGRP_NEIGH, 
"neigh" },
 
   20        { RTNLGRP_IPV4_IFADDR, 
"ipv4-ifaddr" },
 
   21        { RTNLGRP_IPV4_MROUTE, 
"ipv4-mroute" },
 
   22        { RTNLGRP_IPV4_ROUTE, 
"ipv4-route" },
 
   23        { RTNLGRP_IPV6_IFADDR, 
"ipv6-ifaddr" },
 
   24        { RTNLGRP_IPV6_MROUTE, 
"ipv6-mroute" },
 
   25        { RTNLGRP_IPV6_ROUTE, 
"ipv6-route" },
 
   26        { RTNLGRP_IPV6_IFINFO, 
"ipv6-ifinfo" },
 
   27        { RTNLGRP_DECnet_IFADDR, 
"decnet-ifaddr" },
 
   28        { RTNLGRP_DECnet_ROUTE, 
"decnet-route" },
 
   29        { RTNLGRP_IPV6_PREFIX, 
"ipv6-prefix" },
 
   30        { RTNLGRP_IPV4_NETCONF, 
"ipv4-netconf" },
 
   31        { RTNLGRP_IPV6_NETCONF, 
"ipv6-netconf" },
 
   32        { RTNLGRP_MPLS_NETCONF, 
"mpls-netconf" },
 
   33        { RTNLGRP_MDB, 
"mdb" },
 
   34        { RTNLGRP_NONE, NULL }
 
   37static void obj_input(
struct nl_object *obj, 
void *arg)
 
   42static int event_input(
struct nl_msg *msg, 
void *arg)
 
   44        if (nl_msg_parse(msg, &obj_input, arg) < 0)
 
   45                fprintf(stderr, 
"<<EVENT>> Unknown message type\n");
 
   51static void print_usage(
void)
 
   56        "Usage: nl-monitor [OPTION] [<groups>]\n" 
   59        " -d, --debug=LEVEL     Set libnl debug level { 0 - 7 }\n" 
   60        " -f, --format=TYPE     Output format { brief | details | stats }\n" 
   61        " -h, --help            Show this help.\n" 
   64        printf(
"Known groups:");
 
   65        for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++)
 
   66                printf(
" %s", known_groups[i].gr_name);
 
   71int main(
int argc, 
char *argv[])
 
   83        sock = nl_cli_alloc_socket();
 
   89                static struct option long_opts[] = {
 
   90                        { 
"debug",  1, 0, 
'd' },
 
   91                        { 
"format", 1, 0, 
'f' },
 
   92                        { 
"help",   0, 0, 
'h' },
 
   96                c = getopt_long(argc, argv, 
"d:f:h", long_opts, &optidx);
 
  105                        dp.
dp_type = nl_cli_parse_dumptype(optarg);
 
  113        nl_cli_connect(sock, NETLINK_ROUTE);
 
  115        for (idx = optind; argc > idx; idx++) {
 
  116                for (i = 0; known_groups[i].gr_id != RTNLGRP_NONE; i++) {
 
  117                        if (!strcmp(argv[idx], known_groups[i].gr_name)) {
 
  119                                if ((err = nl_socket_add_membership(sock, known_groups[i].gr_id)) < 0) {
 
  127                if (known_groups[i].gr_id == RTNLGRP_NONE)
 
  128                        fprintf(stderr, 
"Warning: Unknown group: %s\n", argv[idx]);
 
  131        nl_cli_link_alloc_cache(sock);
 
  142                retval = select(fd+1, &rfds, NULL, NULL, NULL);
 
@ NL_STOP
Stop parsing altogether and discard remaining messages.
 
@ 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.
 
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_socket_get_fd(const struct nl_sock *sk)
Return the file descriptor of the backing socket.
 
void nl_socket_disable_seq_check(struct nl_sock *sk)
Disable sequence number checking.
 
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.
 
int nl_debug
Global variable indicating the desired level of debugging output.
 
@ NL_DUMP_STATS
Dump all attributes including statistics.
 
enum nl_dump_type dp_type
Specifies the type of dump that is requested.