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