-1

动机

我正在尝试编写一个 bpftrace 程序,以通过挂钩 kprobe 来跟踪套接字何时准备好读取sock_def_readable。我会得到一个struct sock检查。我想将它映射回我在用户区创建的套接字。

问题

如何从 a 中恢复端口号struct sock

4

1 回答 1

0

我只是扩展了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);
}
于 2020-05-09T06:03:57.057 回答