Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
f7b62ff8
Commit
f7b62ff8
authored
Sep 09, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HTTP
parent
cc5bf2f4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
31 deletions
+79
-31
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+17
-12
WiresharkStringExtensions.cs
...Net/src/PcapDotNet.Core.Test/WiresharkStringExtensions.cs
+1
-1
HttpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/HttpTests.cs
+11
-1
RandomPacketsExtensions.cs
...c/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
+40
-14
HttpResponseLayer.cs
PcapDotNet/src/PcapDotNet.Packets/Http/HttpResponseLayer.cs
+1
-1
RandomExtensions.cs
PcapDotNet/src/PcapDotNet.TestUtils/RandomExtensions.cs
+9
-2
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
f7b62ff8
using
System
;
using
System
;
using
System.CodeDom
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Globalization
;
using
System.Globalization
;
...
@@ -8,7 +7,6 @@ using System.Linq;
...
@@ -8,7 +7,6 @@ using System.Linq;
using
System.Reflection
;
using
System.Reflection
;
using
System.Text
;
using
System.Text
;
using
System.Xml.Linq
;
using
System.Xml.Linq
;
using
Microsoft.CSharp
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets
;
...
@@ -37,6 +35,7 @@ namespace PcapDotNet.Core.Test
...
@@ -37,6 +35,7 @@ namespace PcapDotNet.Core.Test
private
const
bool
IsRetry
private
const
bool
IsRetry
// = true;
// = true;
=
false
;
=
false
;
private
const
byte
RetryNumber
=
101
;
/// <summary>
/// <summary>
/// Gets or sets the test context which provides
/// Gets or sets the test context which provides
...
@@ -69,7 +68,7 @@ namespace PcapDotNet.Core.Test
...
@@ -69,7 +68,7 @@ namespace PcapDotNet.Core.Test
[
TestMethod
]
[
TestMethod
]
public
void
ComparePacketsToWiresharkTest
()
public
void
ComparePacketsToWiresharkTest
()
{
{
for
(
int
i
=
0
;
i
!=
10
;
++
i
)
for
(
int
i
=
0
;
i
!=
10
0
;
++
i
)
{
{
// Create packets
// Create packets
List
<
Packet
>
packets
=
new
List
<
Packet
>(
CreateRandomPackets
(
200
));
List
<
Packet
>
packets
=
new
List
<
Packet
>(
CreateRandomPackets
(
200
));
...
@@ -229,7 +228,6 @@ namespace PcapDotNet.Core.Test
...
@@ -229,7 +228,6 @@ namespace PcapDotNet.Core.Test
}
}
else
else
{
{
const
byte
RetryNumber
=
89
;
pcapFilename
=
Path
.
GetTempPath
()
+
"temp."
+
RetryNumber
+
".pcap"
;
pcapFilename
=
Path
.
GetTempPath
()
+
"temp."
+
RetryNumber
+
".pcap"
;
List
<
Packet
>
packetsList
=
new
List
<
Packet
>();
List
<
Packet
>
packetsList
=
new
List
<
Packet
>();
using
(
PacketCommunicator
communicator
=
new
OfflinePacketDevice
(
pcapFilename
).
Open
())
using
(
PacketCommunicator
communicator
=
new
OfflinePacketDevice
(
pcapFilename
).
Open
())
...
@@ -248,6 +246,7 @@ namespace PcapDotNet.Core.Test
...
@@ -248,6 +246,7 @@ namespace PcapDotNet.Core.Test
{
{
process
.
StartInfo
=
new
ProcessStartInfo
process
.
StartInfo
=
new
ProcessStartInfo
{
{
// Wireshark's preferences file is %APPDATA%\Wireshark\preferences
FileName
=
WiresharkTsharkPath
,
FileName
=
WiresharkTsharkPath
,
Arguments
=
"-o udp.check_checksum:TRUE "
+
Arguments
=
"-o udp.check_checksum:TRUE "
+
"-o tcp.relative_sequence_numbers:FALSE "
+
"-o tcp.relative_sequence_numbers:FALSE "
+
...
@@ -255,6 +254,7 @@ namespace PcapDotNet.Core.Test
...
@@ -255,6 +254,7 @@ namespace PcapDotNet.Core.Test
"-o tcp.track_bytes_in_flight:FALSE "
+
"-o tcp.track_bytes_in_flight:FALSE "
+
"-o tcp.desegment_tcp_streams:FALSE "
+
"-o tcp.desegment_tcp_streams:FALSE "
+
"-o tcp.check_checksum:TRUE "
+
"-o tcp.check_checksum:TRUE "
+
"-o http.dechunk_body:FALSE "
+
"-t r -n -r \""
+
pcapFilename
+
"\" -T pdml"
,
"-t r -n -r \""
+
pcapFilename
+
"\" -T pdml"
,
WorkingDirectory
=
WiresharkDiretory
,
WorkingDirectory
=
WiresharkDiretory
,
UseShellExecute
=
false
,
UseShellExecute
=
false
,
...
@@ -478,7 +478,7 @@ namespace PcapDotNet.Core.Test
...
@@ -478,7 +478,7 @@ namespace PcapDotNet.Core.Test
switch
(
field
.
Name
())
switch
(
field
.
Name
())
{
{
case
"arp.hw.type"
:
case
"arp.hw.type"
:
field
.
AssertShow
Hex
((
ushort
)
arpDatagram
.
HardwareType
);
field
.
AssertShow
Decimal
((
ushort
)
arpDatagram
.
HardwareType
);
break
;
break
;
case
"arp.proto.type"
:
case
"arp.proto.type"
:
...
@@ -494,7 +494,7 @@ namespace PcapDotNet.Core.Test
...
@@ -494,7 +494,7 @@ namespace PcapDotNet.Core.Test
break
;
break
;
case
"arp.opcode"
:
case
"arp.opcode"
:
field
.
AssertShow
Hex
((
ushort
)
arpDatagram
.
Operation
);
field
.
AssertShow
Decimal
((
ushort
)
arpDatagram
.
Operation
);
break
;
break
;
case
"arp.src.hw"
:
case
"arp.src.hw"
:
...
@@ -1431,10 +1431,16 @@ namespace PcapDotNet.Core.Test
...
@@ -1431,10 +1431,16 @@ namespace PcapDotNet.Core.Test
break
;
break
;
case
""
:
case
""
:
if
(
fieldShow
==
"HTTP chunked response"
)
{
throw
new
InvalidOperationException
(
"HTTP chunked response"
);
}
data
.
Append
(
field
.
Value
());
data
.
Append
(
field
.
Value
());
if
(
fieldShow
==
@"\r\n"
)
if
(
fieldShow
==
@"\r\n"
)
break
;
break
;
else
if
(
isFirstEmptyName
)
if
(
isFirstEmptyName
)
{
{
CompareHttpFirstLine
(
field
,
httpDatagram
);
CompareHttpFirstLine
(
field
,
httpDatagram
);
isFirstEmptyName
=
false
;
isFirstEmptyName
=
false
;
...
@@ -1443,10 +1449,6 @@ namespace PcapDotNet.Core.Test
...
@@ -1443,10 +1449,6 @@ namespace PcapDotNet.Core.Test
{
{
break
;
break
;
}
}
else
if
(
fieldShow
==
"HTTP chunked response"
)
{
field
.
AssertValue
(
httpDatagram
.
Body
);
}
else
else
{
{
fieldShow
=
Encoding
.
GetEncoding
(
28591
).
GetString
(
HexEncoding
.
Instance
.
GetBytes
(
field
.
Value
()));
fieldShow
=
Encoding
.
GetEncoding
(
28591
).
GetString
(
HexEncoding
.
Instance
.
GetBytes
(
field
.
Value
()));
...
@@ -1546,7 +1548,10 @@ namespace PcapDotNet.Core.Test
...
@@ -1546,7 +1548,10 @@ namespace PcapDotNet.Core.Test
break
;
break
;
case
"http.request.version"
:
case
"http.request.version"
:
field
.
AssertShow
(
httpDatagram
.
Version
.
ToString
());
if
(
httpDatagram
.
Version
==
null
)
field
.
AssertShow
(
string
.
Empty
);
else
field
.
AssertShow
(
httpDatagram
.
Version
.
ToString
());
break
;
break
;
case
"http.response.code"
:
case
"http.response.code"
:
...
...
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkStringExtensions.cs
View file @
f7b62ff8
...
@@ -31,7 +31,7 @@ namespace PcapDotNet.Core.Test
...
@@ -31,7 +31,7 @@ namespace PcapDotNet.Core.Test
if
(
currentChar
>=
0x7F
||
currentChar
<
0x20
)
if
(
currentChar
>=
0x7F
||
currentChar
<
0x20
)
{
{
result
.
Append
(
@"\x"
);
result
.
Append
(
@"\x"
);
result
.
Append
(((
int
)
currentChar
).
ToString
(
"x"
));
result
.
Append
(((
int
)
currentChar
).
ToString
(
"x
2
"
));
break
;
break
;
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/HttpTests.cs
View file @
f7b62ff8
...
@@ -50,7 +50,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -50,7 +50,7 @@ namespace PcapDotNet.Packets.Test
[
TestMethod
]
[
TestMethod
]
public
void
RandomHttpTest
()
public
void
RandomHttpTest
()
{
{
Random
random
=
new
Random
(
1
);
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
{
{
...
@@ -76,6 +76,16 @@ namespace PcapDotNet.Packets.Test
...
@@ -76,6 +76,16 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
httpRequestLayer
.
Method
,
httpRequestDatagram
.
Method
);
Assert
.
AreEqual
(
httpRequestLayer
.
Method
,
httpRequestDatagram
.
Method
);
Assert
.
AreEqual
(
httpRequestLayer
.
Uri
,
httpRequestDatagram
.
Uri
);
Assert
.
AreEqual
(
httpRequestLayer
.
Uri
,
httpRequestDatagram
.
Uri
);
}
}
else
{
Assert
.
IsFalse
(
httpDatagram
.
IsRequest
);
Assert
.
IsTrue
(
httpDatagram
.
IsResponse
);
HttpResponseLayer
httpResponseLayer
=
(
HttpResponseLayer
)
httpLayer
;
HttpResponseDatagram
httpResponseDatagram
=
(
HttpResponseDatagram
)
httpDatagram
;
Assert
.
AreEqual
(
httpResponseLayer
.
StatusCode
,
httpResponseDatagram
.
StatusCode
);
Assert
.
AreEqual
(
httpResponseLayer
.
ReasonPhrase
,
httpResponseDatagram
.
ReasonPhrase
);
}
Assert
.
AreEqual
(
httpLayer
.
Header
,
httpDatagram
.
Header
);
Assert
.
AreEqual
(
httpLayer
.
Header
,
httpDatagram
.
Header
);
Assert
.
AreEqual
(
httpLayer
.
Body
,
httpDatagram
.
Body
);
Assert
.
AreEqual
(
httpLayer
.
Body
,
httpDatagram
.
Body
);
Assert
.
AreEqual
(
httpLayer
,
httpDatagram
.
ExtractLayer
(),
"HTTP Layer"
);
Assert
.
AreEqual
(
httpLayer
,
httpDatagram
.
ExtractLayer
(),
"HTTP Layer"
);
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomPacketsExtensions.cs
View file @
f7b62ff8
...
@@ -958,27 +958,47 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -958,27 +958,47 @@ namespace PcapDotNet.Packets.TestUtils
// HTTP
// HTTP
public
static
HttpLayer
NextHttpLayer
(
this
Random
random
)
public
static
HttpLayer
NextHttpLayer
(
this
Random
random
)
{
{
//
if (random.NextBool())
if
(
random
.
NextBool
())
//
{
{
HttpRequestLayer
httpRequestLayer
=
new
HttpRequestLayer
();
HttpRequestLayer
httpRequestLayer
=
new
HttpRequestLayer
();
if
(
random
.
NextBool
())
if
(
random
.
NextBool
(
10
))
{
{
httpRequestLayer
.
Method
=
random
.
NextHttpRequestMethod
();
httpRequestLayer
.
Method
=
random
.
NextHttpRequestMethod
();
httpRequestLayer
.
Uri
=
httpRequestLayer
.
Method
==
null
?
null
:
random
.
NextHttpUri
();
httpRequestLayer
.
Uri
=
httpRequestLayer
.
Method
==
null
?
null
:
random
.
NextHttpUri
();
httpRequestLayer
.
Version
=
httpRequestLayer
.
Uri
==
null
?
null
:
random
.
NextHttpVersion
();
httpRequestLayer
.
Version
=
httpRequestLayer
.
Uri
==
null
||
random
.
NextBool
(
10
)
?
null
:
random
.
NextHttpVersion
();
httpRequestLayer
.
Header
=
httpRequestLayer
.
Version
==
null
?
null
:
random
.
NextHttpHeader
();
httpRequestLayer
.
Header
=
httpRequestLayer
.
Version
==
null
?
null
:
random
.
NextHttpHeader
();
httpRequestLayer
.
Body
=
httpRequestLayer
.
Header
==
null
?
null
:
random
.
NextHttpBody
(
true
,
null
,
httpRequestLayer
.
Header
);
httpRequestLayer
.
Body
=
httpRequestLayer
.
Header
==
null
?
null
:
random
.
NextHttpBody
(
true
,
null
,
httpRequestLayer
.
Header
);
}
}
return
httpRequestLayer
;
return
httpRequestLayer
;
// }
}
// else
// {
HttpResponseLayer
httpResponseLayer
=
new
HttpResponseLayer
// httpLayer = new HttpResponseLayer
{
// {
Version
=
random
.
NextHttpVersion
(),
//
StatusCode
=
random
.
NextBool
(
10
)
?
null
:
(
uint
?)
random
.
NextUInt
(
100
,
999
),
// };
};
// }
httpResponseLayer
.
ReasonPhrase
=
httpResponseLayer
.
StatusCode
==
null
?
null
:
random
.
NextHttpReasonPhrase
();
httpResponseLayer
.
Header
=
httpResponseLayer
.
ReasonPhrase
==
null
?
null
:
random
.
NextHttpHeader
();
httpResponseLayer
.
Body
=
httpResponseLayer
.
Header
==
null
?
null
:
random
.
NextHttpBody
(
false
,
httpResponseLayer
.
StatusCode
,
httpResponseLayer
.
Header
);
return
httpResponseLayer
;
}
public
static
Datagram
NextHttpReasonPhrase
(
this
Random
random
)
{
int
reasonPhraseLength
=
random
.
Next
(
100
);
StringBuilder
reasonPhrase
=
new
StringBuilder
(
reasonPhraseLength
);
for
(
int
i
=
0
;
i
!=
reasonPhraseLength
;
++
i
)
{
if
(
random
.
NextBool
())
reasonPhrase
.
Append
(
random
.
NextHttpTextChar
());
else
if
(
random
.
NextBool
())
reasonPhrase
.
Append
(
' '
);
else
reasonPhrase
.
Append
(
'\t'
);
}
return
new
Datagram
(
Encoding
.
GetEncoding
(
28591
).
GetBytes
(
reasonPhrase
.
ToString
()));
}
}
public
static
HttpRequestMethod
NextHttpRequestMethod
(
this
Random
random
)
public
static
HttpRequestMethod
NextHttpRequestMethod
(
this
Random
random
)
...
@@ -1127,7 +1147,13 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -1127,7 +1147,13 @@ namespace PcapDotNet.Packets.TestUtils
int
numParameters
=
random
.
Next
(
10
);
int
numParameters
=
random
.
Next
(
10
);
List
<
KeyValuePair
<
string
,
string
>>
parameters
=
new
List
<
KeyValuePair
<
string
,
string
>>(
numParameters
);
List
<
KeyValuePair
<
string
,
string
>>
parameters
=
new
List
<
KeyValuePair
<
string
,
string
>>(
numParameters
);
for
(
int
i
=
0
;
i
!=
numParameters
;
++
i
)
for
(
int
i
=
0
;
i
!=
numParameters
;
++
i
)
parameters
.
Add
(
new
KeyValuePair
<
string
,
string
>(
random
.
NextHttpToken
(),
random
.
NextBool
()
?
random
.
NextHttpToken
()
:
random
.
NextHttpQuotedString
()));
{
string
parameterName
=
random
.
NextHttpToken
();
while
(
parameters
.
Any
(
pair
=>
pair
.
Key
==
parameterName
))
parameterName
=
random
.
NextHttpToken
();
parameters
.
Add
(
new
KeyValuePair
<
string
,
string
>(
parameterName
,
random
.
NextBool
()
?
random
.
NextHttpToken
()
:
random
.
NextHttpQuotedString
()));
}
return
new
HttpFieldParameters
(
parameters
);
return
new
HttpFieldParameters
(
parameters
);
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Http/HttpResponseLayer.cs
View file @
f7b62ff8
...
@@ -17,7 +17,7 @@ namespace PcapDotNet.Packets.Http
...
@@ -17,7 +17,7 @@ namespace PcapDotNet.Packets.Http
{
{
return
base
.
Equals
(
other
)
&&
return
base
.
Equals
(
other
)
&&
StatusCode
==
other
.
StatusCode
&&
StatusCode
==
other
.
StatusCode
&&
ReasonPhrase
==
other
.
ReasonPhrase
;
(
ReferenceEquals
(
ReasonPhrase
,
other
.
ReasonPhrase
)
||
ReasonPhrase
.
Equals
(
other
.
ReasonPhrase
))
;
}
}
protected
override
int
FirstLineLength
protected
override
int
FirstLineLength
...
...
PcapDotNet/src/PcapDotNet.TestUtils/RandomExtensions.cs
View file @
f7b62ff8
...
@@ -7,9 +7,11 @@ namespace PcapDotNet.TestUtils
...
@@ -7,9 +7,11 @@ namespace PcapDotNet.TestUtils
{
{
public
static
class
RandomExtensions
public
static
class
RandomExtensions
{
{
public
static
bool
NextBool
(
this
Random
random
)
public
static
bool
NextBool
(
this
Random
random
,
int
chance
=
2
)
{
{
return
random
.
Next
()
%
2
==
0
;
if
(
chance
<
1
)
throw
new
ArgumentOutOfRangeException
(
"chance"
,
chance
,
"must be at least 1"
);
return
random
.
Next
()
%
chance
==
0
;
}
}
public
static
byte
NextByte
(
this
Random
random
,
int
minValue
,
int
maxValue
)
public
static
byte
NextByte
(
this
Random
random
,
int
minValue
,
int
maxValue
)
...
@@ -64,6 +66,11 @@ namespace PcapDotNet.TestUtils
...
@@ -64,6 +66,11 @@ namespace PcapDotNet.TestUtils
return
random
.
NextUInt
()
%
maxValue
;
return
random
.
NextUInt
()
%
maxValue
;
}
}
public
static
uint
NextUInt
(
this
Random
random
,
uint
minvalue
,
uint
maxValue
)
{
return
random
.
NextUInt
()
%
(
maxValue
-
minvalue
+
1
)
+
minvalue
;
}
public
static
UInt48
NextUInt48
(
this
Random
random
)
public
static
UInt48
NextUInt48
(
this
Random
random
)
{
{
return
(
UInt48
)
random
.
NextLong
(
UInt48
.
MaxValue
+
1
);
return
(
UInt48
)
random
.
NextLong
(
UInt48
.
MaxValue
+
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment