libnl: /data/src/libnl3/src/nl-list-sockets.c Source File

libnl 3.10.0

nl-list-sockets.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2009 Thomas Graf <tgraf@suug.ch>
4 */
5
6#include "nl-default.h"
7
8#include <netlink/cli/utils.h>
9
10#define PROC_NETLINK "/proc/net/netlink"
11
12int main(int argc, char *argv[])
13{
14 FILE *fd;
15 char buf[2048], p[64];
16
17 fd = fopen(PROC_NETLINK, "re");
18 if (fd == NULL) {
19 perror("fopen");
20 return -1;
21 }
22
23 printf("Address Family PID Groups rmem "
24 "wmem CB refcnt\n");
25
26 while (fgets(buf, sizeof(buf), fd)) {
27 unsigned long sk, cb;
28 int ret, proto, pid, rmem, wmem, refcnt;
29 unsigned int groups;
30
31 ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n",
32 &sk, &proto, &pid, &groups, &rmem, &wmem,
33 &cb, &refcnt);
34 if (ret != 8)
35 continue;
36
37 printf("0x%016lx %-16s %-6d %08x %-6d %-6d 0x%08lx %d\n",
38 sk, nl_nlfamily2str(proto, p, sizeof(p)), pid,
39 groups, rmem, wmem, cb, refcnt);
40 }
41
42 fclose(fd);
43
44 return 0;
45}