LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin freebsd linux netbsd openbsd | 5 // +build darwin freebsd linux netbsd openbsd |
6 | 6 |
7 // Socket control messages | 7 // Socket control messages |
8 | 8 |
9 package syscall | 9 package syscall |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 return cmsgAlignOf(SizeofCmsghdr) + datalen | 30 return cmsgAlignOf(SizeofCmsghdr) + datalen |
31 } | 31 } |
32 | 32 |
33 // CmsgSpace returns the number of bytes an ancillary element with | 33 // CmsgSpace returns the number of bytes an ancillary element with |
34 // payload of the passed data length occupies. | 34 // payload of the passed data length occupies. |
35 func CmsgSpace(datalen int) int { | 35 func CmsgSpace(datalen int) int { |
36 return cmsgAlignOf(SizeofCmsghdr) + cmsgAlignOf(datalen) | 36 return cmsgAlignOf(SizeofCmsghdr) + cmsgAlignOf(datalen) |
37 } | 37 } |
38 | 38 |
39 func cmsgData(h *Cmsghdr) unsafe.Pointer { | 39 func cmsgData(h *Cmsghdr) unsafe.Pointer { |
40 » return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + SizeofCmsghdr) | 40 » return unsafe.Pointer(uintptr(unsafe.Pointer(h)) + uintptr(cmsgAlignOf(S
izeofCmsghdr))) |
41 } | 41 } |
42 | 42 |
43 // SocketControlMessage represents a socket control message. | 43 // SocketControlMessage represents a socket control message. |
44 type SocketControlMessage struct { | 44 type SocketControlMessage struct { |
45 Header Cmsghdr | 45 Header Cmsghdr |
46 Data []byte | 46 Data []byte |
47 } | 47 } |
48 | 48 |
49 // ParseSocketControlMessage parses b as an array of socket control | 49 // ParseSocketControlMessage parses b as an array of socket control |
50 // messages. | 50 // messages. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if m.Header.Type != SCM_RIGHTS { | 96 if m.Header.Type != SCM_RIGHTS { |
97 return nil, EINVAL | 97 return nil, EINVAL |
98 } | 98 } |
99 fds := make([]int, len(m.Data)>>2) | 99 fds := make([]int, len(m.Data)>>2) |
100 for i, j := 0, 0; i < len(m.Data); i += 4 { | 100 for i, j := 0, 0; i < len(m.Data); i += 4 { |
101 fds[j] = int(*(*int32)(unsafe.Pointer(&m.Data[i]))) | 101 fds[j] = int(*(*int32)(unsafe.Pointer(&m.Data[i]))) |
102 j++ | 102 j++ |
103 } | 103 } |
104 return fds, nil | 104 return fds, nil |
105 } | 105 } |
LEFT | RIGHT |