1
1

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>
Этот коммит содержится в:
Jakub Jelen 2018-11-27 12:55:49 +01:00 коммит произвёл Andreas Schneider
родитель 1be9618f4e
Коммит fff2e85ab2

Просмотреть файл

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