Skip to content

Commit

Permalink
Arrange tab character > space
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert Lee committed Jul 29, 2014
1 parent c53ab3a commit 6f9671b
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 102 deletions.
2 changes: 1 addition & 1 deletion include/filter/snoopbpfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool SnoopBpFilter::doClose()
if (m_code != NULL)
{
pcap_freecode(m_code);
free(m_code);
free(m_code);
m_code = NULL;
}

Expand Down
202 changes: 101 additions & 101 deletions include/process/snooptcpblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,62 +57,62 @@ int SnoopTcpBlock::sendForwardBlock(SnoopCapture* capture, SnoopPacket* packet,
return -1;
}

int bufSize = sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length();
QByteArray ba; ba.resize(bufSize); BYTE* buf = (BYTE*)ba.data();
int bufSize = sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length();
QByteArray ba; ba.resize(bufSize); BYTE* buf = (BYTE*)ba.data();

ETH_HDR* ethHdr = (ETH_HDR*) &buf[0];
IP_HDR* ipHdr = (IP_HDR*) &buf[sizeof(ETH_HDR)];
TCP_HDR* tcpHdr = (TCP_HDR*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR)];
ETH_HDR* ethHdr = (ETH_HDR*) &buf[0];
IP_HDR* ipHdr = (IP_HDR*) &buf[sizeof(ETH_HDR)];
TCP_HDR* tcpHdr = (TCP_HDR*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR)];
BYTE* data = (BYTE*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR)];

//
// Ethernet Header
//
memcpy(ethHdr, packet->ethHdr, sizeof(ETH_HDR));

//
// IP Header
//
memcpy(ipHdr, packet->ipHdr, sizeof(IP_HDR));
ipHdr->ip_tos = TCP_BLOCK_TOS_NO; // value of 44 means tag identifier of Snoop Component RST sending.
ipHdr->ip_len = htons(sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length());
ipHdr->ip_ttl = 255;

//
// TCP Header
//
int tcpDataLen;
if (!SnoopTcp::isData(packet->ipHdr, packet->tcpHdr, NULL, &tcpDataLen)) tcpDataLen = 0;
int flagAddLen = ((packet->tcpHdr->th_flags & (TH_SYN | TH_FIN))) ? 1 : 0;
UINT32 newSeq = ntohl(packet->tcpHdr->th_seq) + tcpDataLen + flagAddLen;

memcpy(tcpHdr, packet->tcpHdr, sizeof(TCP_HDR));
tcpHdr->th_seq = htonl(newSeq);
tcpHdr->th_off = sizeof(TCP_HDR) / sizeof(UINT32);
tcpHdr->th_flags = flag | TH_ACK;
tcpHdr->th_win = 0;

//
// Data
//
memcpy(data, msg.data(), msg.length());

//
// Checksum
//
tcpHdr->th_sum = htons(SnoopTcp::checksum(ipHdr, tcpHdr));
ipHdr->ip_sum = htons(SnoopIp::checksum(ipHdr));


//
// Write
//
int res = capture->write(buf, bufSize, &packet->divertAddr);
if (res == VERR_FAIL)
{
LOG_ERROR("capture->write return %d", res);
}
return res;
//
// IP Header
//
memcpy(ipHdr, packet->ipHdr, sizeof(IP_HDR));
ipHdr->ip_tos = TCP_BLOCK_TOS_NO; // value of 44 means tag identifier of Snoop Component RST sending.
ipHdr->ip_len = htons(sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length());
ipHdr->ip_ttl = 255;

//
// TCP Header
//
int tcpDataLen;
if (!SnoopTcp::isData(packet->ipHdr, packet->tcpHdr, NULL, &tcpDataLen)) tcpDataLen = 0;
int flagAddLen = ((packet->tcpHdr->th_flags & (TH_SYN | TH_FIN))) ? 1 : 0;
UINT32 newSeq = ntohl(packet->tcpHdr->th_seq) + tcpDataLen + flagAddLen;

memcpy(tcpHdr, packet->tcpHdr, sizeof(TCP_HDR));
tcpHdr->th_seq = htonl(newSeq);
tcpHdr->th_off = sizeof(TCP_HDR) / sizeof(UINT32);
tcpHdr->th_flags = flag | TH_ACK;
tcpHdr->th_win = 0;

//
// Data
//
memcpy(data, msg.data(), msg.length());

//
// Checksum
//
tcpHdr->th_sum = htons(SnoopTcp::checksum(ipHdr, tcpHdr));
ipHdr->ip_sum = htons(SnoopIp::checksum(ipHdr));


//
// Write
//
int res = capture->write(buf, bufSize, &packet->divertAddr);
if (res == VERR_FAIL)
{
LOG_ERROR("capture->write return %d", res);
}
return res;
}

int SnoopTcpBlock::sendBackwardBlock(SnoopCapture* capture, SnoopPacket* packet, UINT8 flag, QByteArray msg)
Expand All @@ -123,13 +123,13 @@ int SnoopTcpBlock::sendBackwardBlock(SnoopCapture* capture, SnoopPacket* packet,
return -1;
}

int bufSize = sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length();
QByteArray ba; ba.resize(bufSize); BYTE* buf = (BYTE*)ba.data();
int bufSize = sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length();
QByteArray ba; ba.resize(bufSize); BYTE* buf = (BYTE*)ba.data();

ETH_HDR* ethHdr = (ETH_HDR*) &buf[0];
IP_HDR* ipHdr = (IP_HDR*) &buf[sizeof(ETH_HDR)];
TCP_HDR* tcpHdr = (TCP_HDR*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR)];
char* data = (char*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR)];
ETH_HDR* ethHdr = (ETH_HDR*) &buf[0];
IP_HDR* ipHdr = (IP_HDR*) &buf[sizeof(ETH_HDR)];
TCP_HDR* tcpHdr = (TCP_HDR*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR)];
char* data = (char*) &buf[sizeof(ETH_HDR) + sizeof(IP_HDR) + sizeof(TCP_HDR)];

//
// Ethernet Header
Expand All @@ -138,53 +138,53 @@ int SnoopTcpBlock::sendBackwardBlock(SnoopCapture* capture, SnoopPacket* packet,
ethHdr->ether_shost = packet->ethHdr->ether_dhost;
ethHdr->ether_type = packet->ethHdr->ether_type;

//
// IP Header
//
memcpy(ipHdr, packet->ipHdr, sizeof(IP_HDR));
ipHdr->ip_tos = TCP_BLOCK_TOS_NO; // value of 44 means tag identifier of Snoop Component RST sending.
ipHdr->ip_len = htons(sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length());
ipHdr->ip_ttl = 255;
ipHdr->ip_src = packet->ipHdr->ip_dst;
ipHdr->ip_dst = packet->ipHdr->ip_src;

//
// TCP Header
//
int tcpDataLen;
if (!SnoopTcp::isData(packet->ipHdr, packet->tcpHdr, NULL, &tcpDataLen)) tcpDataLen = 0;
int flagAddLen = ((packet->tcpHdr->th_flags & (TH_SYN | TH_FIN))) ? 1 : 0;
UINT32 newSeq = ntohl(packet->tcpHdr->th_seq) + tcpDataLen + flagAddLen;

memcpy(tcpHdr, packet->tcpHdr, sizeof(TCP_HDR));
tcpHdr->th_sport = packet->tcpHdr->th_dport;
tcpHdr->th_dport = packet->tcpHdr->th_sport;
tcpHdr->th_seq = packet->tcpHdr->th_ack;
tcpHdr->th_ack = htonl(newSeq);
tcpHdr->th_off = sizeof(TCP_HDR) / sizeof(UINT32);
tcpHdr->th_flags = flag | TH_ACK;
tcpHdr->th_win = 0;

//
// Data
//
memcpy(data, msg.data(), msg.length());

//
// Checksum
//
tcpHdr->th_sum = htons(SnoopTcp::checksum(ipHdr, tcpHdr));
ipHdr->ip_sum = htons(SnoopIp::checksum(ipHdr));

//
// Write
//
int res = capture->write(buf, bufSize, &packet->divertAddr);
if (res == VERR_FAIL)
{
LOG_ERROR("capture->write return %d", res);
}
return res;
//
// IP Header
//
memcpy(ipHdr, packet->ipHdr, sizeof(IP_HDR));
ipHdr->ip_tos = TCP_BLOCK_TOS_NO; // value of 44 means tag identifier of Snoop Component RST sending.
ipHdr->ip_len = htons(sizeof(IP_HDR) + sizeof(TCP_HDR) + msg.length());
ipHdr->ip_ttl = 255;
ipHdr->ip_src = packet->ipHdr->ip_dst;
ipHdr->ip_dst = packet->ipHdr->ip_src;

//
// TCP Header
//
int tcpDataLen;
if (!SnoopTcp::isData(packet->ipHdr, packet->tcpHdr, NULL, &tcpDataLen)) tcpDataLen = 0;
int flagAddLen = ((packet->tcpHdr->th_flags & (TH_SYN | TH_FIN))) ? 1 : 0;
UINT32 newSeq = ntohl(packet->tcpHdr->th_seq) + tcpDataLen + flagAddLen;

memcpy(tcpHdr, packet->tcpHdr, sizeof(TCP_HDR));
tcpHdr->th_sport = packet->tcpHdr->th_dport;
tcpHdr->th_dport = packet->tcpHdr->th_sport;
tcpHdr->th_seq = packet->tcpHdr->th_ack;
tcpHdr->th_ack = htonl(newSeq);
tcpHdr->th_off = sizeof(TCP_HDR) / sizeof(UINT32);
tcpHdr->th_flags = flag | TH_ACK;
tcpHdr->th_win = 0;

//
// Data
//
memcpy(data, msg.data(), msg.length());

//
// Checksum
//
tcpHdr->th_sum = htons(SnoopTcp::checksum(ipHdr, tcpHdr));
ipHdr->ip_sum = htons(SnoopIp::checksum(ipHdr));

//
// Write
//
int res = capture->write(buf, bufSize, &packet->divertAddr);
if (res == VERR_FAIL)
{
LOG_ERROR("capture->write return %d", res);
}
return res;
}

void SnoopTcpBlock::tcpBlock(SnoopPacket* packet)
Expand Down

0 comments on commit 6f9671b

Please sign in to comment.