Skip to content

net: document that DialIP can only be used with WriteMsgIP of Connection-less protocols #23230

@ilyaigpetrov

Description

@ilyaigpetrov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions