Get struct file from of a given struct socket in kernel space
I need to get the struct file that is associated with a specific struct socket. I saw in the kernel source, in the socket.c file, that there the function struct socket *sockfd_lookup(int fd, int *err), which given a fd returns the socket that this fd belongs to. Is there any way to do the opposite thing? i mean to take the fd of the struct socket. I need to do this in a loadable kernel module.
socket struct has a member that is pointer back to its file struct. See linux/net.h struct socket definition
Does the file member of struct socket not hold what you're looking for?