diff --git a/unix/ifreq_linux.go b/unix/ifreq_linux.go index 934af313..15721a51 100644 --- a/unix/ifreq_linux.go +++ b/unix/ifreq_linux.go @@ -8,7 +8,6 @@ package unix import ( - "bytes" "unsafe" ) @@ -45,13 +44,7 @@ func NewIfreq(name string) (*Ifreq, error) { // Name returns the interface name associated with the Ifreq. func (ifr *Ifreq) Name() string { - // BytePtrToString requires a NULL terminator or the program may crash. If - // one is not present, just return the empty string. - if !bytes.Contains(ifr.raw.Ifrn[:], []byte{0x00}) { - return "" - } - - return BytePtrToString(&ifr.raw.Ifrn[0]) + return ByteSliceToString(ifr.raw.Ifrn[:]) } // According to netdevice(7), only AF_INET addresses are returned for numerous diff --git a/unix/ifreq_linux_test.go b/unix/ifreq_linux_test.go index 7a6d56cf..b81a8b63 100644 --- a/unix/ifreq_linux_test.go +++ b/unix/ifreq_linux_test.go @@ -39,17 +39,6 @@ func TestIfreqSize(t *testing.T) { } func TestIfreqName(t *testing.T) { - // Invalid ifreq (no NULL terminator), so expect empty string. - var name [IFNAMSIZ]byte - for i := range name { - name[i] = 0xff - } - - bad := &Ifreq{raw: ifreq{Ifrn: name}} - if got := bad.Name(); got != "" { - t.Fatalf("expected empty ifreq name, but got: %q", got) - } - // Valid ifreq, expect the hard-coded testIfreq name. ifr := testIfreq(t) if want, got := ifreqName, ifr.Name(); want != got {