blob: 259740132cb111a2a70ace3d5e3c9ab6b96c76af [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001// 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
5package ipv6
6
7import (
8 "errors"
9 "net"
10)
11
12var (
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
20func boolint(b bool) int {
21 if b {
22 return 1
23 }
24 return 0
25}
26
27func 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
41func 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}