[PATCH 02/12] tun_linux: use getDummySock()
Simon Ruderich
simon at ruderich.org
Mon Jan 1 11:52:52 CET 2018
Using this helper reduces code duplication.
---
src/tun_linux.go | 23 ++---------------------
1 file changed, 2 insertions(+), 21 deletions(-)
diff --git a/src/tun_linux.go b/src/tun_linux.go
index daa2462..b88426b 100644
--- a/src/tun_linux.go
+++ b/src/tun_linux.go
@@ -156,7 +156,6 @@ func getIFIndex(name string) (int32, error) {
if err != nil {
return 0, err
}
-
defer unix.Close(fd)
var ifr [IFReqSize]byte
@@ -177,19 +176,10 @@ func getIFIndex(name string) (int32, error) {
}
func (tun *NativeTun) setMTU(n int) error {
-
- // open datagram socket
-
- fd, err := unix.Socket(
- unix.AF_INET,
- unix.SOCK_DGRAM,
- 0,
- )
-
+ fd, err := getDummySock()
if err != nil {
return err
}
-
defer unix.Close(fd)
// do ioctl call
@@ -212,19 +202,10 @@ func (tun *NativeTun) setMTU(n int) error {
}
func (tun *NativeTun) MTU() (int, error) {
-
- // open datagram socket
-
- fd, err := unix.Socket(
- unix.AF_INET,
- unix.SOCK_DGRAM,
- 0,
- )
-
+ fd, err := getDummySock()
if err != nil {
return 0, err
}
-
defer unix.Close(fd)
// do ioctl call
--
2.15.1
More information about the WireGuard
mailing list