| 109 | } |
| 110 | |
| 111 | func handleConn(ctx context.Context, out io.Writer, c net.Conn, remote netip.Addr, port uint16) { |
| 112 | defer c.Close() |
| 113 | dialer := &net.Dialer{} |
| 114 | up, err := dialer.DialContext(ctx, "tcp", |
| 115 | net.JoinHostPort(remote.String(), fmt.Sprintf("%d", port))) |
| 116 | if err != nil { |
| 117 | fmt.Fprintf(out, "snix: dial %s:%d: %v\n", remote, port, err) |
| 118 | return |
| 119 | } |
| 120 | defer up.Close() |
| 121 | |
| 122 | go io.Copy(up, c) |
| 123 | _, _ = io.Copy(c, up) |
| 124 | } |
| 125 | |
| 126 | func resolveIPv4(host string) (netip.Addr, error) { |
| 127 | if a, err := netip.ParseAddr(host); err == nil && a.Is4() { |