2 * nl-list-sockets.c Pretty-print /proc/net/netlink
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
14 #define PROC_NETLINK "/proc/net/netlink"
16 static void print_usage(void)
18 fprintf(stderr, "Usage: nl-list-sockets [<file>]\n");
22 int main(int argc, char *argv[])
25 char buf[2048], p[64];
27 if (argc > 1 && !strcasecmp(argv[1], "-h"))
30 fd = fopen(PROC_NETLINK, "r");
36 printf("Address Family PID Groups rmem wmem " \
39 while (fgets(buf, sizeof(buf), fd)) {
41 int ret, proto, pid, rmem, wmem, refcnt;
44 ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n",
45 &sk, &proto, &pid, &groups, &rmem, &wmem,
50 printf("0x%08lx %-16s %-6d %08x %-6d %-6d 0x%08lx %d\n",
51 sk, nl_nlfamily2str(proto, p, sizeof(p)), pid,
52 groups, rmem, wmem, cb, refcnt);