|
Packit Service |
f991dd |
/* SPDX-License-Identifier: LGPL-2.1-only */
|
|
Packit Service |
f991dd |
/*
|
|
Packit Service |
f991dd |
* src/idiag-socket-details.c List socket details
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
f991dd |
* modify it under the terms of the GNU General Public License as
|
|
Packit Service |
f991dd |
* published by the Free Software Foundation version 2 of the License.
|
|
Packit Service |
f991dd |
*
|
|
Packit Service |
f991dd |
* Copyright (c) 2013 Sassano Systems LLC <joe@sassanosystems.com>
|
|
Packit Service |
f991dd |
*/
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
#include <netlink/cli/utils.h>
|
|
Packit Service |
f991dd |
#include <netlink/idiag/idiagnl.h>
|
|
Packit Service |
f991dd |
#include <netlink/idiag/msg.h>
|
|
Packit Service |
f991dd |
#include <linux/netlink.h>
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
static void print_usage(void)
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
printf(
|
|
Packit Service |
f991dd |
"Usage: idiag-socket-details [OPTION]\n"
|
|
Packit Service |
f991dd |
"\n"
|
|
Packit Service |
f991dd |
"Options\n"
|
|
Packit Service |
f991dd |
" --summary Show socket detail summary.\n"
|
|
Packit Service |
f991dd |
" --details Show socket details on multiple lines.\n"
|
|
Packit Service |
f991dd |
" --stats Show full socket statistics.\n"
|
|
Packit Service |
f991dd |
" -h, --help Show this help.\n"
|
|
Packit Service |
f991dd |
" -v, --version Show versioning information.\n"
|
|
Packit Service |
f991dd |
);
|
|
Packit Service |
f991dd |
exit(0);
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
int main(int argc, char *argv[])
|
|
Packit Service |
f991dd |
{
|
|
Packit Service |
f991dd |
struct nl_sock *sock;
|
|
Packit Service |
f991dd |
struct nl_cache *idiag_cache;
|
|
Packit Service |
f991dd |
struct nl_dump_params params = {
|
|
Packit Service |
f991dd |
.dp_type = NL_DUMP_LINE,
|
|
Packit Service |
f991dd |
.dp_nl_cb = NULL,
|
|
Packit Service |
f991dd |
.dp_fd = stdout,
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
int err = 0;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
sock = nl_cli_alloc_socket();
|
|
Packit Service |
f991dd |
nl_cli_connect(sock, NETLINK_INET_DIAG);
|
|
Packit Service |
f991dd |
for (;;) {
|
|
Packit Service |
f991dd |
int c, optidx = 0;
|
|
Packit Service |
f991dd |
enum {
|
|
Packit Service |
f991dd |
ARG_SUMMARY = 257,
|
|
Packit Service |
f991dd |
ARG_DETAILS = 258,
|
|
Packit Service |
f991dd |
ARG_STATS = 259,
|
|
Packit Service |
f991dd |
ARG_FAMILY,
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
static struct option long_opts[] = {
|
|
Packit Service |
f991dd |
{ "details", 0, 0, ARG_DETAILS },
|
|
Packit Service |
f991dd |
{ "summary", 0, 0, ARG_SUMMARY },
|
|
Packit Service |
f991dd |
{ "stats", 0, 0, ARG_STATS},
|
|
Packit Service |
f991dd |
{ "help", 0, 0, 'h' },
|
|
Packit Service |
f991dd |
{ "version", 0, 0, 'v' },
|
|
Packit Service |
f991dd |
{ 0, 0, 0, 0 }
|
|
Packit Service |
f991dd |
};
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
c = getopt_long(argc, argv, "hv", long_opts, &optidx);
|
|
Packit Service |
f991dd |
if (c == -1)
|
|
Packit Service |
f991dd |
break;
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
switch (c) {
|
|
Packit Service |
f991dd |
case '?': exit(NLE_INVAL);
|
|
Packit Service |
f991dd |
case ARG_SUMMARY: params.dp_type = NL_DUMP_LINE; break;
|
|
Packit Service |
f991dd |
case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break;
|
|
Packit Service |
f991dd |
case ARG_STATS: params.dp_type = NL_DUMP_STATS; break;
|
|
Packit Service |
f991dd |
case 'h': print_usage(); break;
|
|
Packit Service |
f991dd |
case 'v': nl_cli_print_version(); break;
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
if ((err = idiagnl_msg_alloc_cache(sock, AF_INET, IDIAGNL_SS_ALL,
|
|
Packit Service |
f991dd |
&idiag_cache))) {
|
|
Packit Service |
f991dd |
nl_cli_fatal(err, "Unable to allocate idiag msg cache: %s",
|
|
Packit Service |
f991dd |
nl_geterror(err));
|
|
Packit Service |
f991dd |
}
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
nl_cache_mngt_provide(idiag_cache);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
nl_cache_dump_filter(idiag_cache, ¶ms, NULL);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
nl_cache_mngt_unprovide(idiag_cache);
|
|
Packit Service |
f991dd |
nl_cache_free(idiag_cache);
|
|
Packit Service |
f991dd |
nl_socket_free(sock);
|
|
Packit Service |
f991dd |
|
|
Packit Service |
f991dd |
return 0;
|
|
Packit Service |
f991dd |
}
|