github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/net/lif/lif.go (about)

     1  // Copyright 2016 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  //go:build solaris
     6  // +build solaris
     7  
     8  // Package lif provides basic functions for the manipulation of
     9  // logical network interfaces and interface addresses on Solaris.
    10  //
    11  // The package supports Solaris 11 or above.
    12  package lif
    13  
    14  import "syscall"
    15  
    16  type endpoint struct {
    17  	af int
    18  	s  uintptr
    19  }
    20  
    21  func (ep *endpoint) close() error {
    22  	return syscall.Close(int(ep.s))
    23  }
    24  
    25  func newEndpoints(af int) ([]endpoint, error) {
    26  	var lastErr error
    27  	var eps []endpoint
    28  	afs := []int{sysAF_INET, sysAF_INET6}
    29  	if af != sysAF_UNSPEC {
    30  		afs = []int{af}
    31  	}
    32  	for _, af := range afs {
    33  		s, err := syscall.Socket(af, sysSOCK_DGRAM, 0)
    34  		if err != nil {
    35  			lastErr = err
    36  			continue
    37  		}
    38  		eps = append(eps, endpoint{af: af, s: uintptr(s)})
    39  	}
    40  	if len(eps) == 0 {
    41  		return nil, lastErr
    42  	}
    43  	return eps, nil
    44  }