Home > Software design >  SOCKADDR_INET in golang
SOCKADDR_INET in golang

Time:04-23

I have a byte array that is actually filled with SOCKADDR_INET structures by C function in the kernel, after transfer to user mode I need to marshal it in the slice of SOCKADDR_INET equivalent. The syscall package contains sockaddr_in and sockaddr_in6 but as I see golang has a lack of a union to emulate SOCKADDR_INET. I'm new in golang so wondering about the right solution for this case.

CodePudding user response:

The si_family field at the end identifies if the bytes should be interpreted as IPv4 or IPv6 SOCKADDR structure.

The most easy route is likey to make a function to unmarshall the bytes into a go version of the SOCKADDR_IN or SOCKADDR_IN6 struct depending on the value of si_family.

  • Related