Skip to content

ipv6 header was stripped from the ip packets in packetConn read apis #40143

@yusong0926

Description

@yusong0926

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

$ go version
go version go1.14.1 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/songyu/Library/Caches/go-build"
GOENV="/Users/songyu/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/songyu/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/82/ywnjzhzn0bv_9w46jyyxp5kh0000gp/T/go-build674890034=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

tried all apis (ipConn, icmp packetConn), couldn't get ip header from the ip packets especially for ipv6 using read or readFrom api.

func main() {
conn, err := icmp.ListenPacket("ip6:ipv6-icmp", "::")
if err != nil {
log.Fatal(err)
}

for {
    var msg []byte
    length, sourceIP, err := conn.ReadFrom(msg)
   //msg was only the payload of the packets, ipv6 header was stripped from it. I want to get hopLimit from the header
    if err != nil {
        log.Println(err)
        continue
    }

    log.Printf("message = '%s', length = %d, source-ip = %s", string(msg), length, sourceIP)
}
_ = conn.Close()

}

What did you expect to see?

read ipv6 header and read hopLimit or ttl from ip header for icmp packets.

What did you see instead?

ipv6 header was stripped. Read or readfrom only receive ip payload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions