{"record":{"id":"9408cba966c21cf5","repo":"embassy-rs/embassy","slug":"ipv4-support-not-enabled","errorCode":null,"errorMessage":"ipv4 support not enabled","messagePattern":"ipv4 support not enabled","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-net/src/tcp.rs","lineNumber":1340,"sourceCode":"            self.socket_timeout = timeout;\n        }\n    }\n\n    impl<'d, const N: usize, const TX_SZ: usize, const RX_SZ: usize> embedded_nal_async::TcpConnect\n        for TcpClient<'d, N, TX_SZ, RX_SZ>\n    {\n        type Error = Error;\n        type Connection<'m>\n            = TcpConnection<'m, 'd, N, TX_SZ, RX_SZ>\n        where\n            Self: 'm;\n\n        async fn connect<'a>(&'a self, remote: core::net::SocketAddr) -> Result<Self::Connection<'a>, Self::Error> {\n            let addr: crate::wire::IpAddress = match remote.ip() {\n                #[cfg(feature = \"ipv4\")]\n                IpAddr::V4(addr) => crate::wire::IpAddress::Ipv4(addr),\n                #[cfg(not(feature = \"ipv4\"))]\n                IpAddr::V4(_) => panic!(\"ipv4 support not enabled\"),\n                #[cfg(feature = \"ipv6\")]\n                IpAddr::V6(addr) => crate::wire::IpAddress::Ipv6(addr),\n                #[cfg(not(feature = \"ipv6\"))]\n                IpAddr::V6(_) => panic!(\"ipv6 support not enabled\"),\n            };\n            let remote_endpoint = (addr, remote.port());\n            let mut socket = TcpConnection::new(self.stack, self.state)?;\n            socket.socket.set_timeout(self.socket_timeout);\n            socket\n                .socket\n                .connect(remote_endpoint)\n                .await\n                .map_err(|_| Error::ConnectionReset)?;\n            Ok(socket)\n        }\n    }\n\n    /// Opened TCP connection in a [`TcpClient`].","sourceCodeStart":1322,"sourceCodeEnd":1358,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-net/src/tcp.rs#L1322-L1358","documentation":"`TcpClient::connect` (the `embedded_nal_async::TcpConnect` impl in embassy-net) converts a `core::net::SocketAddr` to the stack's wire `IpAddress`. When the remote address is IPv4 but the `ipv4` cargo feature is disabled, no arm exists to build the address and the code panics with \"ipv4 support not enabled\". It is a compile-time feature misconfiguration surfaced as a runtime panic.","triggerScenarios":"Calling `TcpClient::connect` (via the embedded-nal-async trait) with a `SocketAddr::V4(...)` remote while embassy-net was built without `features = [\"ipv4\"]`.","commonSituations":"Embedded Rust projects that connect to a hard-coded IPv4 address (e.g. \"192.168.1.10:8080\") but enabled only the `ipv6` feature (or neither) in embassy-net's Cargo feature list; often after upgrading embassy-net or copying a config tuned for IPv6-only networks.","solutions":["Enable the `ipv4` feature on the embassy-net dependency in Cargo.toml.","Alternatively, connect to an IPv6 address so the `ipv6` arm is used, if the target network supports it.","Check the address at runtime before calling `connect` and return your own error for unsupported families.","Verify the resolved feature set with `cargo tree -e features -p embassy-net` in case another crate's default features disabled it."],"exampleFix":"// before\nembassy-net = { version = \"0.4\", features = [\"ipv6\"] }\nlet conn = client.connect(\"192.168.1.10:8080\".parse().unwrap()).await?; // panics\n// after\nembassy-net = { version = \"0.4\", features = [\"ipv4\"] }\nlet conn = client.connect(\"192.168.1.10:8080\".parse().unwrap()).await?;","handlingStrategy":"validation","validationCode":"// Check address family against enabled features before connecting:\nfn addr_supported(remote: core::net::SocketAddr) -> bool {\n    match remote.ip() {\n        IpAddr::V4(_) => cfg!(feature = \"ipv4\"), // check via your own build cfg constants\n        IpAddr::V6(_) => cfg!(feature = \"ipv6\"),\n    }\n}\n// Usage: if !addr_supported(remote) { return Err(MyErr::UnsupportedFamily); }","typeGuard":"fn is_v4(remote: &core::net::SocketAddr) -> bool { matches!(remote, core::net::SocketAddr::V4(_)) }","tryCatchPattern":"// Connect in a wrapper that validates first; in firmware panics cannot be caught, so never call connect with an unsupported family:\nmatch addr { SocketAddr::V4(_) if !CFG_IPV4 => Err(MyError::UnsupportedFamily), _ => client.connect(addr).await }","preventionTips":["Always enable both `ipv4` and `ipv6` features unless the target network is guaranteed single-family.","Add a compile-time assertion: `const _: () = assert!(cfg!(feature = \"ipv4\"));` when your code only dials IPv4.","Parse addresses and check `is_ipv4()`/`is_ipv6()` before calling connect.","Review embassy-net feature flags after every dependency upgrade."],"tags":["embedded","rust","networking","tcp","feature-flags","panic"],"backgroundTag":"feature-not-enabled","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}