6#include <netlink/cli/utils.h>
7#include <netlink/idiag/idiagnl.h>
8#include <netlink/idiag/msg.h>
9#include <linux/netlink.h>
11static void print_usage(
void)
14"Usage: idiag-socket-details [OPTION]\n"
17" --summary Show socket detail summary.\n"
18" --details Show socket details on multiple lines.\n"
19" --stats Show full socket statistics.\n"
20" -h, --help Show this help.\n"
21" -v, --version Show versioning information.\n"
26int main(
int argc,
char *argv[])
29 struct nl_cache *idiag_cache;
37 sock = nl_cli_alloc_socket();
38 nl_cli_connect(sock, NETLINK_INET_DIAG);
47 static struct option long_opts[] = {
48 {
"details", 0, 0, ARG_DETAILS },
49 {
"summary", 0, 0, ARG_SUMMARY },
50 {
"stats", 0, 0, ARG_STATS},
51 {
"help", 0, 0,
'h' },
52 {
"version", 0, 0,
'v' },
56 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
61 case '?': exit(NLE_INVAL);
65 case 'h': print_usage();
break;
66 case 'v': nl_cli_print_version();
break;
72 nl_cli_fatal(err,
"Unable to allocate idiag msg cache: %s",
void nl_cache_mngt_unprovide(struct nl_cache *cache)
Unprovide a cache for global use.
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
void nl_cache_free(struct nl_cache *cache)
Free a cache.
void nl_cache_dump_filter(struct nl_cache *cache, struct nl_dump_params *params, struct nl_object *filter)
Dump all elements of a cache (filtered).
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
#define IDIAGNL_SS_ALL
Macro to represent all socket states.
int idiagnl_msg_alloc_cache(struct nl_sock *sk, int family, int states, struct nl_cache **result)
Build an inetdiag cache to hold socket state information.
void nl_socket_free(struct nl_sock *sk)
Free a netlink socket.
@ NL_DUMP_STATS
Dump all attributes including statistics.
@ NL_DUMP_LINE
Dump object briefly on one line.
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.