aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2015-05-05 10:29:38 +0200
committerAndreas Schneider <asn@cryptomilk.org>2015-05-05 11:27:09 +0200
commit7c79959e9402fc11cbfe74b7574e103d34602f6b (patch)
treed5ccd695e9c5d13621d402ccda3f8d842180c66b
parentca501df8c8d84dfc0589427d91faabe936e127cb (diff)
downloadlibssh-7c79959e9402fc11cbfe74b7574e103d34602f6b.tar.gz
libssh-7c79959e9402fc11cbfe74b7574e103d34602f6b.tar.xz
libssh-7c79959e9402fc11cbfe74b7574e103d34602f6b.zip
example: Check return value of ssh_get_fd()
CID: #1199454 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r--examples/sample.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/examples/sample.c b/examples/sample.c
index 616372cb..b716a1b0 100644
--- a/examples/sample.c
+++ b/examples/sample.c
@@ -298,13 +298,22 @@ static void select_loop(ssh_session session,ssh_channel channel){
int ret;
while(channel){
do{
+ int fd;
+
FD_ZERO(&fds);
if(!eof)
FD_SET(0,&fds);
timeout.tv_sec=30;
timeout.tv_usec=0;
- FD_SET(ssh_get_fd(session),&fds);
- maxfd=ssh_get_fd(session)+1;
+
+ fd = ssh_get_fd(session);
+ if (fd < 0) {
+ fprintf(stderr, "Error getting fd\n");
+ return;
+ }
+ FD_SET(fd, &fds);
+ maxfd = fd + 1;
+
channels[0]=channel; // set the first channel we want to read from
channels[1]=NULL;
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);