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: use original raddr param for RemoteAddr if getpeername fails? #3838

Closed
rsc opened this issue Jul 17, 2012 · 7 comments
Closed

net: use original raddr param for RemoteAddr if getpeername fails? #3838

rsc opened this issue Jul 17, 2012 · 7 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jul 17, 2012

package main

import (
        "fmt"
        "net"
        "os"
)

func main() {
        localAddr := net.ParseIP(os.Args[1])
        remoteAddr := net.ParseIP(os.Args[2])
        netProto := os.Args[3]

        c, err := net.DialIP(netProto, &net.IPAddr{localAddr}, &net.IPAddr{remoteAddr})
        if err != nil {
                fmt.Printf("DialIP failed: %v\n", err)
                return
        }
        fmt.Printf("LocalAddr: %v, RemoteAddr: %v\n", c.LocalAddr(), c.RemoteAddr())
}

# ./test 172.23.124.29 172.23.124.30 ip:tcp
LocalAddr: 172.23.124.29, RemoteAddr: <nil>
# ./test 172.23.124.29 172.23.124.30 ip:udp
LocalAddr: 172.23.124.29, RemoteAddr: <nil>
# ./test 172.23.124.29 172.23.124.30 ip:112
LocalAddr: 172.23.124.29, RemoteAddr: <nil>

because 

# strace ./test 172.23.124.29 172.23.124.30 ip:udp

socket(PF_INET, SOCK_RAW, IPPROTO_UDP)  = 3
fcntl(3, F_SETFD, FD_CLOEXEC)           = 0
setsockopt(3, SOL_SOCKET, SO_BROADCAST, [1], 4) = 0
bind(3, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr("172.23.124.29")}, 16) = 0
fcntl(3, F_GETFL)                       = 0x2 (flags O_RDWR)
fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
connect(3, {sa_family=AF_INET, sin_port=htons(0),
sin_addr=inet_addr("172.23.124.30")}, 16) = 0
getsockname(3, {sa_family=AF_INET, sin_port=htons(17),
sin_addr=inet_addr("172.23.124.29")}, [16]) = 0
getpeername(3, 0xf8400000e0, [112])     = -1 ENOTCONN (Transport
endpoint is not connected)
======================
@rsc
Copy link
Contributor Author

rsc commented Dec 10, 2012

Comment 1:

Labels changed: added size-m.

@rsc
Copy link
Contributor Author

rsc commented Dec 10, 2012

Comment 2:

Labels changed: added suggested.

@gopherbot
Copy link

Comment 3 by tylerbunnell:

I'd like to give this one a go, but I'm unable to duplicate the bug.
On OSX 10.8.2 it says "operation not permitted" unless I run it with sudo, in which case
it will run, but the RemoteAddr is always the same as what I put in originally.
Is there something I need to do in order to force this bug to appear?

@mikioh
Copy link
Contributor

mikioh commented Mar 1, 2013

Comment 4:

At least this happens on Linux.
Perhaps BSD variants are fine.

@gopherbot
Copy link

Comment 5 by tylerbunnell:

Bollocks. I don't have a linux system on which to test this.
Perhaps I can put together a VM or something.

@rsc
Copy link
Contributor Author

rsc commented Mar 13, 2013

Comment 6:

This issue was closed by revision 06cbe78.

Status changed to Fixed.

@mikioh
Copy link
Contributor

mikioh commented Mar 23, 2013

Comment 7:

This issue was closed by revision bfb32dc.

@rsc rsc added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Mar 23, 2013
@rsc rsc self-assigned this Mar 23, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@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.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

3 participants