Exemplo n.º 1
0
func (k *PosixKernel) Pipe(files co.Buf) uint64 {
	var fds [2]int
	err := syscall.Pipe(fds[:])
	if err == nil {
		st := files.Struc()
		err := st.Pack(int32(fds[0]))
		if err == nil {
			err = st.Pack(int32(fds[1]))
		}
		if err != nil {
			return UINT64_MAX // FIXME
		}
	}
	return Errno(err)
}
Exemplo n.º 2
0
func iovecIter(stream co.Buf, count uint64, bits uint) <-chan Iovec64 {
	ret := make(chan Iovec64)
	go func() {
		st := stream.Struc()
		for i := uint64(0); i < count; i++ {
			if bits == 64 {
				var iovec Iovec64
				st.Unpack(&iovec)
				ret <- iovec
			} else {
				var iv32 Iovec32
				st.Unpack(&iv32)
				ret <- Iovec64{uint64(iv32.Base), uint64(iv32.Len)}
			}
		}
		close(ret)
	}()
	return ret
}
Exemplo n.º 3
0
func Sockaddr(buf common.Buf, length int) syscall.Sockaddr {
	var port [2]byte
	order := buf.K.U.ByteOrder()
	// TODO: handle insufficient length
	var family uint16
	if err := buf.Unpack(&family); err != nil {
		return nil
	}
	// TODO: handle errors?
	st := buf.Struc()
	switch family {
	case AF_LOCAL:
		var a SockaddrUnix
		st.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_INET:
		var a SockaddrInet4
		st.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_INET6:
		var a SockaddrInet6
		st.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_PACKET:
		var a SockaddrLinklayer
		st.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_NETLINK:
		var a SockaddrNetlink
		st.Unpack(&a)
		return sockaddrToNative(&a)
	}
	return nil
}