mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-18 09:35:50 +00:00
[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:
parent
e620398615
commit
3f654e0dfd
60 changed files with 155 additions and 162 deletions
|
|
@ -9,12 +9,12 @@ use std::{
|
|||
io::{Read, Write},
|
||||
net,
|
||||
};
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::IpAddr;
|
||||
|
||||
const DEFAULT_PACKET_SIZE: usize = 1024;
|
||||
|
||||
pub trait Socket {
|
||||
fn new(address: &Ipv4Addr, port: u16) -> GDResult<Self>
|
||||
fn new(address: &IpAddr, port: u16) -> GDResult<Self>
|
||||
where Self: Sized;
|
||||
|
||||
fn apply_timeout(&self, timeout_settings: Option<TimeoutSettings>) -> GDResult<()>;
|
||||
|
|
@ -28,7 +28,7 @@ pub struct TcpSocket {
|
|||
}
|
||||
|
||||
impl Socket for TcpSocket {
|
||||
fn new(address: &Ipv4Addr, port: u16) -> GDResult<Self> {
|
||||
fn new(address: &IpAddr, port: u16) -> GDResult<Self> {
|
||||
let complete_address = address_and_port_as_string(address, port);
|
||||
|
||||
Ok(Self {
|
||||
|
|
@ -65,7 +65,7 @@ pub struct UdpSocket {
|
|||
}
|
||||
|
||||
impl Socket for UdpSocket {
|
||||
fn new(address: &Ipv4Addr, port: u16) -> GDResult<Self> {
|
||||
fn new(address: &IpAddr, port: u16) -> GDResult<Self> {
|
||||
let complete_address = address_and_port_as_string(address, port);
|
||||
let socket = net::UdpSocket::bind("0.0.0.0:0").map_err(|_| SocketBind)?;
|
||||
|
||||
|
|
@ -100,7 +100,6 @@ impl Socket for UdpSocket {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::net::IpAddr;
|
||||
use std::thread;
|
||||
|
||||
use super::*;
|
||||
|
|
@ -117,10 +116,7 @@ mod tests {
|
|||
stream.write(&buf).unwrap();
|
||||
});
|
||||
|
||||
let address = match bound_address.ip() {
|
||||
IpAddr::V4(a) => a,
|
||||
_ => panic!("address not ipv4!")
|
||||
};
|
||||
let address = bound_address.ip();
|
||||
|
||||
// Create a TCP socket and send a message to the server
|
||||
let mut socket = TcpSocket::new(&address, bound_address.port()).unwrap();
|
||||
|
|
@ -153,10 +149,7 @@ mod tests {
|
|||
socket.send_to(&buf, src_addr).unwrap();
|
||||
});
|
||||
|
||||
let address = match bound_address.ip() {
|
||||
IpAddr::V4(a) => a,
|
||||
_ => panic!("address not ipv4!")
|
||||
};
|
||||
let address = bound_address.ip();
|
||||
|
||||
// Create a UDP socket and send a message to the server
|
||||
let mut socket = UdpSocket::new(&address, bound_address.port()).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue