| 46 | } |
| 47 | |
| 48 | func (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 | |
| 82 | func (s *ImmutableState) getRemotePeerAddr() (netip.AddrPort, syscall.Errno, error) { |
| 83 | switch s.state { |