From 48a20a61379999c4e4342c0cc23389e1a4c69449 Mon Sep 17 00:00:00 2001 From: milo Date: Mon, 9 Aug 2010 18:43:39 +0200 Subject: example: Fixed the sample ssh server implementation. Signed-off-by: Andreas Schneider --- examples/samplesshd.c | 52 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) (limited to 'examples/samplesshd.c') diff --git a/examples/samplesshd.c b/examples/samplesshd.c index cd8127f..ecb23c2 100644 --- a/examples/samplesshd.c +++ b/examples/samplesshd.c @@ -16,6 +16,7 @@ clients must be made or how a client should react. #include #include +#include #ifdef HAVE_ARGP_H #include @@ -32,6 +33,36 @@ clients must be made or how a client should react. #endif #endif +#ifdef WITH_PCAP +#include +const char *pcap_file="debug.server.pcap"; +#endif + + +#ifdef WITH_PCAP +ssh_pcap_file pcap; +void set_pcap(ssh_session session); +void set_pcap(ssh_session session){ + if(!pcap_file) + return; + pcap=ssh_pcap_file_new(); + if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){ + printf("Error opening pcap file\n"); + ssh_pcap_file_free(pcap); + pcap=NULL; + return; + } + ssh_set_pcap_file(session,pcap); +} + +void cleanup_pcap(void); +void cleanup_pcap(){ + ssh_pcap_file_free(pcap); + pcap=NULL; +} +#endif + + static int auth_password(char *user, char *password){ if(strcmp(user,"aris")) return 0; @@ -147,7 +178,7 @@ int main(int argc, char **argv){ ssh_bind sshbind; ssh_message message; ssh_channel chan=0; - ssh_buffer buf; + char buf[2048]; int auth=0; int sftp=0; int i; @@ -166,6 +197,10 @@ int main(int argc, char **argv){ */ argp_parse (&argp, argc, argv, 0, 0, sshbind); #endif +#ifdef WITH_PCAP + set_pcap(session); +#endif + if(ssh_bind_listen(sshbind)<0){ printf("Error listening to socket: %s\n",ssh_get_error(sshbind)); return 1; @@ -254,18 +289,21 @@ int main(int argc, char **argv){ return 1; } printf("it works !\n"); - buf=buffer_new(); do{ - i=channel_read_buffer(chan,buf,0,0); - if(i>0) - if (write(1,buffer_get(buf),buffer_get_len(buf)) < 0) { - printf("error writint to buffer\n"); + i=ssh_channel_read(chan,buf, 2048, 0); + if(i>0) { + ssh_channel_write(chan, buf, i); + if (write(1,buf,i) < 0) { + printf("error writing to buffer\n"); return 1; } + } } while (i>0); - buffer_free(buf); ssh_disconnect(session); ssh_bind_free(sshbind); +#ifdef WITH_PCAP + cleanup_pcap(); +#endif ssh_finalize(); return 0; } -- cgit v1.2.3