Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use core::net types for IpAddress #1000

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ mod wire {
extern crate test;

#[cfg(feature = "proto-ipv6")]
const SRC_ADDR: IpAddress = IpAddress::Ipv6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1));
const SRC_ADDR: IpAddress = IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1));
#[cfg(feature = "proto-ipv6")]
const DST_ADDR: IpAddress = IpAddress::Ipv6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 2));
const DST_ADDR: IpAddress = IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 2));

#[cfg(all(not(feature = "proto-ipv6"), feature = "proto-ipv4"))]
const SRC_ADDR: IpAddress = IpAddress::Ipv4(Ipv4Address::new(192, 168, 1, 1));
Expand Down
7 changes: 5 additions & 2 deletions examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::socket::tcp;
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};

const AMOUNT: usize = 1_000_000_000;

Expand Down Expand Up @@ -98,7 +98,10 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
});

Expand Down
15 changes: 12 additions & 3 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfdaa, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfdaa, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
});
iface
Expand Down
15 changes: 12 additions & 3 deletions examples/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfdaa, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfdaa, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
});
iface
Expand Down
15 changes: 12 additions & 3 deletions examples/httpclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfdaa, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfdaa, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
});
iface
Expand Down
13 changes: 10 additions & 3 deletions examples/loopback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{Device, Loopback, Medium};
use smoltcp::socket::tcp;
use smoltcp::time::{Duration, Instant};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};

#[cfg(not(feature = "std"))]
mod mock {
Expand Down Expand Up @@ -93,7 +93,10 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(127, 0, 0, 1)),
8,
))
.unwrap();
});

Expand Down Expand Up @@ -153,7 +156,11 @@ fn main() {
if !did_connect {
debug!("connecting");
socket
.connect(cx, (IpAddress::v4(127, 0, 0, 1), 1234), 65000)
.connect(
cx,
(IpAddress::V4(Ipv4Address::new(127, 0, 0, 1)), 1234),
65000,
)
.unwrap();
did_connect = true;
}
Expand Down
13 changes: 10 additions & 3 deletions examples/loopback_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{Device, Loopback, Medium};
use smoltcp::socket::tcp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};

fn main() {
let device = Loopback::new(Medium::Ethernet);
Expand All @@ -33,7 +33,10 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(127, 0, 0, 1), 8))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(127, 0, 0, 1)),
8,
))
.unwrap();
});

Expand Down Expand Up @@ -81,7 +84,11 @@ fn main() {
if !socket.is_open() && !did_connect {
debug!("connecting");
socket
.connect(cx, (IpAddress::v4(127, 0, 0, 1), 1234), 65000)
.connect(
cx,
(IpAddress::V4(Ipv4Address::new(127, 0, 0, 1)), 1234),
65000,
)
.unwrap();
did_connect = true;
}
Expand Down
26 changes: 15 additions & 11 deletions examples/multicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use smoltcp::phy::{wait as phy_wait, Device, Medium};
use smoltcp::socket::{raw, udp};
use smoltcp::time::Instant;
use smoltcp::wire::{
EthernetAddress, IgmpPacket, IgmpRepr, IpAddress, IpCidr, IpProtocol, IpVersion, Ipv4Address,
Ipv4Packet, Ipv6Address,
EthernetAddress, IgmpPacket, IgmpRepr, IpAddress, IpCidr, IpProtocol, Ipv4Address, Ipv4Packet,
Ipv6Address,
};

const MDNS_PORT: u16 = 5353;
Expand Down Expand Up @@ -40,13 +40,22 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfdaa, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfdaa, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
});
iface
Expand All @@ -65,12 +74,7 @@ fn main() {
let raw_rx_buffer = raw::PacketBuffer::new(vec![raw::PacketMetadata::EMPTY; 2], vec![0; 512]);
// Will not send IGMP
let raw_tx_buffer = raw::PacketBuffer::new(vec![], vec![]);
let raw_socket = raw::Socket::new(
IpVersion::Ipv4,
IpProtocol::Igmp,
raw_rx_buffer,
raw_tx_buffer,
);
let raw_socket = raw::Socket::new_v4(IpProtocol::Igmp, raw_rx_buffer, raw_tx_buffer);
let raw_handle = sockets.add(raw_socket);

// Must fit mDNS payload of at least one packet
Expand Down
23 changes: 16 additions & 7 deletions examples/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,22 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfdaa, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfdaa, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
});
iface
Expand Down Expand Up @@ -164,7 +173,7 @@ fn main() {
NetworkEndian::write_i64(&mut echo_payload, timestamp.total_millis());

match remote_addr {
IpAddress::Ipv4(_) => {
IpAddress::V4(_) => {
let (icmp_repr, mut icmp_packet) = send_icmp_ping!(
Icmpv4Repr,
Icmpv4Packet,
Expand All @@ -176,7 +185,7 @@ fn main() {
);
icmp_repr.emit(&mut icmp_packet, &device_caps.checksum);
}
IpAddress::Ipv6(address) => {
IpAddress::V6(address) => {
let (icmp_repr, mut icmp_packet) = send_icmp_ping!(
Icmpv6Repr,
Icmpv6Packet,
Expand Down Expand Up @@ -204,7 +213,7 @@ fn main() {
let (payload, _) = socket.recv().unwrap();

match remote_addr {
IpAddress::Ipv4(_) => {
IpAddress::V4(_) => {
let icmp_packet = Icmpv4Packet::new_checked(&payload).unwrap();
let icmp_repr = Icmpv4Repr::parse(&icmp_packet, &device_caps.checksum).unwrap();
get_icmp_pong!(
Expand All @@ -217,7 +226,7 @@ fn main() {
received
);
}
IpAddress::Ipv6(address) => {
IpAddress::V6(address) => {
let icmp_packet = Icmpv6Packet::new_checked(&payload).unwrap();
let icmp_repr = Icmpv6Repr::parse(
&address,
Expand Down
15 changes: 12 additions & 3 deletions examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,22 @@ fn main() {
let mut iface = Interface::new(config, &mut device, Instant::now());
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(IpAddress::v4(192, 168, 69, 1), 24))
.push(IpCidr::new(
IpAddress::V4(Ipv4Address::new(192, 168, 69, 1)),
24,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfdaa, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfdaa, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
ip_addrs
.push(IpCidr::new(IpAddress::v6(0xfe80, 0, 0, 0, 0, 0, 0, 1), 64))
.push(IpCidr::new(
IpAddress::V6(Ipv6Address::new(0xfe80, 0, 0, 0, 0, 0, 0, 1)),
64,
))
.unwrap();
});
iface
Expand Down
8 changes: 6 additions & 2 deletions examples/sixlowpan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ use smoltcp::phy::{wait as phy_wait, Device, Medium, RawSocket};
use smoltcp::socket::tcp;
use smoltcp::socket::udp;
use smoltcp::time::Instant;
use smoltcp::wire::{EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr};
use smoltcp::wire::{
EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr, Ipv6Address,
};

fn main() {
utils::setup_logging("");
Expand Down Expand Up @@ -83,7 +85,9 @@ fn main() {
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(
IpAddress::v6(0xfe80, 0, 0, 0, 0x180b, 0x4242, 0x4242, 0x4242),
IpAddress::V6(Ipv6Address::new(
0xfe80, 0, 0, 0, 0x180b, 0x4242, 0x4242, 0x4242,
)),
64,
))
.unwrap();
Expand Down
8 changes: 6 additions & 2 deletions examples/sixlowpan_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ use std::str;
use smoltcp::iface::{Config, Interface, SocketSet};
use smoltcp::phy::{wait as phy_wait, Device, Medium, RawSocket};
use smoltcp::socket::tcp;
use smoltcp::wire::{EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr};
use smoltcp::wire::{
EthernetAddress, Ieee802154Address, Ieee802154Pan, IpAddress, IpCidr, Ipv6Address,
};

//For benchmark
use smoltcp::time::{Duration, Instant};
Expand Down Expand Up @@ -163,7 +165,9 @@ fn main() {
iface.update_ip_addrs(|ip_addrs| {
ip_addrs
.push(IpCidr::new(
IpAddress::v6(0xfe80, 0, 0, 0, 0x180b, 0x4242, 0x4242, 0x4242),
IpAddress::V6(Ipv6Address::new(
0xfe80, 0, 0, 0, 0x180b, 0x4242, 0x4242, 0x4242,
)),
64,
))
.unwrap();
Expand Down
Loading
Loading