X-Git-Url: http://git.onelab.eu/?p=libnl.git;a=blobdiff_plain;f=src%2Fnl-list-sockets.c;fp=src%2Fnl-list-sockets.c;h=9a1333c86b0d044bf5bd00fdcdaf14c94150ea87;hp=0000000000000000000000000000000000000000;hb=4cee2ecb3b8afa0637e6f5fe4c57985a4bc740ff;hpb=2df2fbe518d5a221ce6e3ee88a3fb23fb1b94b27 diff --git a/src/nl-list-sockets.c b/src/nl-list-sockets.c new file mode 100644 index 0000000..9a1333c --- /dev/null +++ b/src/nl-list-sockets.c @@ -0,0 +1,58 @@ +/* + * nl-list-sockets.c Pretty-print /proc/net/netlink + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2006 Thomas Graf + */ + +#include "utils.h" + +#define PROC_NETLINK "/proc/net/netlink" + +static void print_usage(void) +{ + fprintf(stderr, "Usage: nl-list-sockets []\n"); + exit(1); +} + +int main(int argc, char *argv[]) +{ + FILE *fd; + char buf[2048], p[64]; + + if (argc > 1 && !strcasecmp(argv[1], "-h")) + print_usage(); + + fd = fopen(PROC_NETLINK, "r"); + if (fd == NULL) { + perror("fopen"); + return -1; + } + + printf("Address Family PID Groups rmem wmem " \ + "CB refcnt\n"); + + while (fgets(buf, sizeof(buf), fd)) { + unsigned long sk, cb; + int ret, proto, pid, rmem, wmem, refcnt; + uint32_t groups; + + ret = sscanf(buf, "%lx %d %d %08x %d %d %lx %d\n", + &sk, &proto, &pid, &groups, &rmem, &wmem, + &cb, &refcnt); + if (ret != 8) + continue; + + printf("0x%08lx %-16s %-6d %08x %-6d %-6d 0x%08lx %d\n", + sk, nl_nlfamily2str(proto, p, sizeof(p)), pid, + groups, rmem, wmem, cb, refcnt); + } + + fclose(fd); + + return 0; +}