Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bd52f9b83cd2
Choose a base ref
...
head repository: smoltcp-rs/smoltcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d16e0bd21293
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 3, 2017

  1. Make sure IpAddress prohibits exhaustive matches.

    I forgot to ensure this.
    whitequark committed Oct 3, 2017
    Copy the full SHA
    02658d0 View commit details
  2. Formatting. NFC.

    whitequark committed Oct 3, 2017
    Copy the full SHA
    d16e0bd View commit details
Showing with 19 additions and 9 deletions.
  1. +3 −3 src/iface/ethernet.rs
  2. +16 −6 src/wire/ip.rs
6 changes: 3 additions & 3 deletions src/iface/ethernet.rs
Original file line number Diff line number Diff line change
@@ -353,8 +353,8 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
}
}

fn process_icmpv4<'frame>(&self, ipv4_repr: Ipv4Repr,
ip_payload: &'frame [u8]) -> Result<Packet<'frame>> {
fn process_icmpv4<'frame>(&self, ipv4_repr: Ipv4Repr, ip_payload: &'frame [u8]) ->
Result<Packet<'frame>> {
let icmp_packet = Icmpv4Packet::new_checked(ip_payload)?;
let checksum_caps = self.device.capabilities().checksum;
let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &checksum_caps)?;
@@ -491,7 +491,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
Packet::Udp((ip_repr, udp_repr)) => {
self.dispatch_ip(timestamp, ip_repr, |ip_repr, payload| {
udp_repr.emit(&mut UdpPacket::new(payload),
&ip_repr.src_addr(), &ip_repr.dst_addr(),
&ip_repr.src_addr(), &ip_repr.dst_addr(),
&checksum_caps);
})
}
22 changes: 16 additions & 6 deletions src/wire/ip.rs
Original file line number Diff line number Diff line change
@@ -63,7 +63,9 @@ pub enum Address {
/// May be used as a placeholder for storage where the address is not assigned yet.
Unspecified,
/// An IPv4 address.
Ipv4(Ipv4Address)
Ipv4(Ipv4Address),
#[doc(hidden)]
__Nonexhaustive
}

impl Address {
@@ -76,23 +78,26 @@ impl Address {
pub fn is_unicast(&self) -> bool {
match self {
&Address::Unspecified => false,
&Address::Ipv4(addr) => addr.is_unicast()
&Address::Ipv4(addr) => addr.is_unicast(),
&Address::__Nonexhaustive => unreachable!()
}
}

/// Query whether the address is the broadcast address.
pub fn is_broadcast(&self) -> bool {
match self {
&Address::Unspecified => false,
&Address::Ipv4(addr) => addr.is_broadcast()
&Address::Ipv4(addr) => addr.is_broadcast(),
&Address::__Nonexhaustive => unreachable!()
}
}

/// Query whether the address falls into the "unspecified" range.
pub fn is_unspecified(&self) -> bool {
match self {
&Address::Unspecified => true,
&Address::Ipv4(addr) => addr.is_unspecified()
&Address::Ipv4(addr) => addr.is_unspecified(),
&Address::__Nonexhaustive => unreachable!()
}
}

@@ -101,6 +106,7 @@ impl Address {
match self {
&Address::Unspecified => Address::Unspecified,
&Address::Ipv4(_) => Address::Ipv4(Ipv4Address::UNSPECIFIED),
&Address::__Nonexhaustive => unreachable!()
}
}
}
@@ -121,7 +127,8 @@ impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&Address::Unspecified => write!(f, "*"),
&Address::Ipv4(addr) => write!(f, "{}", addr)
&Address::Ipv4(addr) => write!(f, "{}", addr),
&Address::__Nonexhaustive => unreachable!()
}
}
}
@@ -316,7 +323,10 @@ impl IpRepr {
}
},

&IpRepr::__Nonexhaustive => unreachable!()
&IpRepr::__Nonexhaustive |
&IpRepr::Unspecified { src_addr: Address::__Nonexhaustive, .. } |
&IpRepr::Unspecified { dst_addr: Address::__Nonexhaustive, .. } =>
unreachable!()
}
}