sockets - 可以从 Linux 内核数据类型“struct sock”中检索套接字的端口吗?
问题描述
动机
我正在尝试编写一个 bpftrace 程序,以通过挂钩 kprobe 来跟踪套接字何时准备好读取sock_def_readable
。我会得到一个struct sock
检查。我想将它映射回我在用户区创建的套接字。
问题
如何从 a 中恢复端口号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);
}
推荐阅读
- javascript - 针对特定容易猜到的模式的正则表达式验证
- c# - 统一网络 | ClientRpc 在错误的播放器对象上被调用
- python - 根据Django中的数据授予权限
- python - 为什么 anaconda install 在使用 conda-forge 时会返回不同的结果?
- json - 通过 ajax post 发送大型 JSON 对象字符串
- linux - 如何执行命令并将值分配给变量?
- javascript - 只允许在 React Native FlatList 中选择一项
- algorithm - 寻找给定大额硬币的最小数量的算法
- android - 你如何加载 GFYCAT GIF?
- laravel - 如何从 Laravel API 获取响应消息?