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: WriteToIP generates "socket is already connected" error #7887

Closed
gopherbot opened this issue Apr 28, 2014 · 4 comments
Closed

net: WriteToIP generates "socket is already connected" error #7887

gopherbot opened this issue Apr 28, 2014 · 4 comments

Comments

@gopherbot
Copy link

by chris@chrisduffin.org:

The following code generates a "socket is already connected" error in OS X.
Error does not occur in Linux.

package main

import (
    "fmt"
    "net"
)

func main() {
    dest := "192.168.2.253"
    host := "192.168.2.56"
    sendpkt := []byte{'r', 'o', 'a', 'd'}
    remote, err := net.ResolveIPAddr("ip4", dest)
    local, err := net.ResolveIPAddr("ip4", host)
    if err != nil {
        fmt.Printf("Could not parse IP address", 1)
    }
    ipconn, err := net.DialIP("ip4:icmp", local, remote)
    if err != nil {
        fmt.Printf("Could not create connection to %s", remote)
    }

    n, err := ipconn.WriteToIP(sendpkt, remote)
    if err != nil {
        fmt.Printf(`net.WriteToIP(..., %v) = %v, %v`, remote, n, err)
    }

}


Prints:

sudo ./ping                                                                             
                                                                                        
                                                                                 ⏎
net.WriteToIP(..., 192.168.2.253) = 0, write ip4 192.168.2.253: socket is already
connected%
@ianlancetaylor
Copy link
Contributor

Comment 1:

Labels changed: added repo-main, release-go1.4.

@mikioh
Copy link
Contributor

mikioh commented Apr 28, 2014

Comment 2:

Please don't use WriteTo/WriteToIP methods to connected-mode raw sockets. Almost all the
platforms prohibit this behavior,
> Error does not occur in Linux.
except Linux.

Labels changed: removed release-go1.4.

@gopherbot
Copy link
Author

Comment 4:

CL https://golang.org/cl/97810043 mentions this issue.

@mikioh
Copy link
Contributor

mikioh commented Apr 29, 2014

Comment 5:

This issue was closed by revision 7e41abb.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

3 participants