如何在 Net::RawIP 中设置 tcp 选项(MSS 值)

how to set tcp options (MSS value) in Net::RawIP

我可以在使用 Net::RawIP 时将最大段大小设置为某个值吗?

我正在尝试以下代码,但不知道如何将 TCP 选项中的 MSS 值设置为自定义值。

#!/usr/bin/perl

use Net::RawIP;

$packet = new Net::RawIP;

$packet->set({
    ip  => {
        saddr => '192.168.122.128',
        daddr => '192.168.122.1'
    },
    tcp => { source => 2323,
        dest    => 8080,
        syn     => 1,
        seq     => 100,
        ack_seq => 0,
        data    => 'hello world'
    }
});

$packet->optset(tcp => { type => [ (2) ], data => [ (10) ] });

$packet->send(0, 1); 

根据documentation

optset(OPTPROTO => { type => [...],data => [...] },...)

[...] The value of the data also is an array reference. This array must be filled with strings which must contain all bytes from a option except bytes with type and length of an option.

(强调)

您正在传递对整数数组的引用;您需要传递对字符串数组的引用。尝试这样的事情:

$packet->optset( tcp => { type => [ 2 ], data => [ "\x00\x0A" ] } );

The length of the maximum segment size field is 4,其中kind字段为1字节,length字段为1字节,数据本身为2字节,所以需要像上面那样传递一个2字节的字符串