~sinzui/ubuntu/vivid/juju-core/vivid-1.24.6

« back to all changes in this revision

Viewing changes to src/code.google.com/p/go.net/ipv4/helper_unix.go

  • Committer: Curtis Hovey
  • Date: 2015-09-30 14:14:54 UTC
  • mfrom: (1.1.34)
  • Revision ID: curtis@hovey.name-20150930141454-o3ldf23dzyjio6c0
Backport of 1.24.6 from wily. (LP: #1500916)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2012 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
 
 
5
 
// +build darwin freebsd linux netbsd openbsd
6
 
 
7
 
package ipv4
8
 
 
9
 
import (
10
 
        "net"
11
 
        "reflect"
12
 
)
13
 
 
14
 
func (c *genericOpt) sysfd() (int, error) {
15
 
        switch p := c.Conn.(type) {
16
 
        case *net.TCPConn, *net.UDPConn, *net.IPConn:
17
 
                return sysfd(p)
18
 
        }
19
 
        return 0, errInvalidConnType
20
 
}
21
 
 
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))
26
 
        }
27
 
        return 0, errInvalidConnType
28
 
}
29
 
 
30
 
func (c *payloadHandler) sysfd() (int, error) {
31
 
        return sysfd(c.PacketConn.(net.Conn))
32
 
}
33
 
 
34
 
func (c *packetHandler) sysfd() (int, error) {
35
 
        return sysfd(c.c)
36
 
}
37
 
 
38
 
func sysfd(c net.Conn) (int, error) {
39
 
        cv := reflect.ValueOf(c)
40
 
        switch ce := cv.Elem(); ce.Kind() {
41
 
        case reflect.Struct:
42
 
                netfd := ce.FieldByName("conn").FieldByName("fd")
43
 
                switch fe := netfd.Elem(); fe.Kind() {
44
 
                case reflect.Struct:
45
 
                        fd := fe.FieldByName("sysfd")
46
 
                        return int(fd.Int()), nil
47
 
                }
48
 
        }
49
 
        return 0, errInvalidConnType
50
 
}