rawaddr.go 723 B

1234567891011121314151617181920
  1. package socket
  2. import (
  3. "unsafe"
  4. )
  5. // RawSockaddr allows structs to be used with [Bind] and [ConnectEx]. The
  6. // struct must meet the Win32 sockaddr requirements specified here:
  7. // https://docs.microsoft.com/en-us/windows/win32/winsock/sockaddr-2
  8. //
  9. // Specifically, the struct size must be least larger than an int16 (unsigned short)
  10. // for the address family.
  11. type RawSockaddr interface {
  12. // Sockaddr returns a pointer to the RawSockaddr and its struct size, allowing
  13. // for the RawSockaddr's data to be overwritten by syscalls (if necessary).
  14. //
  15. // It is the callers responsibility to validate that the values are valid; invalid
  16. // pointers or size can cause a panic.
  17. Sockaddr() (unsafe.Pointer, int32, error)
  18. }