[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Looking for examples on using libssh as a server
[Thread Prev] | [Thread Next]
- Subject: Looking for examples on using libssh as a server
- From: The Geek on Skates <geekonskates@xxxxxxxxxxxxxx>
- Reply-to: libssh@xxxxxxxxxx
- Date: Wed, 17 May 2023 03:04:30 +0000
- To: "libssh@xxxxxxxxxx" <libssh@xxxxxxxxxx>
> Good evening(or afternoon, or morning), :) > > I've been on something of a quest, a project that (at the moment) is just for fun, but maybe not exclusively a game thing. I would like to create something like [SSH Tron](http://sshtron.zachlatta.com/); the workflow is simple: > > - ssh sshtron.zachlatta.com > - You play the game > - You get disconnected > > No room for shenanigans. No passing commands, no CTRL-C or CTRL-Z to kill the program (you do that, you get disconnected). Even so, I'm shocked it hasn't been hacked into oblivion. 😄 > > But unfortunately, it's written in Go (a language I don't know and don't care to learn) and some library that's just for Go. Now I'm an experienced C/C++ programmer - I'm all too familiar with things like buffer overflows, double-frees, dereferencing NULL pointers etc. but all I really know about SSH is basic stuff like how to configure sshd, how to generate keys and stuff like that. I also know a bunch of other languages, but since C is my goto (see what I did there? 😄) I started playing with libssh. I'm trying to see if I can figure out how to set up a program to receive incoming connections, send data to the client (the default ssh "command"), receive data from the client and disconnect. I think I've got it connecting (on localhost) but I'm a bit stuck on the reading/writing. ssh_channel_new is failing, ssh_last_error or whatever it is isn't giving me anything... and there are no tutorials. > > So what I'm asking for - if this is okay - is a high-level walkthrough of the process. I'm not asking you to write my program for me (people who do that drive me nuts too 😄) but I'd like to get some idea of the workflow. Like right now what I have is: > > - Some forum posts say you need to call ssh_init(), so I started there. > > - Then I created a "bind" structure using ssh_bind_new() > - Then I used ssh_bind_options_set to set the host name, port, and private key path > - I also used ssh_set_blocking (with 0) because a game like Tron shouldn't wait for the user to press Enter (like getchar()) > - Then I used ssh_new() to create a new session structure > - Then ssh_bind_listen. At this point, my program waits for a new connection. Then I do ssh me@localhost -p 12345 or whatever. This seems to work. > - Then ssh_bind_accept. It seems to accept my connection and then immediately disconnect. So that's progress. > - With NULL-checks and error-checks and all that every step of the way, cuz this is C and that's how we roll. 😄 > > And here's where I am stuck. Forum posts suggest I need to create a "channel" with ssh_channel_new; from there, theoretically, the ssh_channel_write and ssh_channel_read do the reading/writing. Then of course are all the close and free functions to clean up at the end. And of course to support multiple users it would probably have to call fork() and all that... but I'm nowhere near that point. ssh_channel_new fails. I tried using session->channel, but apparently that is a pointer to an "incomplete" type (an error I've never seen before and will be researching this evening after work 😄)... so... stalemate. > Any ideas? What am I missing here? At this point, my best guess is that there another step required to "complete" the session's channel pointer, some secondary initialization involved that isn't clear from a long list of function names. 😄 Any ideas would be greatly appreciated. Thanks and have a great day!
Re: Looking for examples on using libssh as a server | Skalák, Zdeněk <zskalak@xxxxxxxxxxxx> |
Re: Looking for examples on using libssh as a server | Jakub Jelen <jjelen@xxxxxxxxxx> |