Skip to content

Commit 0454c3f

Browse files
batoniuswhitequark
authored andcommittedSep 24, 2017
Uncomment associated constants.
1 parent 081851d commit 0454c3f

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ include complicated compile-time computations, such as macro or type tricks, eve
66
at cost of performance degradation.
77

88
_smoltcp_ does not need heap allocation *at all*, is [extensively documented][docs],
9-
and compiles on stable Rust 1.19 and later.
9+
and compiles on stable Rust 1.20 and later.
1010

1111
[docs]: https://docs.rs/smoltcp/
1212

‎src/iface/ethernet.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
517517
}
518518

519519
if dst_addr.is_broadcast() {
520-
return Ok(EthernetAddress([0xff; 6]))
520+
return Ok(EthernetAddress::BROADCAST)
521521
}
522522

523523
match (src_addr, dst_addr) {
@@ -529,12 +529,12 @@ impl<'a, 'b, 'c, DeviceT: Device + 'a> Interface<'a, 'b, 'c, DeviceT> {
529529
operation: ArpOperation::Request,
530530
source_hardware_addr: self.hardware_addr,
531531
source_protocol_addr: src_addr,
532-
target_hardware_addr: EthernetAddress([0xff; 6]),
532+
target_hardware_addr: EthernetAddress::BROADCAST,
533533
target_protocol_addr: dst_addr,
534534
};
535535

536536
self.dispatch_ethernet(timestamp, arp_repr.buffer_len(), |mut frame| {
537-
frame.set_dst_addr(EthernetAddress([0xff; 6]));
537+
frame.set_dst_addr(EthernetAddress::BROADCAST);
538538
frame.set_ethertype(EthernetProtocol::Arp);
539539

540540
arp_repr.emit(&mut ArpPacket::new(frame.payload_mut()))

‎src/wire/ethernet.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl fmt::Display for EtherType {
2828
pub struct Address(pub [u8; 6]);
2929

3030
impl Address {
31-
// pub const BROADCAST: Address = Address([0xff; 6]);
31+
pub const BROADCAST: Address = Address([0xff; 6]);
3232

3333
/// Construct an Ethernet address from a sequence of octets, in big-endian.
3434
///
@@ -53,7 +53,7 @@ impl Address {
5353

5454
/// Query whether this address is the broadcast address.
5555
pub fn is_broadcast(&self) -> bool {
56-
self.0 == [0xff; 6]
56+
*self == Self::BROADCAST
5757
}
5858

5959
/// Query whether the "multicast" bit in the OUI is set.
@@ -270,4 +270,12 @@ mod test {
270270
frame.payload_mut().copy_from_slice(&PAYLOAD_BYTES[..]);
271271
assert_eq!(&frame.into_inner()[..], &FRAME_BYTES[..]);
272272
}
273+
274+
#[test]
275+
fn test_broadcast() {
276+
assert!(Address::BROADCAST.is_broadcast());
277+
assert!(!Address::BROADCAST.is_unicast());
278+
assert!(Address::BROADCAST.is_multicast());
279+
assert!(Address::BROADCAST.is_local());
280+
}
273281
}

‎src/wire/ip.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ impl Address {
9999
pub fn to_unspecified(&self) -> Address {
100100
match self {
101101
&Address::Unspecified => Address::Unspecified,
102-
// &Address::Ipv4 => Address::Ipv4(Ipv4Address::UNSPECIFIED),
103-
&Address::Ipv4(_) => Address::Ipv4(Ipv4Address(/*FIXME*/[0x00; 4])),
102+
&Address::Ipv4(_) => Address::Ipv4(Ipv4Address::UNSPECIFIED),
104103
}
105104
}
106105
}
@@ -136,7 +135,7 @@ pub struct Endpoint {
136135
}
137136

138137
impl Endpoint {
139-
// pub const UNSPECIFIED: Endpoint = Endpoint { addr: Address::Unspecified, port: 0 };
138+
pub const UNSPECIFIED: Endpoint = Endpoint { addr: Address::Unspecified, port: 0 };
140139

141140
/// Create an endpoint address from given address and port.
142141
pub fn new(addr: Address, port: u16) -> Endpoint {
@@ -487,7 +486,7 @@ mod test {
487486

488487
assert_eq!(
489488
IpRepr::Ipv4(Ipv4Repr{
490-
src_addr: Ipv4Address::new(0, 0, 0, 0),
489+
src_addr: Ipv4Address::UNSPECIFIED,
491490
dst_addr: ip_addr_b,
492491
protocol: proto,
493492
payload_len
@@ -497,7 +496,7 @@ mod test {
497496

498497
assert_eq!(
499498
IpRepr::Ipv4(Ipv4Repr{
500-
src_addr: Ipv4Address::new(0, 0, 0, 0),
499+
src_addr: Ipv4Address::UNSPECIFIED,
501500
dst_addr: ip_addr_b,
502501
protocol: proto,
503502
payload_len
@@ -510,4 +509,9 @@ mod test {
510509
}))
511510
);
512511
}
512+
513+
#[test]
514+
fn endpoint_unspecified() {
515+
assert!(!Endpoint::UNSPECIFIED.is_specified());
516+
}
513517
}

‎src/wire/ipv4.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub use super::IpProtocol as Protocol;
1212
pub struct Address(pub [u8; 4]);
1313

1414
impl Address {
15-
// pub const UNSPECIFIED: Address = Address([0x00; 4]);
16-
// pub const BROADCAST: Address = Address([0xff; 4]);
15+
pub const UNSPECIFIED: Address = Address([0x00; 4]);
16+
pub const BROADCAST: Address = Address([0xff; 4]);
1717

1818
/// Construct an IPv4 address from parts.
1919
pub fn new(a0: u8, a1: u8, a2: u8, a3: u8) -> Address {
@@ -668,4 +668,22 @@ mod test {
668668
packet.payload_mut().copy_from_slice(&REPR_PAYLOAD_BYTES);
669669
assert_eq!(&packet.into_inner()[..], &REPR_PACKET_BYTES[..]);
670670
}
671+
672+
#[test]
673+
fn test_unspecified() {
674+
assert!(Address::UNSPECIFIED.is_unspecified());
675+
assert!(!Address::UNSPECIFIED.is_broadcast());
676+
assert!(!Address::UNSPECIFIED.is_multicast());
677+
assert!(!Address::UNSPECIFIED.is_link_local());
678+
assert!(!Address::UNSPECIFIED.is_loopback());
679+
}
680+
681+
#[test]
682+
fn test_broadcast() {
683+
assert!(!Address::BROADCAST.is_unspecified());
684+
assert!(Address::BROADCAST.is_broadcast());
685+
assert!(!Address::BROADCAST.is_multicast());
686+
assert!(!Address::BROADCAST.is_link_local());
687+
assert!(!Address::BROADCAST.is_loopback());
688+
}
671689
}

0 commit comments

Comments
 (0)
Please sign in to comment.