Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets 能否检索套接字';Linux内核数据类型“struct sock”的s端口?_Sockets_Linux Kernel_Kprobe - Fatal编程技术网

Sockets 能否检索套接字';Linux内核数据类型“struct sock”的s端口?

Sockets 能否检索套接字';Linux内核数据类型“struct sock”的s端口?,sockets,linux-kernel,kprobe,Sockets,Linux Kernel,Kprobe,动机 我正试图编写一个bpftrace程序,通过挂接到kprobesock\u def\u readable来跟踪套接字何时准备好读取。我将获得一个struct sock进行检查。我想把它映射回我在user land中创建的套接字 问题 如何从struct sock恢复端口号?我刚刚扩展了inet_sk的定义。。。这只是一个演员阵容 #!/usr/bin/env bpftrace #include <linux/net/inet_sock.h> BEGIN { print

动机

我正试图编写一个bpftrace程序,通过挂接到kprobe
sock\u def\u readable
来跟踪套接字何时准备好读取。我将获得一个
struct sock
进行检查。我想把它映射回我在user land中创建的套接字

问题


如何从
struct sock
恢复端口号?

我刚刚扩展了
inet_sk
的定义。。。这只是一个演员阵容

#!/usr/bin/env bpftrace

#include <linux/net/inet_sock.h>

BEGIN
{
    printf("network tracing");
}

kprobe:sock_def_readable
{
  $inet_sock = (struct inet_sock *)arg0;
  printf("sock_def_readable destination port %d, source port %d \n", $inet_sock->inet_sport, $inet_sock->inet_dport);
}
#/usr/bin/env bpftrace
#包括
开始
{
printf(“网络跟踪”);
}
kprobe:sock_def_可读
{
$inet_sock=(struct inet_sock*)arg0;
printf(“sock_def_可读目标端口%d,源端口%d\n”,$inet_sock->inet_sport,$inet_sock->inet_dport);
}

如果它不在那里,那将是令人惊讶的。你考虑过看定义吗?我想我可以用
inet_sk(sk)->inet_sport
inet_sk(sk)->inet_dport
函数来做。你使用哪个内核版本?@red0ct我认为4.15一个恼人的事情是端口都是大端的