Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net.Interfaces on Linux have null-terminated Names #1942

Closed
kylelemons opened this issue Jun 10, 2011 · 2 comments
Closed

net.Interfaces on Linux have null-terminated Names #1942

kylelemons opened this issue Jun 10, 2011 · 2 comments

Comments

@kylelemons
Copy link
Contributor

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
package main

import "net"
import "log"

func main() {
    for i := 1;; i++ {
        iface, err := net.InterfaceByIndex(i)
        if err != nil {
            log.Printf("iface: %s\n", err)
            break
        }
        log.Printf("Interface %q\n", iface.Name)
        if !iface.IsUp() {
            log.Printf(" - Down\n")
            continue
        }
        log.Printf(" - MAC : %s\n", iface.HardwareAddr)
        addrs, err := iface.Addrs()
        if err != nil {
            log.Printf("iface: %s\n", err)
            continue
        }
        for _, addr := range addrs {
            log.Printf(" - Addr: %s\n", addr)
        }
    }
}

What is the expected output?
2011/06/10 08:46:43 Interface "lo" //<--
2011/06/10 08:46:43  - MAC : 
2011/06/10 08:46:43  - Addr: 127.0.0.1
2011/06/10 08:46:43  - Addr: ::1
2011/06/10 08:46:43 Interface "eth0"
2011/06/10 08:46:43  - MAC : <REDACTED>
2011/06/10 08:46:43  - Addr: <REDACTED>

What do you see instead?
2011/06/10 08:46:43 Interface "lo\x00" //<--
2011/06/10 08:46:43  - MAC : 
2011/06/10 08:46:43  - Addr: 127.0.0.1
2011/06/10 08:46:43  - Addr: ::1
2011/06/10 08:46:43 Interface "eth0\x00"
2011/06/10 08:46:43  - MAC : <REDACTED>
2011/06/10 08:46:43  - Addr: <REDACTED>


Which compiler are you using (5g, 6g, 8g, gccgo)?
6g version weekly.2011-06-09 8707+

Which operating system are you using?
Linux x86_64

Which revision are you using?  (hg identify)
8818ac606e92+ tip

Please provide any additional information below.
I suspect this line needs a "[:len(...)-1]":
http://localhost:8080/src/pkg/net/interface_linux.go#L115
@robpike
Copy link
Contributor

robpike commented Jun 12, 2011

Comment 1:

Owner changed to @rsc.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Jun 14, 2011

Comment 2:

This issue was closed by revision c4dfc55.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants