1
0
mirror of https://git.zx2c4.com/wireguard-go synced 2024-11-15 01:05:15 +01:00

tun: use ByteSliceToString from golang.org/x/sys/unix

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>
This commit is contained in:
Tobias Klauser 2022-06-01 11:33:54 +02:00 committed by Jason A. Donenfeld
parent ef5c587f78
commit 6a08d81f6b

View File

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