aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform/linux/uapi.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-15 15:32:36 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-15 15:32:36 +0100
commit05710c455f1c759cf9bc1a1eaa6307fe564f15cc (patch)
treec671d703d0db93a9bc8f27d0e2b02d0422120352 /src/platform/linux/uapi.rs
parentInitial version of full UAPI parser (diff)
downloadwireguard-rs-05710c455f1c759cf9bc1a1eaa6307fe564f15cc.tar.xz
wireguard-rs-05710c455f1c759cf9bc1a1eaa6307fe564f15cc.zip
Update UAPI semantics for remove
Diffstat (limited to 'src/platform/linux/uapi.rs')
-rw-r--r--src/platform/linux/uapi.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/platform/linux/uapi.rs b/src/platform/linux/uapi.rs
new file mode 100644
index 0000000..fdf2bf0
--- /dev/null
+++ b/src/platform/linux/uapi.rs
@@ -0,0 +1,31 @@
+use super::super::uapi::*;
+
+use std::fs;
+use std::io;
+use std::os::unix::net::{UnixListener, UnixStream};
+
+const SOCK_DIR: &str = "/var/run/wireguard/";
+
+pub struct LinuxUAPI {}
+
+impl PlatformUAPI for LinuxUAPI {
+ type Error = io::Error;
+ type Bind = UnixListener;
+
+ fn bind(name: &str) -> Result<UnixListener, io::Error> {
+ let socket_path = format!("{}{}.sock", SOCK_DIR, name);
+ let _ = fs::create_dir_all(SOCK_DIR);
+ let _ = fs::remove_file(&socket_path);
+ UnixListener::bind(socket_path)
+ }
+}
+
+impl BindUAPI for UnixListener {
+ type Stream = UnixStream;
+ type Error = io::Error;
+
+ fn accept(&self) -> Result<UnixStream, io::Error> {
+ let (stream, _) = self.accept()?;
+ Ok(stream)
+ }
+}