资源简介
Capabilities and Features
Key Exchange Methods: diffie-hellman-group1-sha1, diffie-hellman-group14-sha1, diffie-hellman-group-exchange-sha1
Hostkey Types: ssh-rsa, ssh-dss
Ciphers: aes256-cbc (rijndael-cbc@lysator.liu.se), aes192-cbc, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, arcfour, none
Compression Schemes: zlib, none
MAC hashes: hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96, hmac-ripemd160 (hmac-ripemd160@openssh.com), none
Authentication: none, password, public-key, hostbased, keyboard-interactive
Channels: shell, exec (incl. SCP wrapper), direct-tcpip, subsystem
Global Requests: tcpip-forward
Channel Requests: x11, pty
Subsystems: sftp(version 3), publickey(version 2)
Thread-safe: just don't share handles simultaneously
Non-blocking: it can be used both blocking and non-blocking
Your sockets: the app hands over the socket, calls select() etc.
OpenSSL or gcrypt: builds with either
代码片段和文件信息
#include “libssh2_config.h“
#include
#ifdef WIN32
#include
#include
#include
#else
#include
#include
#include
#include
#endif
#include
#include
#include
#include
#include
#include
#ifdef HAVE_SYS_SELECT_H
#include
#endif
#ifndef INADDR_NONE
#define INADDR_NONE (in_addr_t)-1
#endif
const char *keyfile1 = “/home/username/.ssh/id_rsa.pub“;
const char *keyfile2 = “/home/username/.ssh/id_rsa“;
const char *username = “username“;
const char *password = ““;
const char *server_ip = “127.0.0.1“;
const char *local_listenip = “127.0.0.1“;
unsigned int local_listenport = 2222;
const char *remote_desthost = “localhost“; /* resolved by the server */
unsigned int remote_destport = 22;
enum {
AUTH_NONE = 0
AUTH_PASSWORD
AUTH_PUBLICKEY
};
int main(int argc char *argv[])
{
int rc sock = -1 listensock = -1 forwardsock = -1 i auth = AUTH_NONE;
struct sockaddr_in sin;
socklen_t sinlen;
const char *fingerprint;
char *userauthlist;
LIBSSH2_SESSION *session;
LIBSSH2_CHANNEL *channel = NULL;
const char *shost;
unsigned int sport;
fd_set fds;
struct timeval tv;
ssize_t len wr;
char buf[16384];
#ifdef WIN32
char sockopt;
WSADATA wsadata;
WSAStartup(MAKEWORD(20) &wsadata);
#else
int sockopt;
#endif
if (argc > 1)
server_ip = argv[1];
if (argc > 2)
username = argv[2];
if (argc > 3)
password = argv[3];
if (argc > 4)
local_listenip = argv[4];
if (argc > 5)
local_listenport = atoi(argv[5]);
if (argc > 6)
remote_desthost = argv[6];
if (argc > 7)
remote_destport = atoi(argv[7]);
rc = libssh2_init (0);
if (rc != 0) {
fprintf (stderr “libssh2 initialization failed (%d)\n“ rc);
return 1;
}
/* Connect to SSH server */
sock = socket(PF_INET SOCK_STREAM IPPROTO_TCP);
sin.sin_family = AF_INET;
if (INADDR_NONE == (sin.sin_addr.s_addr = inet_addr(server_ip))) {
perror(“inet_addr“);
return -1;
}
sin.sin_port = htons(22);
if (connect(sock (struct sockaddr*)(&sin)
sizeof(struct sockaddr_in)) != 0) {
fprintf(stderr “failed to connect!\n“);
return -1;
}
/* Create a session instance */
session = libssh2_session_init();
if(!session) {
fprintf(stderr “Could not initialize SSH session!\n“);
return -1;
}
/* ... start it up. This will trade welcome banners exchange keys
* and setup crypto compression and MAC layers
*/
rc = libssh2_session_handshake(session sock);
if(rc) {
fprintf(stderr “Error when starting up SSH session: %d\n“ rc);
return -1;
}
/* At this point we havn‘t yet authenticated. The first thing to do
* is check
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- 电梯模拟程序C/C 算法实现
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
- SA1110处理器掌上电脑液晶显示器设计
- 基于Linux的串口服务器设计
评论
共有 条评论