本文整理匯總了Golang中github.com/ghedo/go/pkt/packet.Buffer.Buffer方法的典型用法代碼示例。如果您正苦於以下問題:Golang Buffer.Buffer方法的具體用法?Golang Buffer.Buffer怎麽用?Golang Buffer.Buffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ghedo/go/pkt/packet.Buffer
的用法示例。
在下文中一共展示了Buffer.Buffer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestPackWithIPv4
func TestPackWithIPv4(t *testing.T) {
var b packet.Buffer
b.Init(make([]byte, len(test_with_ipv4)))
ip4 := ipv4.Make()
ip4.SrcAddr = net.ParseIP(ipsrc_str)
ip4.DstAddr = net.ParseIP(ipdst_str)
udp := &udp.Packet{
SrcPort: 52134,
DstPort: 80,
Length: 18,
}
ip4.SetPayload(udp)
err := udp.Pack(&b)
if err != nil {
t.Fatalf("Error packing: %s", err)
}
if !bytes.Equal(test_with_ipv4, b.Buffer()) {
t.Fatalf("Raw packet mismatch: %x", b.Buffer())
}
}
示例2: TestPackOptions
func TestPackOptions(t *testing.T) {
var b packet.Buffer
b.Init(make([]byte, len(test_options)))
p := MakeTestSimple()
p.DataOff = 10
p.Options = append(p.Options,
tcp.Option{
Type: tcp.MSS,
Len: 4,
Data: []byte{0x05, 0x78},
},
)
p.Options = append(p.Options,
tcp.Option{
Type: tcp.SAckOk,
Len: 2,
},
)
p.Options = append(p.Options,
tcp.Option{
Type: tcp.Timestamp,
Len: 10,
Data: []byte{0x61, 0x25, 0xE5, 0xB2, 0x00, 0x13, 0x15, 0x66},
},
)
p.Options = append(p.Options,
tcp.Option{
Type: tcp.WindowScale,
Len: 3,
Data: []byte{0x0A},
},
)
p.Options = append(p.Options,
tcp.Option{
Type: tcp.End,
},
)
err := p.Pack(&b)
if err != nil {
t.Fatalf("Error packing: %s", err)
}
if !bytes.Equal(test_options, b.Buffer()) {
t.Fatalf("Raw packet mismatch: %x", b.Buffer())
}
}
示例3: TestPack
func TestPack(t *testing.T) {
var b packet.Buffer
b.Init(make([]byte, len(test_simple)))
p := MakeTestSimple()
err := p.Pack(&b)
if err != nil {
t.Fatalf("Error packing: %s", err)
}
if !bytes.Equal(test_simple, b.Buffer()) {
t.Fatalf("Raw packet mismatch: %x", b.Buffer())
}
}
示例4: TestPackWithIPv6
func TestPackWithIPv6(t *testing.T) {
var b packet.Buffer
b.Init(make([]byte, len(test_with_ipv6)))
ip6 := ipv6.Make()
ip6.SrcAddr = net.ParseIP(ipsrc_str)
ip6.DstAddr = net.ParseIP(ipdst_str)
icmp6 := MakeTestSimple()
ip6.SetPayload(icmp6)
err := icmp6.Pack(&b)
if err != nil {
t.Fatalf("Error packing: %s", err)
}
if !bytes.Equal(test_with_ipv6, b.Buffer()) {
t.Fatalf("Raw packet mismatch: %x", b.Buffer())
}
}