Refactoring packet detection function arguments

This commit is contained in:
Kaian 2015-09-28 17:11:12 +02:00
parent 3fa4428604
commit 255433595b
7 changed files with 33 additions and 32 deletions

View File

@ -321,25 +321,25 @@ parse_packet(u_char *info, const struct pcap_pkthdr *header, const u_char *packe
}
int
capture_packet_parse(capture_packet_t *pkt)
capture_packet_parse(capture_packet_t *packet)
{
// Media structure for RTP packets
rtp_stream_t *stream;
// We're only interested in packets with payload
if (capture_packet_get_payload_len(pkt)) {
if (capture_packet_get_payload_len(packet)) {
// Parse this header and payload
if (sip_load_message(pkt, pkt->ip_src, pkt->sport, pkt->ip_dst, pkt->dport)) {
if (sip_check_packet(packet)) {
return 0;
}
// Check if this packet belongs to a RTP stream
if ((stream = rtp_check_stream(pkt, pkt->ip_src, pkt->sport, pkt->ip_dst, pkt->dport))) {
if ((stream = rtp_check_packet(packet))) {
// We have an RTP packet!
capture_packet_set_type(pkt, CAPTURE_PACKET_RTP);
capture_packet_set_type(packet, CAPTURE_PACKET_RTP);
// Store this pacekt if capture rtp is enabled
if (capture_cfg.rtp_capture) {
call_add_rtp_packet(stream_get_call(stream), pkt);
call_add_rtp_packet(stream_get_call(stream), packet);
return 0;
}
}

View File

@ -95,13 +95,6 @@ enum SSLConnectionState {
TCP_STATE_CLOSED
};
/**
* XXX We could remove this enum and HandshakeType because
* they are not really used as enums.
* Enumerated values are, in most cases, stored as 4 bytes integer
* while the value it represents in SSL headers is only one byte,
* so we may use SSL3_ defines instead.
*/
//! ContentType values as defined in RFC5246
enum ContentType {
change_cipher_spec = SSL3_RT_CHANGE_CIPHER_SPEC,

View File

@ -149,15 +149,25 @@ rtp_get_standard_format(u_int code)
}
rtp_stream_t *
rtp_check_stream(capture_packet_t *packet, const char *src, u_short sport, const char* dst, u_short dport)
rtp_check_packet(capture_packet_t *packet)
{
// Media structure for RTP packets
const char *src, *dst;
u_short sport, dport;
rtp_stream_t *stream;
rtp_stream_t *reverse;
// RTP payload data
u_int format;
u_char *payload = capture_packet_get_payload(packet);
uint32_t size = capture_packet_get_payload_len(packet);
u_char *payload;
uint32_t size;
// Get packet data
payload = capture_packet_get_payload(packet);
size = capture_packet_get_payload_len(packet);
// Get Addresses from packet
src = packet->ip_src;
dst = packet->ip_dst;
sport = packet->sport;
dport = packet->dport;
// Check if we have at least RTP type
if (size < 2)

View File

@ -94,7 +94,7 @@ const char *
rtp_get_standard_format(u_int code);
rtp_stream_t *
rtp_check_stream(capture_packet_t *packet, const char *src, u_short sport, const char* dst, u_short dport);
rtp_check_packet(capture_packet_t *packet);
rtp_stream_t *
rtp_find_stream(const char *ip_src, u_short sport, const char *ip_dst, u_short dport, u_int format);

View File

@ -24,8 +24,6 @@
* @author Ivan Alonso [aka Kaian] <kaian@irontec.com>
*
* @brief Source of functions defined in sip.h
*
* @todo Replace structures for their typedef shorter names
*/
#include "config.h"
#include <stdlib.h>
@ -216,12 +214,14 @@ sip_get_callid(const char* payload, char *callid)
}
sip_msg_t *
sip_load_message(capture_packet_t *packet, const char *src, u_short sport, const char* dst, u_short dport)
sip_check_packet(capture_packet_t *packet)
{
ENTRY entry;
sip_msg_t *msg;
sip_call_t *call;
char callid[1024];
const char *src, *dst;
u_short sport, dport;
char msg_src[ADDRESSLEN];
char msg_dst[ADDRESSLEN];
u_char payload[MAX_SIP_PAYLOAD];
@ -230,6 +230,12 @@ sip_load_message(capture_packet_t *packet, const char *src, u_short sport, const
if (packet->payload_len > MAX_SIP_PAYLOAD)
return NULL;
// Get Addresses from packet
src = packet->ip_src;
dst = packet->ip_dst;
sport = packet->sport;
dport = packet->dport;
// Get payload from packet(s)
memset(payload, 0, MAX_SIP_PAYLOAD);
memcpy(payload, capture_packet_get_payload(packet), capture_packet_get_payload_len(packet));

View File

@ -149,14 +149,11 @@ sip_get_callid(const char* payload, char *callid);
* Use this function to convert raw data into call and message
* structures. This is mainly used to load data from a file or
*
* @todo This functions should stop using ngrep header format
*
* @param header Raw ngrep header
* @param payload Raw ngrep payload
* @param packet Packet structure pointer
* @return a SIP msg structure pointer
*/
sip_msg_t *
sip_load_message(capture_packet_t *packet, const char *src, u_short sport, const char* dst, u_short dport);
sip_check_packet(capture_packet_t *packet);
/**
* @brief Getter for calls linked list size

View File

@ -389,11 +389,6 @@ draw_message_pos(WINDOW *win, sip_msg_t *msg, int starting);
* @brief Draw a centered dialog with a message
*
* Create a centered dialog with a message.
* TODO improvements
* - Icon
* - Buttons
* - Dimensions
*
* @param msg Message to be drawn
*/
int