Can';无法从结构套接字获取所有者信息:sk_peer_pid始终为空
我试图从Can';无法从结构套接字获取所有者信息:sk_peer_pid始终为空,c,linux,sockets,linux-kernel,C,Linux,Sockets,Linux Kernel,我试图从struct sock中查找PID,因此我使用了以下代码: struct task_struct *get_task_from_sock(struct sock *sk) { struct task_struct *task = NULL; if (sk == NULL) { pr_info("sk is NULL"); return 0; } if (sk->sk_peer_pid ==
struct sock
中查找PID,因此我使用了以下代码:
struct task_struct *get_task_from_sock(struct sock *sk)
{
struct task_struct *task = NULL;
if (sk == NULL)
{
pr_info("sk is NULL");
return 0;
}
if (sk->sk_peer_pid == NULL)
{
pr_info("sk_peer_pid is NULL");
return 0;
}
return get_pid_task(sk->sk_peer_pid, PIDTYPE_PID);
}
但是sk_peer_pid总是空的。所以我参考了源代码:
# grep sk_peer_pid -r
include/net/sock.h: * @sk_peer_pid: &struct pid for this socket's peer
include/net/sock.h: struct pid *sk_peer_pid;
net/core/sock.c: cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
net/core/sock.c: put_pid(sk->sk_peer_pid);
net/core/sock.c: sk->sk_peer_pid = NULL;
net/unix/af_unix.c: put_pid(sk->sk_peer_pid);
net/unix/af_unix.c: sk->sk_peer_pid = get_pid(task_tgid(current));
net/unix/af_unix.c: put_pid(sk->sk_peer_pid);
net/unix/af_unix.c: sk->sk_peer_pid = get_pid(peersk->sk_peer_pid);
它只适用于unix本地套接字吗
如何找到struct sock
的所有者?我读过,它从来没有提到如何从struct sock获取PID
有人知道吗