mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-29 13:01:14 +03:00
tidy-up: example, tests
- drop unnecessary `WIN32`-specific branches. - add `static`. - sync header inclusion order. - sync some common code between examples/tests. - fix formatting/indentation. - fix some `checksrc` errors not caught by `checksrc`. Closes #936
This commit is contained in:
@ -14,26 +14,27 @@
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#ifdef HAVE_ARPA_INET_H
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
|
||||
@ -98,10 +99,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
if(argc > 1)
|
||||
/* must be ip address only */
|
||||
hostname = argv[1];
|
||||
|
||||
if(argc > 1) {
|
||||
hostname = argv[1]; /* must be ip address only */
|
||||
}
|
||||
if(argc > 2) {
|
||||
username = argv[2];
|
||||
}
|
||||
@ -126,8 +126,7 @@ int main(int argc, char *argv[])
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(22);
|
||||
sin.sin_addr.s_addr = hostaddr;
|
||||
if(connect(sock, (struct sockaddr*)(&sin),
|
||||
sizeof(struct sockaddr_in)) != 0) {
|
||||
if(connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in))) {
|
||||
fprintf(stderr, "failed to connect!\n");
|
||||
return -1;
|
||||
}
|
||||
@ -144,7 +143,7 @@ int main(int argc, char *argv[])
|
||||
* and setup crypto, compression, and MAC layers
|
||||
*/
|
||||
while((rc = libssh2_session_handshake(session, sock)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
if(rc) {
|
||||
fprintf(stderr, "Failure establishing SSH session: %d\n", rc);
|
||||
return -1;
|
||||
@ -233,7 +232,7 @@ int main(int argc, char *argv[])
|
||||
for(i = 0; i < BUFSIZE; i++)
|
||||
buffer[i] = 'A';
|
||||
|
||||
fds = malloc(sizeof (LIBSSH2_POLLFD));
|
||||
fds = malloc(sizeof(LIBSSH2_POLLFD));
|
||||
if(!fds) {
|
||||
fprintf(stderr, "malloc failed\n");
|
||||
exit(1);
|
||||
@ -349,8 +348,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
libssh2_session_disconnect(session,
|
||||
"Normal Shutdown, Thank you for playing");
|
||||
libssh2_session_disconnect(session, "Normal Shutdown");
|
||||
libssh2_session_free(session);
|
||||
|
||||
#ifdef WIN32
|
||||
|
Reference in New Issue
Block a user