Exemplo n.º 1
0
func (fd *udtFD) bind() error {
	_, sa, salen, err := fd.laddr.socketArgs()
	if err != nil {
		return err
	}

	// cast sockaddr
	csa := (*C.struct_sockaddr)(unsafe.Pointer(sa))
	if C.udt_bind(fd.sock, csa, C.int(salen)) != 0 {
		return fd.lastErrorOp("bind")
	}

	return nil
}
Exemplo n.º 2
0
func Bind(socket *Socket, portno int) (retval int, err error) {

	hostStr := ""

	if socket.af == syscall.AF_INET6 {
		hostStr = "[0:0:0:0:0:0:0:1]"
	}

	rsa, salen, err := createSockaddr(hostStr, portno)
	if err != nil {
		return -1, fmt.Errorf("could not convert syscall.Sockaddr to syscall.RawSockaddrAny %s", err)
	}

	csa := (*C.struct_sockaddr)(unsafe.Pointer(rsa))
	if C.udt_bind(socket.sock, csa, C.int(salen)) != 0 {
		return -1, udtErrDesc("Unable to bind socket")
	}

	return

}