std::net: clamp multicast ttl value to u8 max.#154113
std::net: clamp multicast ttl value to u8 max.#154113devnexen wants to merge 4 commits intorust-lang:mainfrom
Conversation
on some platforms the underlying type is c_uchar, values above 255 would silently truncate.
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Nominating for libs-api to decide if we want to truncate in std or not. AFAICT, the choice of u32 for the API is historical (I see it's been defined as such since the RFC proposing these, rust-lang/rfcs#1461). The underlying IPv4 packet only has space for u8 (255) TTL, which is what constrains this under the hood. I think the primary alternative is to panic or return an Err in userspace. Linux returns EINVAL on values Maybe the right thing is to change the as-cast into |
|
It seems like on most platforms including Linux, giving a TTL over 255 will return EINVAL - so in the @rust-lang/libs-api meeting, we decided that we'd rather just error here instead of clamping. A similar PR would be welcome for other cases where we set TTL, because this only addresses the multicast case |
on some platforms the underlying type is c_uchar,
values above 255 would silently truncate.