summaryrefslogtreecommitdiffhomepage
path: root/uapi_windows.go
blob: 01f550593f978a7a5c858ede8eab5b7bb3c189fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* SPDX-License-Identifier: GPL-2.0
 *
 * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
 */

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,
	})
}