资源简介
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
相关资源
- LINUX 串口与SPI操作
- 嵌入式Linux应用系统开发精讲源码
- 深入理解计算机系统原书第三版超高
- linux下基于V4L2/Qt的usb摄像头采集显示
- 信息学奥赛一本通课后练习答案汇总
- 操作系统实验生产者与消费者实验报
- linux下哲学家就餐问题大作业
- linux下c (一个简单的sniffer工具)
- linux下使用IIC总线读写EEPROM
- linux 目录树实现代码递归
- Linux下基于原始套接字的嗅探器
- 详细介绍linux下移植wifi的步骤
- 学生管理系统 根据数据结构的链表知
- linux环境rtmp推流
- 为LINUX 设计一个简单的二级文件系统
- Linux引导删除工具(mbrfix)
- mini6410 所有应用程序源码
- linpop neusoft
- VC使用jmail.dll编写电子邮件发送和接受
- Linux下包过滤防火墙的设计与实现
- Linux下网络传输实现Reliable Data Transp
- linux下读写ini文件方法,可直接用
- Linux操作系统基础教程
- linux PCIE架构详解
- Linux复习题及答案-期末考试70%题目
- linux epoll的封装类
- windows 2008 DNS 与 Linux 同步
- linux 下 libssl.so.10 libcrypto.so.10
- STM32F103 ucLinux 开发BOOT源码
- 嵌入式LINUX下WEB服务器的设计与实现
评论
共有 条评论