Hi Y'all,
Wondering if someone can give me some color (including if this Q would be more appropriately aimed at a different email-list). What I'm seeing is that net.Conn.RemoteAddr().String() returns strange results on the Mac platform, when the connection is made to the loopback device. I run the following program on two platforms (linux and mac)
{code}
package main
import (
"fmt"
"net"
"net/http"
"time"
)
type MyHandler struct {
}
func (h *MyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
func main() {
handler := &MyHandler{}
listener, err := net.Listen("tcp", ":80")
if err != nil {
panic(err)
}
go http.Serve(listener, handler)
time.Sleep(time.Second)
conn, err := net.Dial("tcp", "localhost:80")
if err != nil {
panic(err)
}
reportedIp := conn.RemoteAddr().String()
fmt.Printf("net.Dial maps %v --> %v\n", "localhost:80", reportedIp)
return
}
{code}
When I run the code on linux I see
{code}
## On Linux
linux_prompt > uname -a
Linux pc6a.local 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
linux_prompt > sudo -E go run hack/main.go
{code}
which I would expect: localhost:80 being maped to
127.0.0.1:80
But when I run this program on mac
{code}
## On Mac
mac_prompt > uname -a
Darwin oakm07147fbf7.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
mac_prompt > sudo -E go run hack/main.go
{code}
It is very surprising to me that Darwin is maping localhost:80 -->
127.0.0.1:5001 !
Why is port 80 mapped to port 5001? This seems wrong to me, but hoping someone on this list can help me challenge this assumption if you see it differently. Thanks for any help.
-pete
Pete Christopher
iParadigms/Turnitin