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

libnl 3.7.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 <netlink/cli/utils.h>
7
8 #define PROC_NETLINK "/proc/net/netlink"
9
10 int main(int argc, char *argv[])
11 {
12 FILE *fd;
13 char buf[2048], p[64];
14
15 fd = fopen(PROC_NETLINK, "re");
16 if (fd == NULL) {
17 perror("fopen");
18 return -1;
19 }
20
21 printf("Address Family PID Groups rmem "
22 "wmem CB refcnt\n");
23
24 while (fgets(buf, sizeof(buf), fd)) {
25 unsigned long sk, cb;
26 int ret, proto, pid, rmem, wmem, refcnt;
27 unsigned int groups;
28
29 ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n",
30 &sk, &proto, &pid, &groups, &rmem, &wmem,
31 &cb, &refcnt);
32 if (ret != 8)
33 continue;
34
35 printf("0x%016lx %-16s %-6d %08x %-6d %-6d 0x%08lx %d\n",
36 sk, nl_nlfamily2str(proto, p, sizeof(p)), pid,
37 groups, rmem, wmem, cb, refcnt);
38 }
39
40 fclose(fd);
41
42 return 0;
43 }