libcpp/ChangeLog.pph
[official-gcc.git] / libgo / syscalls / socket_linux.go
blobcdcdf4ff28bed5cb29ddb591ae6c85593705d467
1 // socket_linux.go -- Socket handling specific to Linux.
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 package syscall
9 const SizeofSockaddrInet4 = 16
10 const SizeofSockaddrInet6 = 28
11 const SizeofSockaddrUnix = 110
13 type RawSockaddrInet4 struct {
14 Family uint16;
15 Port uint16;
16 Addr [4]byte /* in_addr */;
17 Zero [8]uint8;
20 func (sa *RawSockaddrInet4) setLen() Socklen_t {
21 return SizeofSockaddrInet4
24 type RawSockaddrInet6 struct {
25 Family uint16;
26 Port uint16;
27 Flowinfo uint32;
28 Addr [16]byte /* in6_addr */;
29 Scope_id uint32;
32 func (sa *RawSockaddrInet6) setLen() Socklen_t {
33 return SizeofSockaddrInet6
36 type RawSockaddrUnix struct {
37 Family uint16;
38 Path [108]int8;
41 func (sa *RawSockaddrUnix) setLen(int) {
44 func (sa *RawSockaddrUnix) getLen() (int, int) {
45 if sa.Path[0] == 0 {
46 // "Abstract" Unix domain socket.
47 // Rewrite leading NUL as @ for textual display.
48 // (This is the standard convention.)
49 // Not friendly to overwrite in place,
50 // but the callers below don't care.
51 sa.Path[0] = '@';
54 // Assume path ends at NUL.
55 // This is not technically the Linux semantics for
56 // abstract Unix domain sockets--they are supposed
57 // to be uninterpreted fixed-size binary blobs--but
58 // everyone uses this convention.
59 n := 0;
60 for n < len(sa.Path) - 3 && sa.Path[n] != 0 {
61 n++;
64 return n, 0
67 type RawSockaddr struct {
68 Family uint16;
69 Data [14]int8;
72 // BindToDevice binds the socket associated with fd to device.
73 func BindToDevice(fd int, device string) (errno int) {
74 return SetsockoptString(fd, SOL_SOCKET, SO_BINDTODEVICE, device)