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.
5
// +build darwin freebsd linux netbsd openbsd
14
func (c *genericOpt) sysfd() (int, error) {
15
switch p := c.Conn.(type) {
16
case *net.TCPConn, *net.UDPConn, *net.IPConn:
19
return 0, errInvalidConnType
22
func (c *dgramOpt) sysfd() (int, error) {
23
switch p := c.PacketConn.(type) {
24
case *net.UDPConn, *net.IPConn:
25
return sysfd(p.(net.Conn))
27
return 0, errInvalidConnType
30
func (c *payloadHandler) sysfd() (int, error) {
31
return sysfd(c.PacketConn.(net.Conn))
34
func sysfd(c net.Conn) (int, error) {
35
cv := reflect.ValueOf(c)
36
switch ce := cv.Elem(); ce.Kind() {
38
nfd := ce.FieldByName("conn").FieldByName("fd")
39
switch fe := nfd.Elem(); fe.Kind() {
41
fd := fe.FieldByName("sysfd")
42
return int(fd.Int()), nil
45
return 0, errInvalidConnType