Skip to content

Commit

Permalink
Merge pull request #5 from Ma27/ipv6-support
Browse files Browse the repository at this point in the history
Parse strings using `std::net` to support peers with IPv6 addresses
  • Loading branch information
MindFlavor committed Jun 3, 2019
2 parents b9f0357 + 1b4a7a2 commit b43eff8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/wireguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ use crate::wireguard_config::PeerEntryHashMap;
use log::{debug, trace};
use std::collections::HashMap;
use std::convert::TryFrom;
use std::net::SocketAddr;

const EMPTY: &str = "(none)";

#[derive(Default, Debug, Clone)]
pub(crate) struct LocalEndpoint {
pub public_key: String,
pub private_key: String,
pub local_port: u32,
pub local_port: u16,
pub persistent_keepalive: bool,
}

#[derive(Debug, Clone)]
pub(crate) struct RemoteEndpoint {
pub public_key: String,
pub remote_ip: Option<String>,
pub remote_port: Option<u32>,
pub remote_port: Option<u16>,
pub local_ip: String,
pub local_subnet: String,
pub latest_handshake: u64,
Expand Down Expand Up @@ -69,18 +70,19 @@ impl TryFrom<&str> for WireGuard {
Endpoint::Local(LocalEndpoint {
public_key: v[1].to_owned(),
private_key: v[2].to_owned(),
local_port: v[3].parse::<u32>().unwrap(),
local_port: v[3].parse::<u16>().unwrap(),
persistent_keepalive: to_bool(v[4]),
})
} else {
// remote endpoint
let public_key = v[1].to_owned();

let (remote_ip, remote_port) = if let Some(ip_and_port) = to_option_string(v[3]) {
let toks: Vec<&str> = ip_and_port.split(':').collect();
let addr: SocketAddr = ip_and_port.parse::<SocketAddr>().unwrap();

(
Some(toks[0].to_owned()),
Some(toks[1].parse::<u32>().unwrap()),
Some(addr.ip().to_string()),
Some(addr.port()),
)
} else {
(None, None)
Expand Down

0 comments on commit b43eff8

Please sign in to comment.