What's the correct, portable way to convert between a `syscall.Sockaddr` and `C.struct_sockaddr`?
(Why? am implementing bindings for a c lib.)
Looking through the net and syscall packages, I see
`syscall.RawSockaddr`
syscall.SockaddrX have raw (unexported) ptrs to it.
The raw ptrs seem to get populated when needed.
In some platforms, they're even the same:
type RawSockaddr C.struct_sockaddr
Having a RawSockaddr, one can cast it using `unsafe.Pointer` (seems awful to me).
But can't even find an exported function to turn a Sockaddr -> RawSockaddr portably.
## Unix implementations seem to use (unexported) `Sockaddr.sockaddr()`:
type Sockaddr interface {
sockaddr() (ptr uintptr, len _Socklen, err error) // lowercase; only we can define Sockaddrs
}
func Connect(fd int, sa Sockaddr) (err error) {
ptr, n, err := sa.sockaddr()
if err != nil {
return err
}
return connect(fd, ptr, n)
}
Even windows seems to work the same way:
type Sockaddr interface {
sockaddr() (ptr uintptr, len int32, err error) // lowercase; only we can define Sockaddrs
}
It seems this is a better way to go. But again, this is not exported.
What's the _right_ way to do this?