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