In short, that transmute was always unsound because it assumes that the Rust SocketAddrV4 type is the same as its C counterpart, but that was never guaranteed.
See PR 78802. You can follow some of the links to PRs in popular packages to see how they replaced pointer casts or transmutes with code to construct the sockaddr_in more manually.
You'll probably want to update your dependencies. The version of socket2 you're using (possibly indirectly through some other dependency) is over two years old and has since been yanked[1] from crates.io due to this issue: Yank all `0.3` versions older than `0.3.16` · Issue #139 · rust-lang/socket2 · GitHub. Old versions of crates are supposed to compile on newer versions of Rust, but due to this problem socket2 0.3.12 doesn't and you're getting an error.
If updating is too tricky, you can try using an older version of Rust. Something like
rustup install 1.50.0 // install Rust 1.50.0, which was released in February 2021
cargo +1.50.0 run // `cargo run` using version 1.50.0
Yanking a crate version makes it unavailable to use in new projects, generally due to some serious issue with that version. ↩︎
@quinedot@Heliozoa Thanks, it was a dependency issue. I stick with the old dependencies in my cargo.toml file. I updated to latest version before and I guess that incited the error. Thanks once again