query SO_ORIGINAL_DST failed. origin protocol not available

Viewed 28

i have main.go as below, i's ok to run on my server(4.4.0-209-generic #241-Ubuntu SMP Tue Apr 13 01:06:06 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux) and print the ip and port,
but panic for "protocol not available" on my laptop (ubuntu 5.15.0-46-generic #49-Ubuntu SMP Thu Aug 4 18:03:25 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux), does anybody know what's the reason?

package main

import (
    "fmt"
    "net"
    "syscall"
)

func main() {
   fmt.Println("aaaaaa")


   conn, err := net.Dial("tcp", "127.0.0.1:5432")
   if err != nil {
        panic(err)
   }

   f, err := conn.(*net.TCPConn).File()
   if err != nil {
        panic(err)
   }
   mReq, err := syscall.GetsockoptIPv6Mreq(int(f.Fd()), syscall.IPPROTO_IP, 80)
        _ = f.Close()
        if err != nil {
                panic(fmt.Sprintf("get addr err: %v", err))
        }

        ip := net.IPv4(mReq.Multiaddr[4], mReq.Multiaddr[5], mReq.Multiaddr[6], mReq.Multiaddr[7])
        port := uint16(mReq.Multiaddr[2])<<8 + uint16(mReq.Multiaddr[3])

   fmt.Println(ip, port)
}
0 Answers
Related