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 <ldv@altlinux.org>
This commit is contained in:
Fabien Siron 2016-05-26 10:46:28 +00:00 committed by Dmitry V. Levin
parent f42a3a3a90
commit e4c104ae51
2 changed files with 11 additions and 0 deletions

1
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);

@ -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,