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:
parent
ef5c587f78
commit
6a08d81f6b
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user