11 #include <netlink/cli/utils.h> 12 #include <netlink/idiag/idiagnl.h> 13 #include <netlink/idiag/msg.h> 14 #include <linux/netlink.h> 16 static void print_usage(
void)
19 "Usage: idiag-socket-details [OPTION]\n" 22 " --summary Show socket detail summary.\n" 23 " --details Show socket details on multiple lines.\n" 24 " --stats Show full socket statistics.\n" 25 " -h, --help Show this help.\n" 26 " -v, --version Show versioning information.\n" 31 int main(
int argc,
char *argv[])
34 struct nl_cache *idiag_cache;
42 sock = nl_cli_alloc_socket();
43 nl_cli_connect(sock, NETLINK_INET_DIAG);
52 static struct option long_opts[] = {
53 {
"details", 0, 0, ARG_DETAILS },
54 {
"summary", 0, 0, ARG_SUMMARY },
55 {
"stats", 0, 0, ARG_STATS},
56 {
"help", 0, 0,
'h' },
57 {
"version", 0, 0,
'v' },
61 c = getopt_long(argc, argv,
"hv", long_opts, &optidx);
66 case '?': exit(NLE_INVAL);
70 case 'h': print_usage();
break;
71 case 'v': nl_cli_print_version();
break;
77 nl_cli_fatal(err,
"Unable to allocate idiag msg cache: %s",
Dump object briefly on one line.
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.
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).
Dump all attributes but no statistics.
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_cache_free(struct nl_cache *cache)
Free a cache.
#define IDIAGNL_SS_ALL
Macro to represent all socket states.
void nl_socket_free(struct nl_sock *sk)
Free a netlink socket.
void nl_cache_mngt_unprovide(struct nl_cache *cache)
Unprovide a cache for global use.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Dump all attributes including statistics.