OSDN Git Service

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