Skip to content

Commit

Permalink
Don't assume representation of Ipv*Addr types
Browse files Browse the repository at this point in the history
Also, remove two uses of unsafe :)
  • Loading branch information
est31 authored and djc committed Jan 28, 2021
1 parent 612c9ac commit f3d82d7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions quinn/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
io,
io::IoSliceMut,
mem::{self, MaybeUninit},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
net::{IpAddr, SocketAddr, SocketAddrV4, SocketAddrV6},
os::unix::io::AsRawFd,
ptr,
task::{Context, Poll},
Expand Down Expand Up @@ -375,8 +375,8 @@ fn prepare_msg(
IpAddr::V4(v4) => {
let pktinfo = libc::in_pktinfo {
ipi_ifindex: 0,
ipi_spec_dst: unsafe {
*(v4 as *const Ipv4Addr as *const () as *const libc::in_addr)
ipi_spec_dst: libc::in_addr {
s_addr: u32::from_ne_bytes(v4.octets()),
},
ipi_addr: libc::in_addr { s_addr: 0 },
};
Expand All @@ -385,8 +385,8 @@ fn prepare_msg(
IpAddr::V6(v6) => {
let pktinfo = libc::in6_pktinfo {
ipi6_ifindex: 0,
ipi6_addr: unsafe {
*(v6 as *const Ipv6Addr as *const () as *const libc::in6_addr)
ipi6_addr: libc::in6_addr {
s6_addr: v6.octets(),
},
};
encoder.push(libc::IPPROTO_IPV6, libc::IPV6_PKTINFO, pktinfo);
Expand Down

0 comments on commit f3d82d7

Please sign in to comment.