github.com/binkynet/BinkyNet@v1.12.1-0.20240421190447-da4e34c20be0/proto_vendor/golang.org/x/net/ipv6/helper.go (about)

     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  	"runtime"
    11  )
    12  
    13  var (
    14  	errInvalidConn     = errors.New("invalid connection")
    15  	errMissingAddress  = errors.New("missing address")
    16  	errHeaderTooShort  = errors.New("header too short")
    17  	errInvalidConnType = errors.New("invalid conn type")
    18  	errNoSuchInterface = errors.New("no such interface")
    19  	errNotImplemented  = errors.New("not implemented on " + runtime.GOOS + "/" + runtime.GOARCH)
    20  )
    21  
    22  func boolint(b bool) int {
    23  	if b {
    24  		return 1
    25  	}
    26  	return 0
    27  }
    28  
    29  func netAddrToIP16(a net.Addr) net.IP {
    30  	switch v := a.(type) {
    31  	case *net.UDPAddr:
    32  		if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
    33  			return ip
    34  		}
    35  	case *net.IPAddr:
    36  		if ip := v.IP.To16(); ip != nil && ip.To4() == nil {
    37  			return ip
    38  		}
    39  	}
    40  	return nil
    41  }
    42  
    43  func opAddr(a net.Addr) net.Addr {
    44  	switch a.(type) {
    45  	case *net.TCPAddr:
    46  		if a == nil {
    47  			return nil
    48  		}
    49  	case *net.UDPAddr:
    50  		if a == nil {
    51  			return nil
    52  		}
    53  	case *net.IPAddr:
    54  		if a == nil {
    55  			return nil
    56  		}
    57  	}
    58  	return a
    59  }