source: trunk/ETSI-Testsuites/ETSI_auto_IOT/adapter/src/Dispatcher/TcpDissector.cpp

Last change on this file was 22, checked in by rings, 14 years ago
  • Property svn:executable set to *
File size: 1.6 KB
Line 
1#include "TcpDissector.h"
2#include "Logger/Logger.h"
3#ifdef WIN32
4#include <Winsock2.h>
5#else
6#include <netinet/in.h>
7#endif
8
9TcpDissector::TcpDissector() :
10  m_tcpHdr(0)
11{
12}
13
14TcpDissector::~TcpDissector()
15{
16        delete m_tcpHdr;
17}
18
19TcpDissector * TcpDissector::Clone() const
20{
21  return new TcpDissector();
22}
23
24bool TcpDissector::Dissect(const unsigned char * pData, const ssize_t nDataLen)
25{
26  if (!m_tcpHdr)
27    m_tcpHdr = new TcpHeader;
28  memcpy(m_tcpHdr, pData, sizeof(TcpHeader));
29#if BYTE_ORDER == LITTLE_ENDIAN
30  m_tcpHdr->destPort = ntohs(m_tcpHdr->destPort);
31  m_tcpHdr->srcPort = ntohs(m_tcpHdr->srcPort);
32#endif
33  int nOffset = m_tcpHdr->dataOffset;
34  nOffset *= 4;
35  pData += nOffset;
36
37  ssize_t nLen = nDataLen - nOffset;
38  if (nLen > 0)
39  {
40        SavePayload(pData, nLen);
41        SaveLayerInfo();
42  }
43  if (nLen == 0)
44          Logger::Instance().LogDebug("TCP control packet discarded");
45  return nLen > 0;
46  // TODO: This implementation is not sufficient for all cases. It doesn't handle
47  // out-of-order messages and packet loss issues.
48}
49
50bool TcpDissector::NeedReassembly() const {
51  return false;
52}
53
54bool TcpDissector::Reassemble(Dissector * pDissector, ProtocolInfo * pProtocolInfo) {
55  // Fragmentation has to be solved in application layere protocols
56  return Dissector::Reassemble(pDissector, pProtocolInfo);
57}
58
59const EProtocolType TcpDissector::GetUpperLayerType() const {
60        return EProtocolType_Sip;
61}
62
63ProtocolInfoElement * TcpDissector::CreateLayerInfo()
64{
65        TcpInfo * pRes = new TcpInfo();
66        pRes->SetSourcePort(m_tcpHdr->srcPort);
67        pRes->SetDestinationPort(m_tcpHdr->destPort);
68        return pRes;
69}
Note: See TracBrowser for help on using the repository browser.