[Protocol] Enable the use of Ipv6 addresses (#41)

Replace usages of Ipv4Addr with IpAddr which allows the use of either Ipv4 or Ipv6.

This patch essentially consists of running:
"sed -i 's/Ipv4Addr/IpAddr/g' src/**/*.rs examples/*"
and fixing the errors.
This commit is contained in:
Tom 2023-05-29 08:10:21 +00:00 committed by GitHub
parent e620398615
commit 3f654e0dfd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
60 changed files with 155 additions and 162 deletions

View file

@ -4,7 +4,7 @@ use crate::{
};
use std::cmp::Ordering;
use std::net::Ipv4Addr;
use std::net::IpAddr;
pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
match size.cmp(&expected) {
@ -14,18 +14,18 @@ pub fn error_by_expected_size(expected: usize, size: usize) -> GDResult<()> {
}
}
pub fn address_and_port_as_string(address: &Ipv4Addr, port: u16) -> String { format!("{}:{}", address, port) }
pub fn address_and_port_as_string(address: &IpAddr, port: u16) -> String { format!("{}:{}", address, port) }
pub fn u8_lower_upper(n: u8) -> (u8, u8) { (n & 15, n >> 4) }
#[cfg(test)]
mod tests {
use std::net::Ipv4Addr;
use std::net::{IpAddr, Ipv4Addr};
#[test]
fn address_and_port_as_string() {
assert_eq!(
super::address_and_port_as_string(&Ipv4Addr::new(192, 168, 0, 1), 27015),
super::address_and_port_as_string(&IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)), 27015),
"192.168.0.1:27015"
);
}