Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SSH Socket Try 1
require 'fiddle'
require 'socket'
libssh = Fiddle.dlopen('/usr/lib/libssh.so')
ssh_bind = Fiddle::Function.new(libssh['ssh_bind_new'],[],Fiddle::TYPE_LONG_LONG)
ssh_session = Fiddle::Function.new(libssh['ssh_new'],[],Fiddle::TYPE_LONG_LONG)
ssh_bind_listen = Fiddle::Function.new(libssh['ssh_bind_listen'],[Fiddle::TYPE_LONG_LONG],Fiddle::TYPE_INT)
ssh_bind_accept = Fiddle::Function.new(libssh['ssh_bind_accept'],[Fiddle::TYPE_LONG_LONG,Fiddle::TYPE_LONG_LONG],Fiddle::TYPE_CHAR)
ssh_get_error = Fiddle::Function.new(libssh['ssh_get_error'],[Fiddle::TYPE_LONG],Fiddle::TYPE_CHAR)
sshbind = ssh_bind.call
puts "sshbind pointer: #{sshbind}"
sshsession = ssh_session.call
puts "sshsession pointer: #{sshsession}"
result = ssh_bind_listen.call(sshbind)
if result.to_i < 0
puts "Error: #{ssh_get_error.call(sshbind)}"
else
puts "ssh_bind_listen should return 0: #{result}"
end
sshaccept = ssh_bind_accept.call(sshbind, sshsession)
puts "sshaccept should return 'SSH_OK': #{sshaccept}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment