summaryrefslogtreecommitdiffhomepage
path: root/device/endpoint_test.go
blob: 57c361ca6fab484989e32fdd83a551642dffd79d (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
50
51
52
53
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
 */

package device

import (
	"math/rand"
	"net"
)

type DummyEndpoint struct {
	src [16]byte
	dst [16]byte
}

func CreateDummyEndpoint() (*DummyEndpoint, error) {
	var end DummyEndpoint
	if _, err := rand.Read(end.src[:]); err != nil {
		return nil, err
	}
	_, err := rand.Read(end.dst[:])
	return &end, err
}

func (e *DummyEndpoint) ClearSrc() {}

func (e *DummyEndpoint) SrcToString() string {
	var addr net.UDPAddr
	addr.IP = e.SrcIP()
	addr.Port = 1000
	return addr.String()
}

func (e *DummyEndpoint) DstToString() string {
	var addr net.UDPAddr
	addr.IP = e.DstIP()
	addr.Port = 1000
	return addr.String()
}

func (e *DummyEndpoint) SrcToBytes() []byte {
	return e.src[:]
}

func (e *DummyEndpoint) DstIP() net.IP {
	return e.dst[:]
}

func (e *DummyEndpoint) SrcIP() net.IP {
	return e.src[:]
}