如何打印每个数据包的前 34 个字节(以太网和 IP 标头)(以太网类型:0x0806,协议:ARP)?

2024-01-09

  • 操作系统:Ubuntu 15.10 桌面版(64 位)
  • 内核:4.3
  • 驱动程序:无线
  • Path: /net/mac80211/rx.c http://lxr.free-electrons.com/source/net/mac80211/rx.c

下面是我当前的实现(int i = 0;就在之后struct sta_info *dsta;, and packet_number++;就在之前skb = rx->skb;在原始 rx.c 文件中):

#include <linux/ip.h>
#include <linux/byteorder/generic.h>

unsigned int packet_number = 1;

(etc.)

static void ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
{
    (etc.)

    int i = 0;
    unsigned int *byte_pointer;
    unsigned long byte_contents = 0;

    if (ntohs(ehdr->h_proto) == 0x0806) {
        printk("Packet %d:", packet_number);
        for (i = 0; i < 34; i++) {
            byte_pointer = (unsigned int *) (rx->skb->data + i);
            byte_contents = (unsigned long) (&byte_pointer);
            printk("  %lx", byte_contents);
        }
    }
    printk("\n");
    packet_number++;

但是,运行 dmesg 显示 printk 输出后,我得到的是:

[  103.373847] Packet 6: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  103.375720] Packet 7: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  103.572086] Packet 8: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  103.913790] Packet 12: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  108.940615] Packet 20: ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8
[  114.221127] Packet 28: ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8
[  143.390755] Packet 1354: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  144.394113] Packet 1401: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  194.730646] Packet 2041: ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8
[  208.784474] Packet 2059: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  247.409613] Packet 2130: ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8
[  272.241113] Packet 2171: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  272.241957] Packet 2172: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  272.648982] Packet 2174: ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8 ffff88007bd17bd8
[  273.877091] Packet 2180: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8
[  273.878104] Packet 2181: ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8 ffff88007c603cb8

这些是我想要的输出:

Packet xx: 74 46 a4 08 06 ...
Packet xx: 55 32 3e 45 98 ...
Packet xx: 00 1b 2c 70 55 ...

rx->skb->data 的数据类型是无符号字符 * http://lxr.free-electrons.com/source/include/linux/skbuff.h#L697,为了使其与 %x 兼容,我必须进行这些转换,最终需要使用 unsigned long 和 %lx 来阻止编译警告的发生。

你能告诉我我做错了什么,以及如何打印每个数据包的前 34 个字节(以太网和 IP 标头)(以太网类型:0x0806,协议:ARP)?


你必须使用%*ph说明符或print_hex_dump()如果你想把它放在多行上。无论如何,这并不是为时间紧迫的零件而设计的。因此,在这种情况下,您必须切换到具有相应的跟踪点trace_printk() calls.

对于慢速的,示例如下。

pr_info("Packet %d: %34ph\n", packet_number, rx->skb->data);

or

pr_info("Packet %d:\n", packet_number);
print_hex_dump(KERN_INFO, "Packet:", DUMP_PREFIX_OFFSET, 16, 1, rx->skb->data, 34, false);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何打印每个数据包的前 34 个字节(以太网和 IP 标头)(以太网类型:0x0806,协议:ARP)? 的相关文章

  • Linux 内核线程没有地址空间

    为什么Linux内核线程没有地址空间 对于任何要执行的任务 它都应该有一个内存区域 对吗 内核线程的文本和数据去了哪里 内核线程确实有一个地址空间 只是他们都有同一个 这并不妨碍它们各自拥有不同的堆栈 文本和数据放置在内核地址空间 由所有线
  • 在 Mac OS X 中创建虚拟 USB 设备

    我尝试以编程方式在 Mac OS 中添加带有驱动程序的虚拟 USB 设备 IOKit 文档说 传统上 虚拟设备的驱动程序在 IOResources 上匹配 因为虚拟设备不发布自己的 nub 此类驱动程序的另一个示例是 HelloIOKit
  • 如何在 Windows 中拦截 DNS 查询

    我正在研究如何在 Windows 中拦截 DNS 查询 以一种不需要将 DLL 注入到每个进程中的方式 并且理想情况下能够根据发出查询的进程做出决策 因此简单的 DNS 代理服务器是不够的 从表面上看 DNS 查询所采用的路径如下所示 某些
  • 套接字对和一对无名管道有什么区别吗?

    我不仅想知道用户端的差异 还想知道 Linux 内核实现中的差异 共同部分 管道是单向的 因此需要两个管道才能进行双向通信 而套接字对是双向的 管道始终是面向流的 而套接字对可以是面向数据报的 套接字对正常AF UNIX套接字 这意味着辅助
  • 如何显示 Jupyter 笔记本的版本并在 Jupyter 笔记本中运行单元?我收到错误:错误的解释器

    我已经安装了 Anaconda 并使用 conda 环境和 conda 命令来安装软件 当我输入 jupyter notebook version 我收到以下错误 zsh Users cr517 local bin jupyter bad
  • jQuery JSON 请求得到“200 OK”答案,但没有内容

    我正在使用 jQuery 通过访问者的 IP 地址获取其位置 有一项很棒的服务叫做免费地理IP http freegeoip appspot com 我需要做的就是在 URL 末尾添加 json 或 xml 然后添加 IP 地址 它将返回所
  • 编译错误:linux/module.h:没有这样的文件或目录

    我写了一个简单的模块 define KERNEL define MODULE include
  • 如何在 Linux 内核空间使用 ioctl()?

    可以打电话吗ioctl来自 Linux 内核模块 谁能提供一个如何使用它的例子吗 您可以尝试拨打电话sys ioctl 如果内核是用以下命令编译的 则它会被导出CONFIG COMPAT 或者 如果您有设备驱动程序struct file o
  • IIS:添加功能

    我需要使用 IIS 7 0 中的 IP 地址和域限制功能编辑 IP 规则 但在我的 Windows 7 计算机上 我的 IIS 中不存在此功能 有谁知道如何向 IIS 添加此功能 我无法在任何地方找到下载 或 IIS 中用于添加功能的部分
  • 如何获取uinput创建的设备的名称(路径)

    我已经成功设置了一个小程序来创建uinput questions tagged uinput我计划使用它来自动测试接收键盘输入事件的应用程序 我已关注both http thiemonge org getting started with
  • “do { ... } while (0)”在内核代码中到底做了什么? [复制]

    这个问题在这里已经有答案了 可能的重复 当我们定义宏时 do while 0 有什么用 https stackoverflow com questions 923822 whats the use of do while0 when we
  • ARM 系统调用的接口是什么?它在 Linux 内核中的何处定义?

    我读过有关 Linux 中的系统调用的内容 并且到处都给出了有关 x86 架构的描述 0x80中断和SYSENTER 但我无法追踪 ARM 架构中系统调用的文件和进程 任何人都可以帮忙吗 我知道的几个相关文件是 arch arm kerne
  • 当IRQL下降时,Windows中如何触发软件中断?

    我知道对于硬件中断 当 KeAcquireInterruptSpinLock 调用 KeLowerIrql 时 HAL 会调整 LAPIC 中的中断掩码 这将允许自动服务排队的中断 可能在 IRR 中 但是对于软件中断 例如 ntdll d
  • 将 mmap 内核启动参数保留的内存映射到用户空间

    正如中所讨论的this https stackoverflow com q 1911473 143897问题 我在启动时使用内核启动参数保留一个内存块memmap 8G 64G 我写了一个字符驱动程序 http pete akeo ie 2
  • 内核与系统中的 Windows 进程

    我有一些与内核和用户模式下的 Windows 进程相关的问题 如果我有一个 hello world 应用程序和一个公开新系统调用 foo 的 hello world 驱动程序 我很好奇一旦处于内核模式 我能做什么和不能做什么 对于初学者来说
  • saber sd 如何在没有 SPL 的情况下直接从 uboot 启动

    sabre sd 基于 imx 6 最大内部 RAM 约为 150Kb 然而 uboot 足够大 可以容纳在这个空间中 在这个场景中事情是如何进行的 https community freescale com docs DOC 95015
  • 选择 c 和 gamma 值

    您好 我正在使用 SMO 执行 SVM 分类 其中我的内核是 RBF 现在我想选择c and sigma值 使用网格搜索和交叉验证 我是内核函数的新手 请帮助 一步一步的过程 选择一些您认为有趣的 C 和 sigma 值 例如 C 1 10
  • 在Linux中断上下文中运行用户线程

    我正在编写一些定制的应用程序 并允许更改 Linux 内核中的中断处理程序代码 我有一个用户线程正在等待中断发生 如果发生中断 那么我要做的第一件事就是执行该用户线程 有什么办法让它发挥作用吗 Thanks 创建一个字符设备 这就是内核所做
  • 这个反斜杠在这段汇编代码中起什么作用?

    我不确定这些推线有什么区别 修剪下来来自 Linux 的 x86 entry calling h https github com torvalds linux blob 241e39004581475b2802cd63c111fec43b
  • 在 /dev/input/eventX 中写入事件需要哪些命令?

    我正在开发一个android需要将触摸事件发送到 dev input eventX 的应用程序 我知道C执行此类操作的代码结构如下 struct input event struct timeval time unsigned short

随机推荐