You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

32 lines
727 B

  1. // Copyright 2016 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. // +build !go1.9
  5. // +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
  6. package netreflect
  7. import (
  8. "net"
  9. "reflect"
  10. "runtime"
  11. )
  12. func socketOf(c net.Conn) (uintptr, error) {
  13. v := reflect.ValueOf(c)
  14. switch e := v.Elem(); e.Kind() {
  15. case reflect.Struct:
  16. fd := e.FieldByName("conn").FieldByName("fd")
  17. switch e := fd.Elem(); e.Kind() {
  18. case reflect.Struct:
  19. sysfd := e.FieldByName("sysfd")
  20. if runtime.GOOS == "windows" {
  21. return uintptr(sysfd.Uint()), nil
  22. }
  23. return uintptr(sysfd.Int()), nil
  24. }
  25. }
  26. return 0, errInvalidType
  27. }