diff --git a/examples/samplesshd-cb.c b/examples/samplesshd-cb.c index 8bc70c47..c0758a2e 100644 --- a/examples/samplesshd-cb.c +++ b/examples/samplesshd-cb.c @@ -25,6 +25,10 @@ clients must be made or how a client should react. #include #include +#ifdef _WIN32 +#include +#endif + #ifndef KEYS_FOLDER #ifdef _WIN32 #define KEYS_FOLDER @@ -241,7 +245,7 @@ int main(int argc, char **argv){ .channel_open_request_session_function = new_session_channel }; - char buf[2048]; + char buf[2049]; int i; int r; @@ -297,19 +301,24 @@ int main(int argc, char **argv){ } else printf("Authenticated and got a channel\n"); do{ - i=ssh_channel_read(chan,buf, 2048, 0); + i=ssh_channel_read(chan, buf, sizeof(buf) - 1, 0); if(i>0) { - ssh_channel_write(chan, buf, i); - if (write(1,buf,i) < 0) { - printf("error writing to buffer\n"); + if (ssh_channel_write(chan, buf, i) == SSH_ERROR) { + printf("error writing to channel\n"); return 1; } + + buf[i] = '\0'; + printf("%s", buf); + fflush(stdout); + if (buf[0] == '\x0d') { - if (write(1, "\n", 1) < 0) { - printf("error writing to buffer\n"); + if (ssh_channel_write(chan, "\n", 1) == SSH_ERROR) { + printf("error writing to channel\n"); return 1; } - ssh_channel_write(chan, "\n", 1); + + printf("\n"); } } } while (i>0);