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

x/net/ipv4: wrong endianness in IP header on darwin-amd64 #32118

Open
hrqiang opened this issue May 17, 2019 · 5 comments
Open

x/net/ipv4: wrong endianness in IP header on darwin-amd64 #32118

hrqiang opened this issue May 17, 2019 · 5 comments
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Milestone

Comments

@hrqiang
Copy link

hrqiang commented May 17, 2019

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

$ go version
go version go1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rhuang/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/rhuang/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
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/xy/qpsgj2816g97b0ctzkq0ps_r0000gs/T/go-build097375093=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

marshall IPv4 IP header with x/net/ipv4/header, but I got little-endian instead of big-endian.

What did you expect to see?

Got big-endian IP header len.

What did you see instead?

little-endian

Looking at By looking at the code https://github.com/golang/net/blob/master/ipv4/header.go#L71., for darwin, 32bit/64bit os should have a different conversion.
Darwin amd64 is little-endian, it should convert.

@bradfitz bradfitz changed the title Wrong endianness for osx 64bit(little endian) on IP header. x/net/ipv4: wrong endianness in IP header on darwin-amd64 May 17, 2019
@gopherbot gopherbot added this to the Unreleased milestone May 17, 2019
@bradfitz
Copy link
Contributor

/cc @mikioh

@ianlancetaylor
Copy link
Contributor

Can you show us a self-contained program we can use to recreate the problem?

@hrqiang
Copy link
Author

hrqiang commented May 18, 2019

@ianlancetaylor this is the program to recreate the issue. https://github.com/hrqiang/iphdr/blob/master/iphdr.go

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 20, 2019
@networkimprov
Copy link

@gopherbot add "help wanted"
@gopherbot add OS-Darwin

cc @odeke-em

@WingLim
Copy link

WingLim commented Jul 5, 2021

You can see this answer: https://stackoverflow.com/a/15881825/13019406
This is the 'feature' of BSD and OSX, golang should and just read it from sock.
You should to use ipv4.ParseHeader to parse raw bytes, rather than golang modify it to big-endian IP header len.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Darwin
Projects
None yet
Development

No branches or pull requests

7 participants