我正在尝试读取过滤器的一些BPF语法,试图找出它的功能。有一件事我找不到,那就是“字节偏移”从哪里开始的。意思是,如果我们有以下汇编程序代码:
0000: 0x28 0x00 0x00 0x00000004 ldh $data[4]
0001: 0x15 0x00 0x61 0x00000028 jeq 40 true:0002 false:0099
0002: 0x30 0x00 0x00 0x0000000d ldb $data[13]
0003: 0x14 0x00 0x00 0x00000033 sub 51
0004: 0x15 0x00 0x5e 0x00000006 jeq 6 true:0005 false:0099对于字节偏移量4,这是否将我置于802.3帧的目标MAC地址的中间?还是在序言里?在包中我从哪里开始,然后步行4个字节到我的半个字是我要问的。
如果它是在MAC地址,替罪羊会是一个可行的选择,写我自己的数据包的以太网帧?这样做的目的是编写一个客户端,它将连接并通过所有的BPF需求。
发布于 2018-03-30 16:37:38
关于你的第一个问题:这取决于你把你的BPF程序附加在哪里,以及如何附加。
- If the protocol you passed when creating your socket is, for example, TCP, then the program starts on the L3 (IP) header. See for example [this question](https://stackoverflow.com/questions/39540291/classic-bpf-on-linux-filter-does-not-work).
- If the protocol required is “every packet”, then the program starts working on the MAC header. See the example [in the BPF kernel documentation](https://www.kernel.org/doc/Documentation/networking/filter.txt) (grep for `ETH_P_ALL`).编辑:而不是协议,这更有可能是在使用的套接字域(AF_PACKET和AF_INET),在这里产生了差异。
关于你的第二个问题,你可以用替罪羊构建以太网报头和有效负载,但我很抱歉,我不明白你所说的“连接并通过所有BPF需求”…是什么意思你能再详细一点吗?
https://stackoverflow.com/questions/49577061
复制相似问题