github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/net/ipv4/helper.go (about) 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 23 func boolint(b bool) int { 24 if b { 25 return 1 26 } 27 return 0 28 } 29 30 func netAddrToIP4(a net.Addr) net.IP { 31 switch v := a.(type) { 32 case *net.UDPAddr: 33 if ip := v.IP.To4(); ip != nil { 34 return ip 35 } 36 case *net.IPAddr: 37 if ip := v.IP.To4(); ip != nil { 38 return ip 39 } 40 } 41 return nil 42 }