diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-01 09:35:54 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-01 10:03:49 +1100 |
commit | 2fc1498517523a20a3080816ec50ee9e7fbe533d (patch) | |
tree | 808b455c38c2e96f3d3930fa49f3f605416e5f24 /vendor/golang.org/x/sys/unix/sockcmsg_linux.go | |
parent | 7a464ae5b7782b383050de6dc3ae5bd51a88bad0 (diff) |
some refactoring in anticipation of the graph feature
Diffstat (limited to 'vendor/golang.org/x/sys/unix/sockcmsg_linux.go')
-rw-r--r-- | vendor/golang.org/x/sys/unix/sockcmsg_linux.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/golang.org/x/sys/unix/sockcmsg_linux.go b/vendor/golang.org/x/sys/unix/sockcmsg_linux.go index e86d543b9..326fb04a5 100644 --- a/vendor/golang.org/x/sys/unix/sockcmsg_linux.go +++ b/vendor/golang.org/x/sys/unix/sockcmsg_linux.go @@ -56,3 +56,34 @@ func PktInfo6(info *Inet6Pktinfo) []byte { *(*Inet6Pktinfo)(h.data(0)) = *info return b } + +// ParseOrigDstAddr decodes a socket control message containing the original +// destination address. To receive such a message the IP_RECVORIGDSTADDR or +// IPV6_RECVORIGDSTADDR option must be enabled on the socket. +func ParseOrigDstAddr(m *SocketControlMessage) (Sockaddr, error) { + switch { + case m.Header.Level == SOL_IP && m.Header.Type == IP_ORIGDSTADDR: + pp := (*RawSockaddrInet4)(unsafe.Pointer(&m.Data[0])) + sa := new(SockaddrInet4) + p := (*[2]byte)(unsafe.Pointer(&pp.Port)) + sa.Port = int(p[0])<<8 + int(p[1]) + for i := 0; i < len(sa.Addr); i++ { + sa.Addr[i] = pp.Addr[i] + } + return sa, nil + + case m.Header.Level == SOL_IPV6 && m.Header.Type == IPV6_ORIGDSTADDR: + pp := (*RawSockaddrInet6)(unsafe.Pointer(&m.Data[0])) + sa := new(SockaddrInet6) + p := (*[2]byte)(unsafe.Pointer(&pp.Port)) + sa.Port = int(p[0])<<8 + int(p[1]) + sa.ZoneId = pp.Scope_id + for i := 0; i < len(sa.Addr); i++ { + sa.Addr[i] = pp.Addr[i] + } + return sa, nil + + default: + return nil, EINVAL + } +} |