From e4c104ae5132cf21bd908cae000b888b21bffdbc Mon Sep 17 00:00:00 2001 From: Fabien Siron Date: Thu, 26 May 2016 10:46:28 +0000 Subject: [PATCH] Introduce get_sockaddr_by_inode Add a way to get socket information without printing it. * defs.h (get_sockaddr_by_inode): New prototype. * socketutils.c (get_sockaddr_by_inode): New function. Co-authored-by: Dmitry V. Levin --- defs.h | 1 + socketutils.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/defs.h b/defs.h index 70ff07bc..0837b9ce 100644 --- a/defs.h +++ b/defs.h @@ -596,6 +596,7 @@ printpath(struct tcb *, kernel_ulong_t addr); (sizeof(long long) * 3 * 2 + sizeof("{tv_sec=-, tv_nsec=}")) extern void printfd(struct tcb *, int); extern void print_sockaddr(struct tcb *tcp, const void *, int); +extern const char *get_sockaddr_by_inode(struct tcb *, int fd, unsigned long inode); extern bool print_sockaddr_by_inode(struct tcb *, int fd, unsigned long inode); extern void print_dirfd(struct tcb *, int); diff --git a/socketutils.c b/socketutils.c index a52f2656..a3aedb4e 100644 --- a/socketutils.c +++ b/socketutils.c @@ -517,6 +517,16 @@ print_sockaddr_by_inode_uncached(const unsigned long inode, return false; } +/* Given an inode number of a socket, return its protocol details. */ +const char * +get_sockaddr_by_inode(struct tcb *const tcp, const int fd, + const unsigned long inode) +{ + const char *details = get_sockaddr_by_inode_cached(inode); + return details ? details : + get_sockaddr_by_inode_uncached(inode, getfdproto(tcp, fd)); +} + /* Given an inode number of a socket, print out its protocol details. */ bool print_sockaddr_by_inode(struct tcb *const tcp, const int fd, -- 2.50.1