#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <libssh/libssh.h>
#include <libssh/kex.h>
int main(int argc, char **argv)
{
const char *banner = NULL;
ssh_session session = NULL;
const char *hostkeys = NULL;
int rc = 1;
bool process_config = false;
if (argc < 1 || argv[1] == NULL) {
fprintf(stderr, "Error: Need an argument (hostname)\n");
goto out;
}
ssh_init();
session = ssh_new();
if (session == NULL) {
goto out;
}
rc = ssh_options_set(session, SSH_OPTIONS_HOST, argv[1]);
if (rc < 0) {
goto out;
}
rc = ssh_options_set(session, SSH_OPTIONS_USER, "ping");
if (rc < 0) {
goto out;
}
rc = ssh_options_set(session, SSH_OPTIONS_PROCESS_CONFIG, &process_config);
if (rc < 0) {
goto out;
}
hostkeys = ssh_kex_get_supported_method(SSH_HOSTKEYS);
rc = ssh_options_set(session, SSH_OPTIONS_HOSTKEYS, hostkeys);
if (rc < 0) {
goto out;
}
rc = ssh_connect(session);
if (rc != SSH_OK) {
fprintf(stderr, "Connection failed : %s\n", ssh_get_error(session));
goto out;
}
banner = ssh_get_serverbanner(session);
if (banner == NULL) {
fprintf(stderr, "Did not receive SSH banner\n");
goto out;
}
printf("OK: %s\n", banner);
rc = 0;
out:
ssh_free(session);
ssh_finalize();
return rc;
}