Fix "PR c++/92804 ICE trying to use concept as a nested-name-specifier"
[official-gcc.git] / libgo / go / syscall / socket_bsd.go
blobf62457f2bdb6caddfcab072ed5daa43924acee73
1 // socket_bsd.go -- Socket handling specific to *BSD based systems.
3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // +build darwin dragonfly freebsd hurd openbsd netbsd
9 package syscall
11 import "unsafe"
13 const SizeofSockaddrInet4 = 16
14 const SizeofSockaddrInet6 = 28
15 const SizeofSockaddrUnix = 110
17 type RawSockaddrInet4 struct {
18 Len uint8
19 Family uint8
20 Port uint16
21 Addr [4]byte /* in_addr */
22 Zero [8]uint8
25 func (sa *RawSockaddrInet4) setLen() Socklen_t {
26 sa.Len = SizeofSockaddrInet4
27 return SizeofSockaddrInet4
30 type RawSockaddrInet6 struct {
31 Len uint8
32 Family uint8
33 Port uint16
34 Flowinfo uint32
35 Addr [16]byte /* in6_addr */
36 Scope_id uint32
39 func (sa *RawSockaddrInet6) setLen() Socklen_t {
40 sa.Len = SizeofSockaddrInet6
41 return SizeofSockaddrInet6
44 type RawSockaddrUnix struct {
45 Len uint8
46 Family uint8
47 Path [108]int8
50 func (sa *RawSockaddrUnix) setLen(n int) {
51 sa.Len = uint8(3 + n) // 2 for Family, Len; 1 for NUL.
54 func (sa *RawSockaddrUnix) getLen() (int, error) {
55 if sa.Len < 3 || sa.Len > SizeofSockaddrUnix {
56 return 0, EINVAL
58 n := int(sa.Len) - 3 // subtract leading Family, Len, terminating NUL.
59 for i := 0; i < n; i++ {
60 if sa.Path[i] == 0 {
61 // found early NUL; assume Len is overestimating.
62 n = i
63 break
66 return n, nil
69 func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
70 return sl
73 type RawSockaddr struct {
74 Len uint8
75 Family uint8
76 Data [14]int8
79 // BindToDevice binds the socket associated with fd to device.
80 func BindToDevice(fd int, device string) (err error) {
81 return ENOSYS
84 func anyToSockaddrOS(rsa *RawSockaddrAny) (Sockaddr, error) {
85 return nil, EAFNOSUPPORT
88 func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) {
89 var value IPv6MTUInfo
90 vallen := Socklen_t(SizeofIPv6MTUInfo)
91 err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
92 return &value, err