diff options
Diffstat (limited to 'src/pkg/syscall/syscall_bsd.go')
-rw-r--r-- | src/pkg/syscall/syscall_bsd.go | 162 |
1 files changed, 17 insertions, 145 deletions
diff --git a/src/pkg/syscall/syscall_bsd.go b/src/pkg/syscall/syscall_bsd.go index 560409a26..76b1f41b4 100644 --- a/src/pkg/syscall/syscall_bsd.go +++ b/src/pkg/syscall/syscall_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin freebsd netbsd openbsd +// +build darwin dragonfly freebsd netbsd openbsd // BSD system call wrappers shared by *BSD based systems // including OS X (Darwin) and FreeBSD. Like the other @@ -18,17 +18,6 @@ import ( ) /* - * Pseudo-system calls - */ - -// The const provides a compile-time constant so clients -// can adjust to whether there is a working Getwd and avoid -// even linking this function into the binary. See ../os/getwd.go. -const ImplementsGetwd = false - -func Getwd() (string, error) { return "", ENOTSUP } - -/* * Wrapped */ @@ -151,20 +140,6 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) //sys Shutdown(s int, how int) (err error) -// For testing: clients can set this flag to force -// creation of IPv6 sockets to return EAFNOSUPPORT. -var SocketDisableIPv6 bool - -type Sockaddr interface { - sockaddr() (ptr uintptr, len _Socklen, err error) // lowercase; only we can define Sockaddrs -} - -type SockaddrInet4 struct { - Port int - Addr [4]byte - raw RawSockaddrInet4 -} - func (sa *SockaddrInet4) sockaddr() (uintptr, _Socklen, error) { if sa.Port < 0 || sa.Port > 0xFFFF { return 0, 0, EINVAL @@ -180,13 +155,6 @@ func (sa *SockaddrInet4) sockaddr() (uintptr, _Socklen, error) { return uintptr(unsafe.Pointer(&sa.raw)), _Socklen(sa.raw.Len), nil } -type SockaddrInet6 struct { - Port int - ZoneId uint32 - Addr [16]byte - raw RawSockaddrInet6 -} - func (sa *SockaddrInet6) sockaddr() (uintptr, _Socklen, error) { if sa.Port < 0 || sa.Port > 0xFFFF { return 0, 0, EINVAL @@ -203,11 +171,6 @@ func (sa *SockaddrInet6) sockaddr() (uintptr, _Socklen, error) { return uintptr(unsafe.Pointer(&sa.raw)), _Socklen(sa.raw.Len), nil } -type SockaddrUnix struct { - Name string - raw RawSockaddrUnix -} - func (sa *SockaddrUnix) sockaddr() (uintptr, _Socklen, error) { name := sa.Name n := len(name) @@ -328,58 +291,17 @@ func Getsockname(fd int) (sa Sockaddr, err error) { return } // TODO(jsing): Remove after OpenBSD 5.4 is released (see issue 3349). - if runtime.GOOS == "openbsd" && rsa.Addr.Family == AF_UNSPEC && rsa.Addr.Len == 0 { + // TODO(jsing): Apparently dragonfly has the same "bug", which should + // be reported upstream. + if (runtime.GOOS == "dragonfly" || runtime.GOOS == "openbsd") && rsa.Addr.Family == AF_UNSPEC && rsa.Addr.Len == 0 { rsa.Addr.Family = AF_UNIX rsa.Addr.Len = SizeofSockaddrUnix } return anyToSockaddr(&rsa) } -func Getpeername(fd int) (sa Sockaddr, err error) { - var rsa RawSockaddrAny - var len _Socklen = SizeofSockaddrAny - if err = getpeername(fd, &rsa, &len); err != nil { - return - } - return anyToSockaddr(&rsa) -} - -func Bind(fd int, sa Sockaddr) (err error) { - ptr, n, err := sa.sockaddr() - if err != nil { - return err - } - return bind(fd, ptr, n) -} - -func Connect(fd int, sa Sockaddr) (err error) { - ptr, n, err := sa.sockaddr() - if err != nil { - return err - } - return connect(fd, ptr, n) -} - -func Socket(domain, typ, proto int) (fd int, err error) { - if domain == AF_INET6 && SocketDisableIPv6 { - return -1, EAFNOSUPPORT - } - fd, err = socket(domain, typ, proto) - return -} - //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) -func Socketpair(domain, typ, proto int) (fd [2]int, err error) { - var fdx [2]int32 - err = socketpair(domain, typ, proto, &fdx) - if err == nil { - fd[0] = int(fdx[0]) - fd[1] = int(fdx[1]) - } - return -} - func GetsockoptByte(fd, level, opt int) (value byte, err error) { var n byte vallen := _Socklen(1) @@ -387,13 +309,6 @@ func GetsockoptByte(fd, level, opt int) (value byte, err error) { return n, err } -func GetsockoptInt(fd, level, opt int) (value int, err error) { - var n int32 - vallen := _Socklen(4) - err = getsockopt(fd, level, opt, uintptr(unsafe.Pointer(&n)), &vallen) - return int(n), err -} - func GetsockoptInet4Addr(fd, level, opt int) (value [4]byte, err error) { vallen := _Socklen(4) err = getsockopt(fd, level, opt, uintptr(unsafe.Pointer(&value[0])), &vallen) @@ -414,64 +329,22 @@ func GetsockoptIPv6Mreq(fd, level, opt int) (*IPv6Mreq, error) { return &value, err } -func SetsockoptByte(fd, level, opt int, value byte) (err error) { - var n = byte(value) - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(&n)), 1) -} - -func SetsockoptInt(fd, level, opt int, value int) (err error) { - var n = int32(value) - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(&n)), 4) -} - -func SetsockoptInet4Addr(fd, level, opt int, value [4]byte) (err error) { - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(&value[0])), 4) -} - -func SetsockoptTimeval(fd, level, opt int, tv *Timeval) (err error) { - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(tv)), unsafe.Sizeof(*tv)) -} - -func SetsockoptLinger(fd, level, opt int, l *Linger) (err error) { - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(l)), unsafe.Sizeof(*l)) -} - -func SetsockoptIPMreq(fd, level, opt int, mreq *IPMreq) (err error) { - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq)) -} - -func SetsockoptIPv6Mreq(fd, level, opt int, mreq *IPv6Mreq) (err error) { - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(mreq)), unsafe.Sizeof(*mreq)) -} - -func SetsockoptString(fd, level, opt int, s string) (err error) { - return setsockopt(fd, level, opt, uintptr(unsafe.Pointer(&[]byte(s)[0])), uintptr(len(s))) -} - -//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) - -func Recvfrom(fd int, p []byte, flags int) (n int, from Sockaddr, err error) { - var rsa RawSockaddrAny - var len _Socklen = SizeofSockaddrAny - if n, err = recvfrom(fd, p, flags, &rsa, &len); err != nil { - return - } - if rsa.Addr.Family != AF_UNSPEC { - from, err = anyToSockaddr(&rsa) - } - return +func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) { + var value IPv6MTUInfo + vallen := _Socklen(SizeofIPv6MTUInfo) + err := getsockopt(fd, level, opt, uintptr(unsafe.Pointer(&value)), &vallen) + return &value, err } -//sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (err error) - -func Sendto(fd int, p []byte, flags int, to Sockaddr) (err error) { - ptr, n, err := to.sockaddr() - if err != nil { - return err - } - return sendto(fd, p, flags, ptr, n) +func GetsockoptICMPv6Filter(fd, level, opt int) (*ICMPv6Filter, error) { + var value ICMPv6Filter + vallen := _Socklen(SizeofICMPv6Filter) + err := getsockopt(fd, level, opt, uintptr(unsafe.Pointer(&value)), &vallen) + return &value, err } +//sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) +//sys sendto(s int, buf []byte, flags int, to uintptr, addrlen _Socklen) (err error) //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) { @@ -514,10 +387,9 @@ func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) { var ptr uintptr var salen _Socklen if to != nil { - var err error ptr, salen, err = to.sockaddr() if err != nil { - return err + return } } var msg Msghdr |