Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@distanz.ch>
To: wireguard@lists.zx2c4.com
Subject: [PATCH wireguard-go] tun: use ByteSliceToString from golang.org/x/sys/unix
Date: Wed,  1 Jun 2022 11:33:54 +0200	[thread overview]
Message-ID: <20220601093354.30833-1-tklauser@distanz.ch> (raw)

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


             reply	other threads:[~2022-06-01  9:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01  9:33 Tobias Klauser [this message]
2022-06-01  9:36 ` Tobias Klauser
2022-06-01 13:01 ` Jason A. Donenfeld

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220601093354.30833-1-tklauser@distanz.ch \
    --to=tklauser@distanz.ch \
    --cc=wireguard@lists.zx2c4.com \
    --subject='Re: [PATCH wireguard-go] tun: use ByteSliceToString from golang.org/x/sys/unix' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).