OSDN Git Service

new repo
[bytom/vapor.git] / vendor / golang.org / x / net / ipv6 / helper.go
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
5 package ipv6
6
7 import (
8         "errors"
9         "net"
10 )
11
12 var (
13         errMissingAddress  = errors.New("missing address")
14         errHeaderTooShort  = errors.New("header too short")
15         errInvalidConnType = errors.New("invalid conn type")
16         errOpNoSupport     = errors.New("operation not supported")
17         errNoSuchInterface = errors.New("no such interface")
18 )
19
20 func boolint(b bool) int {
21         if b {
22                 return 1
23         }
24         return 0
25 }
26
27 func netAddrToIP16(a net.Addr) net.IP {
28         switch v := a.(type) {
29         case *net.UDPAddr:
30                 if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
31                         return ip
32                 }
33         case *net.IPAddr:
34                 if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
35                         return ip
36                 }
37         }
38         return nil
39 }
40
41 func opAddr(a net.Addr) net.Addr {
42         switch a.(type) {
43         case *net.TCPAddr:
44                 if a == nil {
45                         return nil
46                 }
47         case *net.UDPAddr:
48                 if a == nil {
49                         return nil
50                 }
51         case *net.IPAddr:
52                 if a == nil {
53                         return nil
54                 }
55         }
56         return a
57 }