aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2022-06-01 11:33:54 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2022-06-01 15:00:07 +0200
commit6a08d81f6bc465a2276c61093d96e567d00beb24 (patch)
tree718fff1c16c27e23b91bad5cb5f16529f4c3811f
parentconn: remove the final alloc per packet receive (diff)
downloadwireguard-go-6a08d81f6bc465a2276c61093d96e567d00beb24.tar.xz
wireguard-go-6a08d81f6bc465a2276c61093d96e567d00beb24.zip
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>
-rw-r--r--tun/tun_linux.go7
1 files changed, 1 insertions, 6 deletions
diff --git a/tun/tun_linux.go b/tun/tun_linux.go
index 89b716d..fbb8585 100644
--- a/tun/tun_linux.go
+++ b/tun/tun_linux.go
@@ -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) {