From c57daeb0b283c4c0ab338968ab32408ac6759d2e Mon Sep 17 00:00:00 2001 From: Per-Grana Date: Thu, 26 May 2011 11:28:57 +0200 Subject: [PATCH] indentation change --- src/tcp.cpp | 418 ++++++++++++++++++++++++++-------------------------- 1 file changed, 209 insertions(+), 209 deletions(-) diff --git a/src/tcp.cpp b/src/tcp.cpp index 85c4f4b..f6b6260 100755 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -43,31 +43,31 @@ namespace se { /// TCP Stream id class - serves as the key in the streams map class Stream_id { - public: - /// constructor - Stream_id() - { - } - /// constructor taking source and destination adresses - Stream_id( in6addr_t &src_ip, - in6addr_t &dst_ip, - unsigned short src_port, - unsigned short dst_port) - { - m_src_ip = src_ip; - m_dst_ip = dst_ip; - m_src_port = src_port; - m_dst_port = dst_port; - } - - /// < comparison operator for the std::map - bool operator < (const Stream_id &rhs) const - { - return memcmp(this,&rhs,sizeof(Stream_id)) < 0; - } - private: - in6addr_t m_src_ip, m_dst_ip; - unsigned short m_src_port,m_dst_port; + public: + /// constructor + Stream_id() + { + } + /// constructor taking source and destination adresses + Stream_id( in6addr_t &src_ip, + in6addr_t &dst_ip, + unsigned short src_port, + unsigned short dst_port) + { + m_src_ip = src_ip; + m_dst_ip = dst_ip; + m_src_port = src_port; + m_dst_port = dst_port; + } + + /// < comparison operator for the std::map + bool operator < (const Stream_id &rhs) const + { + return memcmp(this,&rhs,sizeof(Stream_id)) < 0; + } + private: + in6addr_t m_src_ip, m_dst_ip; + unsigned short m_src_port,m_dst_port; }; /// TCP data segment container @@ -76,37 +76,37 @@ class Stream_id */ class Data_segment { - public: - /// Constructor taking a memory block with packet content - Data_segment( unsigned char *data, unsigned int len) - { - m_datasize = len; - m_data = new unsigned char[len]; - for (unsigned int i=0; i 0 && s.m_datasize <= 65535) ) - { - m_segments.push_back(s); - m_seq=seq+s.m_datasize; - } - } - } - /// checka if there's any content in the stream - bool has_content() - { - return m_content; - } - /// Erase (and free) all segments and reset state - void erase() - { - m_content = false; - m_nseq = false; - m_segments.clear(); - - } - /// return the streams data size - int get_size() - { - int size = 0; - for (std::list::iterator it = m_segments.begin(); - it != m_segments.end(); it ++) - { - size += it->m_datasize; - } - return size; - } - /// debug functionality to dump a streams content - void dump() - { - int start=2; - for (std::list::iterator it = m_segments.begin(); - it != m_segments.end(); it ++) - { - for (unsigned int i=start; i< it->m_datasize; i++) + if (m_seq==seq) { - printf("%02x",it->m_data[i]); + m_content = true; + if ( (s.m_datasize > 0 && s.m_datasize <= 65535) ) + { + m_segments.push_back(s); + m_seq=seq+s.m_datasize; + } } - start = 0; - } - printf("\n"); - } - /// returns the data in the stream - /** The returned data is located in a static buffer shared by all streams - * the data is valid until the next call to get_buffer() - */ - unsigned char *get_buffer() - { - int start=2, p=0; - for (std::list::iterator it = m_segments.begin(); - it != m_segments.end(); it ++) - { - for (unsigned int i=0; i< it->m_datasize; i++) + } + /// checka if there's any content in the stream + bool has_content() + { + return m_content; + } + /// Erase (and free) all segments and reset state + void erase() + { + m_content = false; + m_nseq = false; + m_segments.clear(); + + } + /// return the streams data size + int get_size() + { + int size = 0; + for (std::list::iterator it = m_segments.begin(); + it != m_segments.end(); it ++) { - m_buffer[p++]=it->m_data[i]; - if (p>=0xffff) - return m_buffer; + size += it->m_datasize; } - start = 0; - } - return m_buffer; - } - private: - unsigned int m_seq; - int m_ser; - bool m_content; - bool m_nseq; - std::list m_segments; - - static unsigned char m_buffer[0x10000]; + return size; + } + /// debug functionality to dump a streams content + void dump() + { + int start=2; + for (std::list::iterator it = m_segments.begin(); + it != m_segments.end(); it ++) + { + for (unsigned int i=start; i< it->m_datasize; i++) + { + printf("%02x",it->m_data[i]); + } + start = 0; + } + printf("\n"); + } + /// returns the data in the stream + /** The returned data is located in a static buffer shared by all streams + * the data is valid until the next call to get_buffer() + */ + unsigned char *get_buffer() + { + int start=2, p=0; + for (std::list::iterator it = m_segments.begin(); + it != m_segments.end(); it ++) + { + for (unsigned int i=0; i< it->m_datasize; i++) + { + m_buffer[p++]=it->m_data[i]; + if (p>=0xffff) + return m_buffer; + } + start = 0; + } + return m_buffer; + } + private: + unsigned int m_seq; + int m_ser; + bool m_content; + bool m_nseq; + std::list m_segments; + + static unsigned char m_buffer[0x10000]; }; unsigned char Stream::m_buffer[0x10000]; std::map g_tcp_streams; - + /// assemble_tcp builds datastreams out of tcp packets @@ -227,69 +227,69 @@ std::map g_tcp_streams; * it is up to the caller to free() the memory returned. */ unsigned char * -assemble_tcp ( - Payload &payload, - in6addr_t *src_ip, - in6addr_t *dst_ip, - unsigned short src_port, - unsigned short dst_port, - unsigned int *rest, - unsigned int seq, - unsigned char *data, - int len, - char syn, - char fin, - char rst, - char ack) -{ - Stream_id id ( *src_ip, *dst_ip, src_port, dst_port ); - Stream &str = g_tcp_streams[id]; - bool data_avail = false; + assemble_tcp ( + Payload &payload, + in6addr_t *src_ip, + in6addr_t *dst_ip, + unsigned short src_port, + unsigned short dst_port, + unsigned int *rest, + unsigned int seq, + unsigned char *data, + int len, + char syn, + char fin, + char rst, + char ack) + { + Stream_id id ( *src_ip, *dst_ip, src_port, dst_port ); + Stream &str = g_tcp_streams[id]; + bool data_avail = false; - if (!str.has_content()) - { - Data_segment seg( data, len); - str.add( syn,seq, seg); - } - else - { - if (rst == 1) - { - str.erase(); - } - else if (syn == 1) - { - str.erase(); - Data_segment seg( data, len); - str.add( syn,seq, seg); - } - else if (fin == 0) - { - Data_segment seg( data, len); - str.add( syn,seq, seg); - } - } + if (!str.has_content()) + { + Data_segment seg( data, len); + str.add( syn,seq, seg); + } + else + { + if (rst == 1) + { + str.erase(); + } + else if (syn == 1) + { + str.erase(); + Data_segment seg( data, len); + str.add( syn,seq, seg); + } + else if (fin == 0) + { + Data_segment seg( data, len); + str.add( syn,seq, seg); + } + } - data = 0; - if (str.has_content() ) - { - int size = str.get_size(); - unsigned char *buffer = str.get_buffer(); - int dns_size = (int(buffer[0])<<8) | buffer[1]; + data = 0; + if (str.has_content() ) + { + int size = str.get_size(); + unsigned char *buffer = str.get_buffer(); + int dns_size = (int(buffer[0])<<8) | buffer[1]; - data_avail = (fin == 1) && (rst == 0); - if (data_avail || dns_size+2==size) - { - *rest = size; - if (*rest > 0xffff) - *rest = 0xffff; - data = (unsigned char*)payload.alloc(*rest); - memcpy( data, buffer, *rest ); - str.erase(); - g_tcp_streams.erase(id); - } - } - return data; -} + data_avail = (fin == 1) && (rst == 0); + if (data_avail || dns_size+2==size) + { + *rest = size; + if (*rest > 0xffff) + *rest = 0xffff; + data = (unsigned char*)payload.alloc(*rest); + memcpy( data, buffer, *rest ); + str.erase(); + g_tcp_streams.erase(id); + } + } + return data; + } }