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

Method getRemoteBindAddr

cmd/run/socket/inode.go:48–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func (s *ImmutableState) getRemoteBindAddr() (netip.AddrPort, syscall.Errno, error) {
49 switch s.state {
50 case StatePassive:
51 if s.passive.bind == nil {
52 return netip.AddrPort{}, 0, nil
53 }
54 return getsockname(s.passive.bind)
55
56 case StateConnected:
57 addr, err := netip.ParseAddrPort(s.connected.proxy.external.LocalAddr().String())
58 if err != nil {
59 return netip.AddrPort{}, 0, fmt.Errorf("connected: parse addr: %w", err)
60 }
61 return addr, 0, nil
62
63 case StateConnecting:
64 if s.connecting.bind == nil {
65 panic("connecting socket has no bind")
66 }
67 return getsockname(s.connecting.bind)
68
69 case StateListening:
70 addr, err := netip.ParseAddrPort(s.listening.lis.Addr().String())
71 if err != nil {
72 return netip.AddrPort{}, 0, fmt.Errorf("listen: parse addr: %w", err)
73 }
74 return addr, 0, nil
75
76 case StateClosed:
77 return netip.AddrPort{}, unix.EBADF, nil
78 }
79 panic("unreachable")
80}
81
82func (s *ImmutableState) getRemotePeerAddr() (netip.AddrPort, syscall.Errno, error) {
83 switch s.state {

Callers 3

ConnectMethod · 0.80
BindAddrMethod · 0.80
ListenMethod · 0.80

Calls 3

getsocknameFunction · 0.85
AddrMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected