helper_windows.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2013 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package ipv6
  5. import (
  6. "net"
  7. "reflect"
  8. "syscall"
  9. )
  10. func (c *genericOpt) sysfd() (syscall.Handle, error) {
  11. switch p := c.Conn.(type) {
  12. case *net.TCPConn, *net.UDPConn, *net.IPConn:
  13. return sysfd(p)
  14. }
  15. return syscall.InvalidHandle, errInvalidConnType
  16. }
  17. func (c *dgramOpt) sysfd() (syscall.Handle, error) {
  18. switch p := c.PacketConn.(type) {
  19. case *net.UDPConn, *net.IPConn:
  20. return sysfd(p.(net.Conn))
  21. }
  22. return syscall.InvalidHandle, errInvalidConnType
  23. }
  24. func (c *payloadHandler) sysfd() (syscall.Handle, error) {
  25. return sysfd(c.PacketConn.(net.Conn))
  26. }
  27. func sysfd(c net.Conn) (syscall.Handle, error) {
  28. cv := reflect.ValueOf(c)
  29. switch ce := cv.Elem(); ce.Kind() {
  30. case reflect.Struct:
  31. netfd := ce.FieldByName("conn").FieldByName("fd")
  32. switch fe := netfd.Elem(); fe.Kind() {
  33. case reflect.Struct:
  34. fd := fe.FieldByName("sysfd")
  35. return syscall.Handle(fd.Uint()), nil
  36. }
  37. }
  38. return syscall.InvalidHandle, errInvalidConnType
  39. }