2019-03-03 05:01:06 +01:00
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
2020-05-02 10:08:26 +02:00
|
|
|
* Copyright (C) 2017-2020 WireGuard LLC. All Rights Reserved.
|
2019-03-03 05:01:06 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package device
|
|
|
|
|
2019-05-17 15:35:20 +02:00
|
|
|
import "errors"
|
|
|
|
|
2019-03-03 05:01:06 +01:00
|
|
|
func (device *Device) PeekLookAtSocketFd4() (fd int, err error) {
|
2019-05-17 15:35:20 +02:00
|
|
|
nb, ok := device.net.bind.(*nativeBind)
|
|
|
|
if !ok {
|
|
|
|
return 0, errors.New("no socket exists")
|
|
|
|
}
|
|
|
|
sysconn, err := nb.ipv4.SyscallConn()
|
2019-03-03 05:01:06 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = sysconn.Control(func(f uintptr) {
|
|
|
|
fd = int(f)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (device *Device) PeekLookAtSocketFd6() (fd int, err error) {
|
2019-05-17 15:35:20 +02:00
|
|
|
nb, ok := device.net.bind.(*nativeBind)
|
|
|
|
if !ok {
|
|
|
|
return 0, errors.New("no socket exists")
|
|
|
|
}
|
|
|
|
sysconn, err := nb.ipv6.SyscallConn()
|
2019-03-03 05:01:06 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = sysconn.Control(func(f uintptr) {
|
|
|
|
fd = int(f)
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|