* [PATCH wireguard-go] tun: use ByteSliceToString from golang.org/x/sys/unix
@ 2022-06-01 9:33 Tobias Klauser
2022-06-01 9:36 ` Tobias Klauser
2022-06-01 13:01 ` Jason A. Donenfeld
0 siblings, 2 replies; 3+ messages in thread
From: Tobias Klauser @ 2022-06-01 9:33 UTC (permalink / raw)
To: wireguard
Use unix.ByteSliceToString in (*NativeTun).nameSloce to convert the
TUNGETIFF ioctl result []byte to a string.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
tun/tun_linux.go | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/tun/tun_linux.go b/tun/tun_linux.go
index 89b716d9c70b..fbb8585ff449 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) {
--
2.36.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-01 13:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01 9:33 [PATCH wireguard-go] tun: use ByteSliceToString from golang.org/x/sys/unix Tobias Klauser
2022-06-01 9:36 ` Tobias Klauser
2022-06-01 13:01 ` Jason A. Donenfeld
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).