mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-07-28 01:41:48 +03:00
Pcap: more cleanup and minimalist API
This commit is contained in:
@ -464,7 +464,6 @@ static int client(ssh_session session){
|
|||||||
ssh_pcap_file pcap;
|
ssh_pcap_file pcap;
|
||||||
void set_pcap(ssh_session session);
|
void set_pcap(ssh_session session);
|
||||||
void set_pcap(ssh_session session){
|
void set_pcap(ssh_session session){
|
||||||
ssh_pcap_context ctx;
|
|
||||||
if(!pcap_file)
|
if(!pcap_file)
|
||||||
return;
|
return;
|
||||||
pcap=ssh_pcap_file_new();
|
pcap=ssh_pcap_file_new();
|
||||||
@ -474,10 +473,9 @@ void set_pcap(ssh_session session){
|
|||||||
pcap=NULL;
|
pcap=NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx=ssh_pcap_context_new(session);
|
ssh_set_pcap_file(session,pcap);
|
||||||
ssh_pcap_context_set_file(ctx,pcap);
|
|
||||||
ssh_set_pcap_context(session,ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup_pcap(void);
|
void cleanup_pcap(void);
|
||||||
void cleanup_pcap(){
|
void cleanup_pcap(){
|
||||||
ssh_pcap_file_free(pcap);
|
ssh_pcap_file_free(pcap);
|
||||||
|
@ -109,6 +109,7 @@ typedef struct ssh_agent_struct* ssh_agent;
|
|||||||
typedef struct ssh_buffer_struct* ssh_buffer;
|
typedef struct ssh_buffer_struct* ssh_buffer;
|
||||||
typedef struct ssh_channel_struct* ssh_channel;
|
typedef struct ssh_channel_struct* ssh_channel;
|
||||||
typedef struct ssh_message_struct* ssh_message;
|
typedef struct ssh_message_struct* ssh_message;
|
||||||
|
typedef struct ssh_pcap_file_struct* ssh_pcap_file;
|
||||||
typedef struct ssh_private_key_struct* ssh_private_key;
|
typedef struct ssh_private_key_struct* ssh_private_key;
|
||||||
typedef struct ssh_public_key_struct* ssh_public_key;
|
typedef struct ssh_public_key_struct* ssh_public_key;
|
||||||
typedef struct ssh_scp_struct* ssh_scp;
|
typedef struct ssh_scp_struct* ssh_scp;
|
||||||
@ -377,7 +378,10 @@ LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv
|
|||||||
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
|
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
|
||||||
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||||
const void *value);
|
const void *value);
|
||||||
|
LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
|
||||||
|
LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
|
||||||
|
LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
|
||||||
|
LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
|
||||||
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
|
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
|
||||||
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
|
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
|
||||||
LIBSSH_API int ssh_scp_close(ssh_scp scp);
|
LIBSSH_API int ssh_scp_close(ssh_scp scp);
|
||||||
@ -403,6 +407,7 @@ LIBSSH_API void ssh_set_fd_except(ssh_session session);
|
|||||||
LIBSSH_API void ssh_set_fd_toread(ssh_session session);
|
LIBSSH_API void ssh_set_fd_toread(ssh_session session);
|
||||||
LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
|
LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
|
||||||
LIBSSH_API void ssh_silent_disconnect(ssh_session session);
|
LIBSSH_API void ssh_silent_disconnect(ssh_session session);
|
||||||
|
LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
|
||||||
ssh_public_key publickey);
|
ssh_public_key publickey);
|
||||||
|
@ -6,17 +6,11 @@
|
|||||||
|
|
||||||
#ifdef WITH_PCAP
|
#ifdef WITH_PCAP
|
||||||
typedef struct ssh_pcap_context_struct* ssh_pcap_context;
|
typedef struct ssh_pcap_context_struct* ssh_pcap_context;
|
||||||
typedef struct ssh_pcap_file_struct* ssh_pcap_file;
|
|
||||||
|
|
||||||
ssh_pcap_file ssh_pcap_file_new(void);
|
|
||||||
int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
|
|
||||||
int ssh_pcap_file_close(ssh_pcap_file pcap);
|
|
||||||
void ssh_pcap_file_free(ssh_pcap_file pcap);
|
|
||||||
|
|
||||||
/* to be removed from here after tests */
|
|
||||||
int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, u_int32_t original_len);
|
int ssh_pcap_file_write_packet(ssh_pcap_file pcap, ssh_buffer packet, u_int32_t original_len);
|
||||||
|
|
||||||
ssh_pcap_context ssh_pcap_context_new(ssh_session session);
|
ssh_pcap_context ssh_pcap_context_new(ssh_session session);
|
||||||
|
void ssh_pcap_context_free(ssh_pcap_context ctx);
|
||||||
|
|
||||||
enum ssh_pcap_direction{
|
enum ssh_pcap_direction{
|
||||||
SSH_PCAP_DIR_IN,
|
SSH_PCAP_DIR_IN,
|
||||||
@ -26,7 +20,6 @@ void ssh_pcap_context_set_file(ssh_pcap_context, ssh_pcap_file);
|
|||||||
int ssh_pcap_context_write(ssh_pcap_context,enum ssh_pcap_direction direction, void *data,
|
int ssh_pcap_context_write(ssh_pcap_context,enum ssh_pcap_direction direction, void *data,
|
||||||
u_int32_t len, u_int32_t origlen);
|
u_int32_t len, u_int32_t origlen);
|
||||||
|
|
||||||
void ssh_set_pcap_context(ssh_session session, ssh_pcap_context pcap);
|
|
||||||
|
|
||||||
#endif /* WITH_PCAP */
|
#endif /* WITH_PCAP */
|
||||||
#endif /* PCAP_H_ */
|
#endif /* PCAP_H_ */
|
||||||
|
@ -220,6 +220,10 @@ ssh_pcap_context ssh_pcap_context_new(ssh_session session){
|
|||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ssh_pcap_context_free(ssh_pcap_context ctx){
|
||||||
|
SAFE_FREE(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
void ssh_pcap_context_set_file(ssh_pcap_context ctx, ssh_pcap_file pcap){
|
void ssh_pcap_context_set_file(ssh_pcap_context ctx, ssh_pcap_file pcap){
|
||||||
ctx->file=pcap;
|
ctx->file=pcap;
|
||||||
}
|
}
|
||||||
@ -355,8 +359,23 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ssh_set_pcap_context(ssh_session session, ssh_pcap_context pcap){
|
/** @brief sets the pcap file used to trace the session
|
||||||
session->pcap_ctx=pcap;
|
* @param current session
|
||||||
|
* @param pcap an handler to a pcap file. A pcap file may be used in several
|
||||||
|
* sessions.
|
||||||
|
* @returns SSH_ERROR in case of error, SSH_OK otherwise.
|
||||||
|
*/
|
||||||
|
int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcap){
|
||||||
|
ssh_pcap_context ctx=ssh_pcap_context_new(session);
|
||||||
|
if(ctx==NULL){
|
||||||
|
ssh_set_error_oom(session);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
ctx->file=pcap;
|
||||||
|
if(session->pcap_ctx)
|
||||||
|
ssh_pcap_context_free(session->pcap_ctx);
|
||||||
|
session->pcap_ctx=ctx;
|
||||||
|
return SSH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,6 +118,12 @@ void ssh_free(ssh_session session) {
|
|||||||
SAFE_FREE(session->serverbanner);
|
SAFE_FREE(session->serverbanner);
|
||||||
SAFE_FREE(session->clientbanner);
|
SAFE_FREE(session->clientbanner);
|
||||||
SAFE_FREE(session->banner);
|
SAFE_FREE(session->banner);
|
||||||
|
#ifdef WITH_PCAP
|
||||||
|
if(session->pcap_ctx){
|
||||||
|
ssh_pcap_context_free(session->pcap_ctx);
|
||||||
|
session->pcap_ctx=NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
buffer_free(session->in_buffer);
|
buffer_free(session->in_buffer);
|
||||||
buffer_free(session->out_buffer);
|
buffer_free(session->out_buffer);
|
||||||
session->in_buffer=session->out_buffer=NULL;
|
session->in_buffer=session->out_buffer=NULL;
|
||||||
|
Reference in New Issue
Block a user