]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: use ByteSliceToString from golang.org/x/sys/unix
authorTobias Klauser <tklauser@distanz.ch>
Wed, 1 Jun 2022 09:33:54 +0000 (11:33 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 1 Jun 2022 13:00:07 +0000 (15:00 +0200)
Use unix.ByteSliceToString in (*NativeTun).nameSlice to convert the
TUNGETIFF ioctl result []byte to a string.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
tun/tun_linux.go

index 89b716d9c70b04ac47b9b54dac9b63679e067dc0..fbb8585ff449a5f540810a42ef8cc7b30d867e93 100644 (file)
@@ -9,7 +9,6 @@ package tun
  */
 
 import (
-       "bytes"
        "errors"
        "fmt"
        "os"
@@ -321,11 +320,7 @@ func (tun *NativeTun) nameSlow() (string, error) {
        if errno != 0 {
                return "", fmt.Errorf("failed to get name of TUN device: %w", errno)
        }
-       name := ifr[:]
-       if i := bytes.IndexByte(name, 0); i != -1 {
-               name = name[:i]
-       }
-       return string(name), nil
+       return unix.ByteSliceToString(ifr[:]), nil
 }
 
 func (tun *NativeTun) Write(buf []byte, offset int) (int, error) {