Skip to content

net: connecting to 0.0.0.0 fails on windows #6290

@alexbrainman

Description

@alexbrainman
What steps will reproduce the problem?

run this program on windows

package main

import (
    "log"
    "net"
)

func dial() error {
    l, err := net.Listen("tcp", ":0")
    if err != nil {
        return err
    }

    go func() {
        c, err := l.Accept()
        if err != nil {
            return
        }
        c.Close()
    }()

    c, err := net.Dial("tcp", l.Addr().String())
    if err != nil {
        return err
    }
    c.Close()
    return nil
}

func main() {
    err := dial()
    if err != nil {
        log.Fatal(err)
    }
}


What is the expected output?

Should output noting.

What do you see instead?

2013/08/30 16:43:22 dial tcp 0.0.0.0:1406: ConnectEx tcp: The format of the specified
network name is invalid.

Please use labels and text to provide additional information.

The problem seems to be that l.Addr().String() returns '0.0.0.0', but connecting to that
address is not allowed on windows. From
http://msdn.microsoft.com/en-us/library/aa923167.aspx

" ... If the address member of the structure specified by the name parameter is
all zeroes, connect will return the error WSAEADDRNOTAVAIL. ..."

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.OS-Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions