Mikio Hara | 99f5f79 | 2015-01-28 20:08:41 +0900 | [diff] [blame] | 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 | |
Russ Cox | d4b2638 | 2021-02-19 18:35:10 -0500 | [diff] [blame] | 5 | //go:build cgo && !netgo && (aix || darwin || dragonfly || freebsd || netbsd || openbsd) |
Mikio Hara | 99f5f79 | 2015-01-28 20:08:41 +0900 | [diff] [blame] | 6 | |
| 7 | package net |
| 8 | |
| 9 | /* |
| 10 | #include <sys/types.h> |
| 11 | #include <sys/socket.h> |
| 12 | |
| 13 | #include <netinet/in.h> |
| 14 | */ |
| 15 | import "C" |
| 16 | |
| 17 | import ( |
| 18 | "syscall" |
| 19 | "unsafe" |
| 20 | ) |
| 21 | |
| 22 | func cgoSockaddrInet4(ip IP) *C.struct_sockaddr { |
| 23 | sa := syscall.RawSockaddrInet4{Len: syscall.SizeofSockaddrInet4, Family: syscall.AF_INET} |
| 24 | copy(sa.Addr[:], ip) |
| 25 | return (*C.struct_sockaddr)(unsafe.Pointer(&sa)) |
| 26 | } |
| 27 | |
Mikio Hara | 8854bdb | 2015-11-27 12:06:11 +0900 | [diff] [blame] | 28 | func cgoSockaddrInet6(ip IP, zone int) *C.struct_sockaddr { |
| 29 | sa := syscall.RawSockaddrInet6{Len: syscall.SizeofSockaddrInet6, Family: syscall.AF_INET6, Scope_id: uint32(zone)} |
Mikio Hara | 99f5f79 | 2015-01-28 20:08:41 +0900 | [diff] [blame] | 30 | copy(sa.Addr[:], ip) |
| 31 | return (*C.struct_sockaddr)(unsafe.Pointer(&sa)) |
| 32 | } |