From a0f54cbe5ac2cd8b8296c2c57c30029dd349cff0 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sun, 4 Feb 2018 16:08:26 +0100 Subject: Align with go library layout --- uapi_windows.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 uapi_windows.go (limited to 'uapi_windows.go') diff --git a/uapi_windows.go b/uapi_windows.go new file mode 100644 index 0000000..a4599a5 --- /dev/null +++ b/uapi_windows.go @@ -0,0 +1,44 @@ +package main + +/* UAPI on windows uses a bidirectional named pipe + */ + +import ( + "fmt" + "github.com/Microsoft/go-winio" + "golang.org/x/sys/windows" + "net" +) + +const ( + ipcErrorIO = -int64(windows.ERROR_BROKEN_PIPE) + ipcErrorProtocol = -int64(windows.ERROR_INVALID_NAME) + ipcErrorInvalid = -int64(windows.ERROR_INVALID_PARAMETER) + ipcErrorPortInUse = -int64(windows.ERROR_ALREADY_EXISTS) +) + +const PipeNameFmt = "\\\\.\\pipe\\wireguard-ipc-%s" + +type UAPIListener struct { + listener net.Listener +} + +func (uapi *UAPIListener) Accept() (net.Conn, error) { + return nil, nil +} + +func (uapi *UAPIListener) Close() error { + return uapi.listener.Close() +} + +func (uapi *UAPIListener) Addr() net.Addr { + return nil +} + +func NewUAPIListener(name string) (net.Listener, error) { + path := fmt.Sprintf(PipeNameFmt, name) + return winio.ListenPipe(path, &winio.PipeConfig{ + InputBufferSize: 2048, + OutputBufferSize: 2048, + }) +} -- cgit v1.2.3-59-g8ed1b