Debian Codegraph @

libgo/go/syscall/socket_hurd.go

raw
1 // socket_hurd.go -- Socket handling specific to GNU/Hurd based systems.
2 // This file is derived from socket_bsd.go without SockaddrDatalink since
3 // AF_LINK is not yet supported on GNU/Hurd.
4
5 // Copyright 2010 The Go Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style
7 // license that can be found in the LICENSE file.
8
9 //go:build hurd
10 // +build hurd
11
12 package syscall
13
14 import "unsafe"
15
16 const SizeofSockaddrInet4 = 16
17 const SizeofSockaddrInet6 = 28
18 const SizeofSockaddrUnix = 110
19
20 type RawSockaddrInet4 struct {
21 Len uint8
22 Family uint8
23 Port uint16
24 Addr [4]byte /* in_addr */
25 Zero [8]uint8
26 }
27
28 func (sa *RawSockaddrInet4) setLen() Socklen_t {
29 sa.Len = SizeofSockaddrInet4
30 return SizeofSockaddrInet4
31 }
32
33 type RawSockaddrInet6 struct {
34 Len uint8
35 Family uint8
36 Port uint16
37 Flowinfo uint32
38 Addr [16]byte /* in6_addr */
39 Scope_id uint32
40 }
41
42 func (sa *RawSockaddrInet6) setLen() Socklen_t {
43 sa.Len = SizeofSockaddrInet6
44 return SizeofSockaddrInet6
45 }
46
47 type RawSockaddrUnix struct {
48 Len uint8
49 Family uint8
50 Path [108]int8
51 }
52
53 func (sa *RawSockaddrUnix) setLen(n int) {
54 sa.Len = uint8(3 + n) // 2 for Family, Len; 1 for NUL.
55 }
56
57 func (sa *RawSockaddrUnix) getLen() (int, error) {
58 if sa.Len < 2 || sa.Len > SizeofSockaddrUnix {
59 return 0, EINVAL
60 }
61
62 // Some BSDs include the trailing NUL in the length, whereas
63 // others do not. Work around this by subtracting the leading
64 // family and len. The path is then scanned to see if a NUL
65 // terminator still exists within the length.
66 n := int(sa.Len) - 2 // subtract leading Family, Len
67 for i := 0; i < n; i++ {
68 if sa.Path[i] == 0 {
69 // found early NUL; assume Len included the NUL
70 // or was overestimating.
71 n = i
72 break
73 }
74 }
75 return n, nil
76 }
77
78 func (sa *RawSockaddrUnix) adjustAbstract(sl Socklen_t) Socklen_t {
79 return sl
80 }
81
82 type RawSockaddr struct {
83 Len uint8
84 Family uint8
85 Data [14]int8
86 }
87
88 // BindToDevice binds the socket associated with fd to device.
89 func BindToDevice(fd int, device string) (err error) {
90 return ENOSYS
91 }
92
93 func anyToSockaddrOS(rsa *RawSockaddrAny) (Sockaddr, error) {
94 return nil, EAFNOSUPPORT
95 }
96
97 func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) {
98 var value IPv6MTUInfo
99 vallen := Socklen_t(SizeofIPv6MTUInfo)
100 err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
101 return &value, err
102 }