aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilo <milo@r0ot.me>2010-08-09 18:43:39 +0200
committerAndreas Schneider <asn@cynapses.org>2010-08-09 20:54:40 +0200
commit48a20a61379999c4e4342c0cc23389e1a4c69449 (patch)
treed6294d4351bd6a5190db2b0a949afe06d531f157
parent8ef0fbc294d8193278385f45456f45d74e177418 (diff)
downloadlibssh-48a20a61379999c4e4342c0cc23389e1a4c69449.tar.gz
libssh-48a20a61379999c4e4342c0cc23389e1a4c69449.tar.xz
libssh-48a20a61379999c4e4342c0cc23389e1a4c69449.zip
example: Fixed the sample ssh server implementation.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
-rw-r--r--examples/samplesshd.c52
1 files changed, 45 insertions, 7 deletions
diff --git a/examples/samplesshd.c b/examples/samplesshd.c
index cd8127f9..ecb23c2e 100644
--- a/examples/samplesshd.c
+++ b/examples/samplesshd.c
@@ -16,6 +16,7 @@ clients must be made or how a client should react.
#include <libssh/libssh.h>
#include <libssh/server.h>
+#include <libssh/buffer.h>
#ifdef HAVE_ARGP_H
#include <argp.h>
@@ -32,6 +33,36 @@ clients must be made or how a client should react.
#endif
#endif
+#ifdef WITH_PCAP
+#include <libssh/pcap.h>
+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;
}