MCPcopy Index your code
hub / github.com/subtrace/subtrace / vmReadSockaddr

Method vmReadSockaddr

cmd/run/engine/process/vm.go:131–165  ·  view source on GitHub ↗

vmReadSockaddr reads a sockaddr struct of size bytes to the process's virtual memory starting at ptr.

(n *seccomp.Notif, ptr uintptr, size int)

Source from the content-addressed store, hash-verified

129// vmReadSockaddr reads a sockaddr struct of size bytes to the process's
130// virtual memory starting at ptr.
131func (p *Process) vmReadSockaddr(n *seccomp.Notif, ptr uintptr, size int) (netip.AddrPort, syscall.Errno, error) {
132 if ptr == 0 || size == 0 {
133 return netip.AddrPort{}, unix.EINVAL, nil
134 }
135
136 b, errno, err := p.vmReadBytes(n, ptr, size)
137 if errno != 0 || err != nil {
138 return netip.AddrPort{}, errno, err
139 }
140 if len(b) < 2 {
141 return netip.AddrPort{}, unix.EINVAL, nil
142 }
143
144 family := arch.Uint16(b[0:2])
145 switch family {
146 case unix.AF_INET:
147 sa := new(linux.SockAddrInet)
148 if len(b) < sa.SizeBytes() {
149 return netip.AddrPort{}, unix.EINVAL, nil
150 }
151 sa.UnmarshalBytes(b)
152 return netip.AddrPortFrom(netip.AddrFrom4(sa.Addr), htons(sa.Port)), 0, nil
153
154 case unix.AF_INET6:
155 sa := new(linux.SockAddrInet6)
156 if len(b) < sa.SizeBytes() {
157 return netip.AddrPort{}, unix.EINVAL, nil
158 }
159 sa.UnmarshalBytes(b)
160 return netip.AddrPortFrom(netip.AddrFrom16(sa.Addr), htons(sa.Port)), 0, nil
161
162 default:
163 return netip.AddrPort{}, unix.EINVAL, nil
164 }
165}
166
167// vmWriteBytes writes b to the process's memory starting at ptr. It returns an
168// error if the address range isn't writable or if the notification is invalid.

Callers 2

handleBindMethod · 0.95
handleConnectMethod · 0.95

Calls 4

vmReadBytesMethod · 0.95
htonsFunction · 0.85
UnmarshalBytesMethod · 0.80
SizeBytesMethod · 0.45

Tested by

no test coverage detected