summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libssh/channels.c2
-rw-r--r--libssh/server.c1
-rw-r--r--sample.c10
3 files changed, 10 insertions, 3 deletions
diff --git a/libssh/channels.c b/libssh/channels.c
index a87d338..3158631 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -674,6 +674,8 @@ int channel_poll(CHANNEL *channel, int is_stderr){
} else
return 0; /* nothing is available has said fd_poll */
}
+ if(channel->remote_eof)
+ return 1;
return buffer_get_len(buffer);
}
diff --git a/libssh/server.c b/libssh/server.c
index 31bae3b..0f42985 100644
--- a/libssh/server.c
+++ b/libssh/server.c
@@ -27,6 +27,7 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>
diff --git a/sample.c b/sample.c
index 60125d6..1d0b367 100644
--- a/sample.c
+++ b/sample.c
@@ -155,7 +155,7 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){
}
}
if(outchannel[0]){
- while(channel_poll(outchannel[0],0)){
+ while(channel && channel_poll(outchannel[0],0)){
lus=channel_read(outchannel[0],readbuf,0,0);
if(lus==-1){
ssh_say(0,"error reading channel : %s\n",ssh_get_error(session));
@@ -163,10 +163,12 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){
}
if(lus==0){
ssh_say(1,"EOF received\n");
+ channel_free(channel);
+ channel=NULL;
} else
write(1,buffer_get(readbuf),lus);
}
- while(channel_poll(outchannel[0],1)){ /* stderr */
+ while(channel && channel_poll(outchannel[0],1)){ /* stderr */
lus=channel_read(outchannel[0],readbuf,0,1);
if(lus==-1){
ssh_say(0,"error reading channel : %s\n",ssh_get_error(session));
@@ -174,11 +176,13 @@ void select_loop(SSH_SESSION *session,CHANNEL *channel){
}
if(lus==0){
ssh_say(1,"EOF received\n");
+ channel_free(channel);
+ channel=NULL;
} else
write(2,buffer_get(readbuf),lus);
}
}
- if(!channel_is_open(channel)){
+ if(channel && !channel_is_open(channel)){
channel_free(channel);
channel=NULL;
}