mirror of
https://github.com/libssh2/libssh2.git
synced 2025-07-28 01:41:49 +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:
@ -12,20 +12,21 @@
|
||||
#include <libssh2_sftp.h>
|
||||
|
||||
#ifdef WIN32
|
||||
# define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||
#define write(f, b, c) write((f), (b), (unsigned int)(c))
|
||||
#endif
|
||||
|
||||
#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
|
||||
@ -86,6 +87,8 @@ int main(int argc, char *argv[])
|
||||
struct sockaddr_in sin;
|
||||
const char *fingerprint;
|
||||
LIBSSH2_SESSION *session;
|
||||
const char *pubkey = "/home/username/.ssh/id_rsa.pub";
|
||||
const char *privkey = "/home/username/.ssh/id_rsa";
|
||||
const char *username = "username";
|
||||
const char *password = "password";
|
||||
const char *sftppath = "/tmp/TEST";
|
||||
@ -117,7 +120,6 @@ int main(int argc, char *argv[])
|
||||
else {
|
||||
hostaddr = htonl(0x7F000001);
|
||||
}
|
||||
|
||||
if(argc > 2) {
|
||||
username = argv[2];
|
||||
}
|
||||
@ -143,8 +145,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;
|
||||
}
|
||||
@ -196,10 +197,7 @@ int main(int argc, char *argv[])
|
||||
/* Or by public key */
|
||||
while((rc =
|
||||
libssh2_userauth_publickey_fromfile(session, username,
|
||||
"/home/username/"
|
||||
".ssh/id_rsa.pub",
|
||||
"/home/username/"
|
||||
".ssh/id_rsa",
|
||||
pubkey, privkey,
|
||||
password)) ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
if(rc) {
|
||||
@ -281,9 +279,8 @@ int main(int argc, char *argv[])
|
||||
shutdown:
|
||||
|
||||
fprintf(stderr, "libssh2_session_disconnect\n");
|
||||
while(libssh2_session_disconnect(session,
|
||||
"Normal Shutdown, Thank you") ==
|
||||
LIBSSH2_ERROR_EAGAIN);
|
||||
while(libssh2_session_disconnect(session, "Normal Shutdown")
|
||||
== LIBSSH2_ERROR_EAGAIN);
|
||||
libssh2_session_free(session);
|
||||
|
||||
#ifdef WIN32
|
||||
|
Reference in New Issue
Block a user