# Move the platform independent part of net into core

**URL:** <https://internals.rust-lang.org/t/move-the-platform-independent-part-of-net-into-core/14064>\
**Category:** Uncategorized\
**Created:** [February 17, 2021, 3:41am UTC](https://internals.rust-lang.org/t/move-the-platform-independent-part-of-net-into-core/14064 "2021-02-17T03:41:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lygstate](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lygstate/32/7250_2.png) [@lygstate](https://internals.rust-lang.org/u/lygstate)\
**Post date:** [February 17, 2021, 3:41am UTC](https://internals.rust-lang.org/t/move-the-platform-independent-part-of-net-into-core/14064/1 "2021-02-17T03:41:45Z")

</div>

Specifically, the address manipulation part for IPV4 and IPV6 can be moved to core

> <https://github.com/rust-lang/rust/blob/master/library/std/src/net/addr.rs>

So the bare-metal and network stack implementor care sharing same piece of code across library

---

<div class="post-metadata">

**Author:** ![bascule](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/bascule/32/3057_2.png) [@bascule](https://internals.rust-lang.org/u/bascule)\
**Post date:** [February 17, 2021, 3:53am UTC](https://internals.rust-lang.org/t/move-the-platform-independent-part-of-net-into-core/14064/2 "2021-02-17T03:53:53Z")

</div>

Related:

> <https://github.com/rust-lang/rfcs/pull/2832>
>
> Make the \`IpAddr\`, \`Ipv4Addr\`, \`Ipv6Addr\`, \`SocketAddr\`, \`SocketAddrV4\`,
> \`Socke…tAddrV6\`, \`Ipv6MulticastScope\` and \`AddrParseError\` types available in \`no\_std\`
> contexts by moving them into a \`core::net\` module.
> 
> \[Rendered\](https://rust-lang.github.io/rfcs/2832-core-net-types.html)
> 
> \---
> 
> Implementation: https://github.com/rust-lang/rust/pull/104265

> [@std::net::Ipv4Addr in core?](https://internals.rust-lang.org/t/std-ipv4addr-in-core/11247):
>
> I'm an embedded developer so I don't have access to std. Could we move std::net::Ipv4 to core?

> [@Why are SocketAddrV4/SocketAddrV6 based on low level sockaddr\_in\[6\]?](https://internals.rust-lang.org/t/why-are-socketaddrv4-socketaddrv6-based-on-low-level-sockaddr-in-6/13321):
>
> A port is always 16 bits (2 bytes). An IPv4 address is 4 bytes. This means the optimal size for SocketAddrV4 is 6 bytes (8 bytes with alignment 4 for Ipv4Addr). However, size\_of::\<SocketAddrV4\>() == 16 (on Linux). This is 2x the expected size open_mouth Hmm.. Yes, this is because the implementation is: pub struct SocketAddrV4 { inner: c::sockaddr\_in, } And sockaddr\_in has more data than just the IP and port. It's also not (currently) possible to make the new constructors for these sock…

---

<div class="post-metadata">

**Author:** ![faern](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/faern/32/3580_2.png) [@faern](https://internals.rust-lang.org/u/faern)\
**Post date:** [February 17, 2021, 5:24pm UTC](https://internals.rust-lang.org/t/move-the-platform-independent-part-of-net-into-core/14064/3 "2021-02-17T17:24:50Z")

</div>

I'm trying to remove the blockers for doing this in [Implement network primitives with ideal Rust layout, not C system layout by faern · Pull Request #78802 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/pull/78802)

The problem is that the current `IpAddr` structs are based on system representations that we can't have in `core` really. And we can't just merge the fix for that since a bunch of crates invalidly assumed the memory layout of the types 🤦‍♂️ So it's currently a waiting game. We have to find everyone who broke this API contract, patch them and wait for the usage of the broken crates to drop quite a lot.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [May 18, 2021, 5:25pm UTC](https://internals.rust-lang.org/t/move-the-platform-independent-part-of-net-into-core/14064/4 "2021-05-18T17:25:05Z")

</div>

Closed on May 18, 2021, 5:25pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
