我想通過BSD套接字在ssh-server上進行身份驗證。我知道如何發起連接,但不知道如何進行真正的身份驗證。感謝您爲我指出正確方向的時間。通過BSD套接字在SSH上進行身份驗證
這裏是源代碼:
//
#include <stdio.h> // printf()
#include <sys/types.h> // socket data types
#include <sys/socket.h> // socket(), connect(), send(), recv()
#include <arpa/inet.h> // sockaddr_in, inet_addr()
#include <stdlib.h> // free()
#include <unistd.h> // close()
int *ssh(char *host, int port, char *user, char *pass);
int main(void)
{
// create socket
int *ssh_socket = ssh("127.0.0.1", 22, "root", "password");
// close and free
close(*ssh_socket);
free(ssh_socket);
return 0;
}
int *ssh(char *host, int port, char *user, char *pass)
{
int *sock = calloc(sizeof(int), 1);
struct sockaddr_in addr = {.sin_family=AF_INET, \
.sin_port=htons(port), \
.sin_addr.s_addr=inet_addr(host)};
*sock=socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); // create socket
connect(*sock, (struct sockaddr *)&addr, sizeof(addr)); // init connection
// here is the problem
// how do I authenticate on this socket?
return sock;
}
伊斯梅爾,thx打算我的代碼:) – ClosedID 2011-01-20 11:30:34