Skip to content

Commit

Permalink
tun: use ByteSliceToString from golang.org/x/sys/unix
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
tklauser authored and zx2c4 committed Jun 1, 2022
1 parent ef5c587 commit 6a08d81
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions tun/tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package tun
*/

import (
"bytes"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6a08d81

Please sign in to comment.