Skip to content

Commit 6a08d81

Browse files
tklauserzx2c4
authored andcommitted
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 <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent ef5c587 commit 6a08d81

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

tun/tun_linux.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package tun
99
*/
1010

1111
import (
12-
"bytes"
1312
"errors"
1413
"fmt"
1514
"os"
@@ -321,11 +320,7 @@ func (tun *NativeTun) nameSlow() (string, error) {
321320
if errno != 0 {
322321
return "", fmt.Errorf("failed to get name of TUN device: %w", errno)
323322
}
324-
name := ifr[:]
325-
if i := bytes.IndexByte(name, 0); i != -1 {
326-
name = name[:i]
327-
}
328-
return string(name), nil
323+
return unix.ByteSliceToString(ifr[:]), nil
329324
}
330325

331326
func (tun *NativeTun) Write(buf []byte, offset int) (int, error) {

0 commit comments

Comments
 (0)