From c5ff2059f619ac91c14d55412314d1c67de6a593 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 17 Jul 2015 14:55:15 +0200 Subject: 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//exe, thus move that functionality to an own function. Signed-off-by: Tobias Klauser --- proto_nlmsg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'proto_nlmsg.c') 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"); -- cgit v1.2.3-54-g00ecf