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