2019-03-03 04:01:06 +00:00
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|