Skip to content

Commit

Permalink
The memory leak test is completed
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jul 15, 2017
1 parent 6d93f82 commit 7bbdbbd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion ConsoleApplication11/ConsoleApplication11.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>ConsoleApplication11</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<ProjectName>Simple-Packet-Sniffer</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -159,7 +160,7 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ConsoleApplication11.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Portocols.cpp" />
<ClCompile Include="Portocols.hpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
Expand Down
6 changes: 3 additions & 3 deletions ConsoleApplication11/ConsoleApplication11.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
<ClCompile Include="stdafx.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="ConsoleApplication11.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="Portocol_IPV4.hpp">
<Filter>源文件\Portocols</Filter>
</ClCompile>
Expand Down Expand Up @@ -83,5 +80,8 @@
<ClCompile Include="Protocol_RARP.cpp">
<Filter>源文件\Portocols</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions ConsoleApplication11/Portocol_IPV4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ inline Protocol_IPV4::Protocol_IPV4(u_char *_uBytes, int _iLength) {
cout << (int)IP_HEADER.ucDestIp[2] << "." << (int)IP_HEADER.ucDestIp[3]<<" ";

Protocols::ProtocolUnit new_protocol = Protocols::get_protocol(get_protocol_num(type()), IP_BODY.packet, _iLength - iHeadLength);
delete new_protocol.oProtocol;
delete IP_BODY.packet;
}
inline int Protocol_IPV4::get_protocol_num(int _iCode) {
switch (_iCode)
Expand Down
3 changes: 2 additions & 1 deletion ConsoleApplication11/Protocol_EthernetII.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ inline Protocol_EthernetII::Protocol_EthernetII(const u_char * _uBytes, int _iLe
MAC_FRAME_BODY.packet = new u_char[_iLength - iHeadLength - iTailLength];
memcpy(MAC_FRAME_BODY.packet, _uBytes + iHeadLength, _iLength - iHeadLength - iTailLength);
Protocols::ProtocolUnit new_protocol = Protocols::get_protocol(get_protocol_num(type()), MAC_FRAME_BODY.packet, _iLength - iHeadLength - iTailLength);

delete new_protocol.oProtocol;
delete MAC_FRAME_BODY.packet;
}

inline int Protocol_EthernetII::get_protocol_num(int _iCode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ConsoleApplication11.cpp : 定义控制台应用程序的入口点。
// main.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
Expand All @@ -14,14 +14,16 @@ using namespace std;


class Packet {
int count = 0;
public:
void new_packet(const u_char* packet,const int len) {
void new_packet(const u_char* packet, const int len) {
cout << "[" << count + 1 << "]";
Protocol_EthernetII EthernetII(packet, len);
count++;
}
};



#define LINE_LEN 16


Expand Down Expand Up @@ -62,9 +64,8 @@ int main(int argc, char **argv)
}

printf("Enter the interface number (1-%d):", i);
//scanf_s("%d", &inum);
inum = 5;

scanf_s("%d", &inum);

if (inum < 1 || inum > i)
{
printf("\nInterface number out of range.\n");
Expand Down
1 change: 0 additions & 1 deletion ConsoleApplication11/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

#pragma once

#include "targetver.h"

#include <tchar.h>
Expand Down

0 comments on commit 7bbdbbd

Please sign in to comment.