summaryrefslogtreecommitdiff
path: root/proto_nlmsg.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-07-17 14:55:15 +0200
committerTobias Klauser <tklauser@distanz.ch>2015-07-17 14:55:15 +0200
commitc5ff2059f619ac91c14d55412314d1c67de6a593 (patch)
tree18c324c5d2bbbe9a913ae693ff75b109d050a1e5 /proto_nlmsg.c
parent5d6d5f85d8ed49698eb3d790308e05a50b784c54 (diff)
flowtop, netsniff-ng: Move process name extraction to own function
flowtop and the netsniff-ng's netlink message dissector both need to get the process name for a pid from /proc/<pid>/exe, thus move that functionality to an own function. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'proto_nlmsg.c')
-rw-r--r--proto_nlmsg.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/proto_nlmsg.c b/proto_nlmsg.c
index 22d50a8..1dde5e1 100644
--- a/proto_nlmsg.c
+++ b/proto_nlmsg.c
@@ -17,6 +17,7 @@
#include "dev.h"
#include "pkt_buff.h"
+#include "proc.h"
#include "proto.h"
#include "protos.h"
#include "timer.h"
@@ -226,7 +227,7 @@ static void rtnl_print_ifinfo(struct nlmsghdr *hdr)
uint32_t attrs_len = IFLA_PAYLOAD(hdr);
char flags[256];
char if_addr[64] = {};
- char *af_link = "Unknown";
+ char *af_link = "unknown";
if (ifi->ifi_family == AF_UNSPEC)
af_link = "unspec";
@@ -717,14 +718,8 @@ static void nlmsg_print(uint16_t family, struct nlmsghdr *hdr)
* PID and the information will not be printed.
*/
if (hdr->nlmsg_pid != 0) {
- char path[1024];
- int ret;
-
- snprintf(path, sizeof(path), "/proc/%u/exe", hdr->nlmsg_pid);
- ret = readlink(path, procname, sizeof(procname) - 1);
- if (ret < 0)
- ret = 0;
- procname[ret] = '\0';
+ if (proc_get_cmdline(hdr->nlmsg_pid, procname, sizeof(procname)) < 0)
+ snprintf(procname, sizeof(procname), "unknown process");
} else
snprintf(procname, sizeof(procname), "kernel");