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