...
1
2
3
4
5
6
7 package ipv4
8
9 import (
10 "net"
11 "syscall"
12 "unsafe"
13
14 "golang.org/x/net/internal/iana"
15 "golang.org/x/net/internal/socket"
16
17 "golang.org/x/sys/unix"
18 )
19
20 func marshalDst(b []byte, cm *ControlMessage) []byte {
21 m := socket.ControlMessage(b)
22 m.MarshalHeader(iana.ProtocolIP, unix.IP_RECVDSTADDR, net.IPv4len)
23 return m.Next(net.IPv4len)
24 }
25
26 func parseDst(cm *ControlMessage, b []byte) {
27 if len(cm.Dst) < net.IPv4len {
28 cm.Dst = make(net.IP, net.IPv4len)
29 }
30 copy(cm.Dst, b[:net.IPv4len])
31 }
32
33 func marshalInterface(b []byte, cm *ControlMessage) []byte {
34 m := socket.ControlMessage(b)
35 m.MarshalHeader(iana.ProtocolIP, sockoptReceiveInterface, syscall.SizeofSockaddrDatalink)
36 return m.Next(syscall.SizeofSockaddrDatalink)
37 }
38
39 func parseInterface(cm *ControlMessage, b []byte) {
40 var sadl syscall.SockaddrDatalink
41 copy((*[unsafe.Sizeof(sadl)]byte)(unsafe.Pointer(&sadl))[:], b)
42 cm.IfIndex = int(sadl.Index)
43 }
44
View as plain text