我正在一个团队中构建包含客户端和服务器架构的SSH软件。我正在编写SSH服务器,并使用libssh C API在本地服务器上进行测试,然后再部署到远程服务器计算机上。服务器可以正常构建和链接,但是在运行时,accept函数会发生错误,无法创建BIO。下面是我的服务器代码

unsigned int port = xxxx;
int log_func = SSH_LOG_PROTOCOL;
int rc;
static const char * dsakey = "rservd_dsa_file_key";
static const char * rsakey = "rservd_rsa_file_key";


ssh_init();
ssh_bind sshbind = ssh_bind_new();
ssh_session session = ssh_new();

const char * hostname = "127.0.0.1";


ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, hostname);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, dsakey);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY, &log_func);
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, rsakey);


if(ssh_bind_listen(sshbind)<0)
{
    fprintf(stderr, "failed to listen at port %s\n", ssh_get_error(sshbind));
    exit(-1);
}


rc = ssh_bind_accept(sshbind, session);

if(rc == SSH_ERROR)
{
    fprintf(stderr, "Error in accepting a connection : %s\n", ssh_get_error(sshbind));
    exit(-1);
}

ssh_bind_free(sshbind);
ssh_free(session);


谷歌搜索之后,我发现BIO与SSL有关,但是我不太确定。 libssh社区规模不大,因此示例很少,而且不够清晰。那么,该错误的原因可能是什么,我应该怎么做才能解决它?仅供参考,这是libssh 0.5.0

最佳答案

我通过升级到libssh 0.6.3来修复它,连接正常

关于c - libssh bind_accept错误:无法创建BIO,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29072202/

10-11 23:08