(local: Option<&str>, default_port: u16)
| 3012 | impl std::error::Error for ForwardTcpConnectionError {} |
| 3013 | |
| 3014 | fn parse_tcp_forward_spec(local: Option<&str>, default_port: u16) -> Result<(String, u16)> { |
| 3015 | let Some(spec) = local else { |
| 3016 | return Ok(("127.0.0.1".to_string(), default_port)); |
| 3017 | }; |
| 3018 | |
| 3019 | if let Some(pos) = spec.rfind(':') { |
| 3020 | let addr = &spec[..pos]; |
| 3021 | let port_str = &spec[pos + 1..]; |
| 3022 | if let Ok(port) = port_str.parse::<u16>() { |
| 3023 | if addr.is_empty() { |
| 3024 | return Err(miette::miette!("bind address is required before ':'")); |
| 3025 | } |
| 3026 | return Ok((addr.to_string(), port)); |
| 3027 | } |
| 3028 | } |
| 3029 | |
| 3030 | let port: u16 = spec.parse().map_err(|_| { |
| 3031 | miette::miette!("invalid local forward spec '{spec}': expected [bind_address:]port") |
| 3032 | })?; |
| 3033 | Ok(("127.0.0.1".to_string(), port)) |
| 3034 | } |
| 3035 | |
| 3036 | async fn forward_one_tcp_connection( |
| 3037 | client: &mut crate::tls::GrpcClient, |
no test coverage detected