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

Method handleGetsockname

cmd/run/engine/process/handle.go:505–542  ·  view source on GitHub ↗

handleGetsockname handles the getsockname(2) syscall to emulate the external connection's bind address.

(n *seccomp.Notif, fd int, addrPtr uintptr, addrSizePtr uintptr)

Source from the content-addressed store, hash-verified

503// handleGetsockname handles the getsockname(2) syscall to emulate the external
504// connection's bind address.
505func (p *Process) handleGetsockname(n *seccomp.Notif, fd int, addrPtr uintptr, addrSizePtr uintptr) error {
506 s, ok := p.getSocket(fd)
507 if !ok {
508 return n.Skip()
509 }
510
511 bind, errno, err := s.BindAddr()
512 if err != nil {
513 return fmt.Errorf("get bind addr: %w", err)
514 }
515 if errno != 0 {
516 return n.Return(0, errno)
517 }
518
519 if !bind.IsValid() {
520 errno, err := p.vmWriteUint32(n, addrSizePtr, 0)
521 if err != nil {
522 return fmt.Errorf("write zero size: %w", err)
523 }
524 if errno != 0 {
525 return n.Return(0, errno)
526 }
527 return n.Return(0, 0)
528 }
529
530 if s.Inode.Domain == unix.AF_INET6 && bind.Addr().Is4() {
531 bind = netip.AddrPortFrom(netip.AddrFrom16(bind.Addr().As16()), bind.Port())
532 }
533
534 if addrPtr == 0 || addrSizePtr == 0 {
535 return n.Return(0, unix.EFAULT)
536 }
537 errno, err = p.vmWriteSockaddr(n, bind, addrPtr, addrSizePtr)
538 if err != nil {
539 return fmt.Errorf("write bind addr: %w", err)
540 }
541 return n.Return(0, errno)
542}
543
544// handleGetpeername handles the getpeername(2) syscall to emulate the external
545// connection's peer address.

Callers 1

initFunction · 0.80

Calls 7

getSocketMethod · 0.95
vmWriteUint32Method · 0.95
vmWriteSockaddrMethod · 0.95
SkipMethod · 0.80
BindAddrMethod · 0.80
ReturnMethod · 0.80
AddrMethod · 0.80

Tested by

no test coverage detected