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: document that DialIP can only be used with WriteMsgIP of Connection-less protocols #23230

Open
ilyaigpetrov opened this Issue Dec 23, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@ilyaigpetrov

ilyaigpetrov commented Dec 23, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ilyaigpetrov/go"
GORACE=""
GOROOT="/usr/lib/go-1.9"
GOTOOLDIR="/usr/lib/go-1.9/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build418566627=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

WriteMsgIP can't be used after DialIP to TCP

package main

import (
  "net"
  "fmt"
)

func main() {

  loIP := net.IPv4(127,0,0,1)

  // Accept TCP connections on localohst
  listener, err := net.ListenTCP("tcp", &net.TCPAddr{ IP: loIP , Port: 0})
  if err != nil {
    panic(err)
  }
  go func(){
    for {
      _, err := listener.Accept()
      if err != nil {
        fmt.Println(err)
      }
    }
  }()

  // Dial localhost
  ipconn, err := net.DialIP("ip:tcp", nil, &net.IPAddr{IP: loIP})
  if err != nil {
    panic(err)
  }
  _, _, err = ipconn.WriteMsgIP([]byte{11,22,33}, []byte{}, &net.IPAddr{ IP: loIP })
  if err != nil {
    panic(err)
  }
  fmt.Println("Heppy exit!")

}

What did you expect to see?

It doesn't work. Error appears: write ip 127.0.0.1->127.0.0.1: use of WriteTo with pre-connected connection.
It seems DialIP can't be used with WriteMsgIP and I want this to be documented.

What did you see instead?

No documentation.

@ilyaigpetrov ilyaigpetrov changed the title from Document That net.DialIP Can Only Be Used With Connection-less Protocols to Document That net.DialIP Can Only Be Used With net.WriteMsgIP of Connection-less Protocols Dec 23, 2017

@odeke-em odeke-em changed the title from Document That net.DialIP Can Only Be Used With net.WriteMsgIP of Connection-less Protocols to net: document that DialIP can only be used with WriteMsgIP of Connection-less protocols Dec 23, 2017

@odeke-em

This comment has been minimized.

Member

odeke-em commented Dec 23, 2017

/cc @mikioh

@gopherbot

This comment has been minimized.

gopherbot commented Jan 7, 2018

Change https://golang.org/cl/86576 mentions this issue: net: update documentation on IPConn and UPDConn

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment