pcap: Reformat ssh_pcap_context_write()

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Daiki Ueno <dueno@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2018-11-27 12:55:49 +01:00
committed by Andreas Schneider
parent 1be9618f4e
commit fff2e85ab2

View File

@@ -353,17 +353,25 @@ static int ssh_pcap_context_connect(ssh_pcap_context ctx){
* @returns SSH_OK write is successful
* @returns SSH_ERROR an error happened.
*/
int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction direction
, void *data, uint32_t len, uint32_t origlen){
int ssh_pcap_context_write(ssh_pcap_context ctx,
enum ssh_pcap_direction direction,
void *data,
uint32_t len,
uint32_t origlen)
{
ssh_buffer ip;
int rc;
if(ctx==NULL || ctx->file ==NULL)
if (ctx == NULL || ctx->file == NULL) {
return SSH_ERROR;
if(ctx->connected==0)
if(ssh_pcap_context_connect(ctx)==SSH_ERROR)
}
if (ctx->connected == 0) {
if (ssh_pcap_context_connect(ctx) == SSH_ERROR) {
return SSH_ERROR;
ip=ssh_buffer_new();
if(ip==NULL){
}
}
ip = ssh_buffer_new();
if (ip == NULL) {
ssh_set_error_oom(ctx->session);
return SSH_ERROR;
}
@@ -384,61 +392,61 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
if (rc != SSH_OK){
goto error;
}
if(direction==SSH_PCAP_DIR_OUT){
rc = ssh_buffer_add_u32(ip,ctx->ipsource);
if (direction == SSH_PCAP_DIR_OUT) {
rc = ssh_buffer_add_u32(ip, ctx->ipsource);
if (rc < 0) {
goto error;
}
rc = ssh_buffer_add_u32(ip,ctx->ipdest);
rc = ssh_buffer_add_u32(ip, ctx->ipdest);
if (rc < 0) {
goto error;
}
} else {
rc = ssh_buffer_add_u32(ip,ctx->ipdest);
rc = ssh_buffer_add_u32(ip, ctx->ipdest);
if (rc < 0) {
goto error;
}
rc = ssh_buffer_add_u32(ip,ctx->ipsource);
rc = ssh_buffer_add_u32(ip, ctx->ipsource);
if (rc < 0) {
goto error;
}
}
/* TCP */
if(direction==SSH_PCAP_DIR_OUT){
rc = ssh_buffer_add_u16(ip,ctx->portsource);
if (direction == SSH_PCAP_DIR_OUT) {
rc = ssh_buffer_add_u16(ip, ctx->portsource);
if (rc < 0) {
goto error;
}
rc = ssh_buffer_add_u16(ip,ctx->portdest);
rc = ssh_buffer_add_u16(ip, ctx->portdest);
if (rc < 0) {
goto error;
}
} else {
rc = ssh_buffer_add_u16(ip,ctx->portdest);
rc = ssh_buffer_add_u16(ip, ctx->portdest);
if (rc < 0) {
goto error;
}
rc = ssh_buffer_add_u16(ip,ctx->portsource);
rc = ssh_buffer_add_u16(ip, ctx->portsource);
if (rc < 0) {
goto error;
}
}
/* sequence number */
if(direction==SSH_PCAP_DIR_OUT){
if (direction == SSH_PCAP_DIR_OUT) {
rc = ssh_buffer_pack(ip, "d", ctx->outsequence);
if (rc != SSH_OK) {
goto error;
}
ctx->outsequence+=origlen;
ctx->outsequence += origlen;
} else {
rc = ssh_buffer_pack(ip, "d", ctx->insequence);
if (rc != SSH_OK) {
goto error;
}
ctx->insequence+=origlen;
ctx->insequence += origlen;
}
/* ack number */
if(direction==SSH_PCAP_DIR_OUT){
if (direction == SSH_PCAP_DIR_OUT) {
rc = ssh_buffer_pack(ip, "d", ctx->insequence);
if (rc != SSH_OK) {
goto error;
@@ -461,7 +469,8 @@ int ssh_pcap_context_write(ssh_pcap_context ctx,enum ssh_pcap_direction directio
if (rc != SSH_OK) {
goto error;
}
rc=ssh_pcap_file_write_packet(ctx->file,ip,origlen + TCPIPHDR_LEN);
rc = ssh_pcap_file_write_packet(ctx->file, ip, origlen + TCPIPHDR_LEN);
error:
ssh_buffer_free(ip);
return rc;