Files

50 lines
992 B
Go
Raw Permalink Normal View History

2019-01-02 01:55:51 +01:00
/* SPDX-License-Identifier: MIT
2018-05-03 15:04:00 +02:00
*
2025-05-04 17:48:53 +02:00
* Copyright (C) 2017-2025 WireGuard LLC. All Rights Reserved.
2018-05-03 15:04:00 +02:00
*/
2019-03-03 04:04:41 +01:00
package device
import (
"math/rand"
2022-03-16 16:09:48 -07:00
"net/netip"
)
type DummyEndpoint struct {
2021-11-05 01:52:54 +01:00
src, dst netip.Addr
}
func CreateDummyEndpoint() (*DummyEndpoint, error) {
2021-11-05 01:52:54 +01:00
var src, dst [16]byte
if _, err := rand.Read(src[:]); err != nil {
return nil, err
}
2021-11-05 01:52:54 +01:00
_, err := rand.Read(dst[:])
return &DummyEndpoint{netip.AddrFrom16(src), netip.AddrFrom16(dst)}, err
}
func (e *DummyEndpoint) ClearSrc() {}
func (e *DummyEndpoint) SrcToString() string {
2021-11-05 01:52:54 +01:00
return netip.AddrPortFrom(e.SrcIP(), 1000).String()
}
func (e *DummyEndpoint) DstToString() string {
2021-11-05 01:52:54 +01:00
return netip.AddrPortFrom(e.DstIP(), 1000).String()
}
2021-11-05 01:52:54 +01:00
func (e *DummyEndpoint) DstToBytes() []byte {
out := e.DstIP().AsSlice()
out = append(out, byte(1000&0xff))
out = append(out, byte((1000>>8)&0xff))
return out
}
2021-11-05 01:52:54 +01:00
func (e *DummyEndpoint) DstIP() netip.Addr {
return e.dst
}
2021-11-05 01:52:54 +01:00
func (e *DummyEndpoint) SrcIP() netip.Addr {
return e.src
}