diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-16 07:49:44 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-16 07:49:44 +0000 |
commit | 160f6a08d0ee6804ab355d38bbc351b73bd6318a (patch) | |
tree | 0fc17a1e60dcd306159a3b254d4f9ee3540fb305 | |
parent | 1f1e9dc15ba12e382cf6bf8b3231dbdfa46fc9ec (diff) | |
download | libssh-160f6a08d0ee6804ab355d38bbc351b73bd6318a.tar.gz libssh-160f6a08d0ee6804ab355d38bbc351b73bd6318a.tar.xz libssh-160f6a08d0ee6804ab355d38bbc351b73bd6318a.zip |
Improve and document ssh_get_banner().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@483 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r-- | libssh/client.c | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/libssh/client.c b/libssh/client.c index 77e80a4..b04f2ca 100644 --- a/libssh/client.c +++ b/libssh/client.c @@ -33,36 +33,51 @@ if (opt->connect_status_function) \ opt->connect_status_function(opt->connect_status_arg, status); \ } while (0) -/* simply gets a banner from a socket */ -char *ssh_get_banner(SSH_SESSION *session){ - char buffer[128]; - int i = 0; - char *ret; - enter_function(); - while (i < 127) { - if(ssh_socket_read(session->socket, &buffer[i], 1)!= SSH_OK){ - ssh_set_error(session,SSH_FATAL,"Remote host closed connection"); - leave_function(); - return NULL; - } - if (buffer[i] == '\r') - buffer[i] = 0; - if (buffer[i] == '\n') { - buffer[i] = 0; - ret = strdup(buffer); - if (ret == NULL) { - leave_function(); - return NULL; - } - leave_function(); - return ret; - } - i++; +/** + * @internal + * + * @brief Get a banner from a socket. + * + * The caller has to free memroy. + * + * @param session The session to get the banner from. + * + * @return A newly allocated string with the banner or NULL on error. + */ +char *ssh_get_banner(SSH_SESSION *session) { + char buffer[128] = {0}; + char *str = NULL; + int i; + + enter_function(); + + for (i = 0; i < 127; i++) { + if (ssh_socket_read(session->socket, &buffer[i], 1) != SSH_OK) { + ssh_set_error(session, SSH_FATAL, "Remote host closed connection"); + leave_function(); + return NULL; } - ssh_set_error(session,SSH_FATAL,"Too large banner"); - leave_function(); - return NULL; + + if (buffer[i] == '\r') { + buffer[i] = '\0'; + } + if (buffer[i] == '\n') { + buffer[i] = '\0'; + str = strdup(buffer); + if (str == NULL) { + leave_function(); + return NULL; + } + leave_function(); + return str; + } + } + + ssh_set_error(session, SSH_FATAL, "Too large banner"); + + leave_function(); + return NULL; } static int ssh_analyze_banner(SSH_SESSION *session, int *ssh1, int *ssh2){ |