我是新手libssh
并试图连接到远程机器以运行一些命令。所有的连接和命令都没有错误地返回,但是在离开范围时程序会出现段错误。我究竟做错了什么?
代码
#include <string>
#include <iostream>
using namespace std;
#define SSH_NO_CPP_EXCEPTIONS
#include <libssh/libsshpp.hpp>
int main()
{
ssh::Session session;
//Set options
session.setOption(SSH_OPTIONS_HOST, "192.168.200.101");
session.setOption( SSH_OPTIONS_USER, "user" );
//Connect to host
session.connect();
//Authenticate user
session.userauthPassword( "password" );
//Open channel
ssh::Channel channel( session );
channel.openSession();
//Do something
channel.requestExec( "ps_aux" );
//Close channel
channel.sendEof();
channel.close();
//Disconnect
session.disconnect();
return 0;
}
GDB 跟踪
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff3a70a2f in ssh_channel_free () from /usr/local/lib/libssh.so.4
(gdb) where
#0 0x00007ffff3a70a2f in ssh_channel_free () from /usr/local/lib/libssh.so.4
#1 0x000000000059f436 in ssh::Channel::~Channel() ()
#2 0x000000000059e603 in main ()