通过Golang中的RAW_Sockets发送ipv6数据包

时间:2019-06-27 16:02:42

标签: sockets go system-calls ipv6 raw-sockets

我正在尝试使用golang发送IPv6数据包。因此,我正在使用syscall.Socket(syscall.AF_INET6, syscall.SOCK_RAW, syscall.IPPROTO_RAW) IPv6Packets掉了,但是如果我用Wireshark检查它们,则它们的格式不正确。

Hexdump Wireshark:

0000   cc ce 1e 3b 13 9b ac bc 32 79 d5 5f 86 dd 60 0d
0010   a3 80 00 30 ff ff 20 03 00 cd df 1e 3d 00 91 17
0020   c3 e0 8b b3 ff fe 2a 00 14 50 40 01 08 1e 00 00
0030   00 00 00 00 20 03 6a ba ff e0 00 08 3a 40 20 03
0040   00 cd df 1e 3d 00 08 51 b8 bd e1 17 94 85 2a 00
0050   14 50 40 01 08 1e 00 00 00 00 00 00 20 03 80 00
0060   00 00 be ef 00 01

Hexdump缓冲区:

00000000  6a ba ff e0 00 08 3a 40  20 03 00 cd df 1e 3d 00
00000010  08 51 b8 bd e1 17 94 85  2a 00 14 50 40 01 08 1e  
00000020  00 00 00 00 00 00 20 03  80 00 00 00 be ef 00 01 

因此正确的标头始于Wireshark转储中的pos 36

ipv4教程 https://www.darkcoding.net/software/raw-sockets-in-go-link-layer/

buffer := createHeader()

sockWrite, _ := syscall.Socket(syscall.AF_INET6, syscall.SOCK_RAW, syscall.IPPROTO_RAW)

var addrArr [16]byte
copy(addrArr[:], destAddr.IP)
addr := syscall.SockaddrInet6{
    Port: 0,
    Addr: addrArr,
}

syscall.Sendto(sockWrite, buffer, 0, &addr)

0 个答案:

没有答案