Black Lives Matter. Support the Equal Justice Initiative.

Source file src/net/cgo_sockold.go

Documentation: net

     1  // Copyright 2015 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 cgo && !netgo && (aix || darwin || dragonfly || freebsd || netbsd || openbsd)
     6  // +build cgo
     7  // +build !netgo
     8  // +build aix darwin dragonfly freebsd netbsd openbsd
     9  
    10  package net
    11  
    12  /*
    13  #include <sys/types.h>
    14  #include <sys/socket.h>
    15  
    16  #include <netinet/in.h>
    17  */
    18  import "C"
    19  
    20  import (
    21  	"syscall"
    22  	"unsafe"
    23  )
    24  
    25  func cgoSockaddrInet4(ip IP) *C.struct_sockaddr {
    26  	sa := syscall.RawSockaddrInet4{Len: syscall.SizeofSockaddrInet4, Family: syscall.AF_INET}
    27  	copy(sa.Addr[:], ip)
    28  	return (*C.struct_sockaddr)(unsafe.Pointer(&sa))
    29  }
    30  
    31  func cgoSockaddrInet6(ip IP, zone int) *C.struct_sockaddr {
    32  	sa := syscall.RawSockaddrInet6{Len: syscall.SizeofSockaddrInet6, Family: syscall.AF_INET6, Scope_id: uint32(zone)}
    33  	copy(sa.Addr[:], ip)
    34  	return (*C.struct_sockaddr)(unsafe.Pointer(&sa))
    35  }
    36  

View as plain text