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
be380b07
Commit
be380b07
authored
Oct 21, 2011
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DNS
parent
8e1d67cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
163 additions
and
10 deletions
+163
-10
RandomDnsExtensions.cs
...t/src/PcapDotNet.Packets.TestUtils/RandomDnsExtensions.cs
+3
-0
ByteArrayExtensions.cs
PcapDotNet/src/PcapDotNet.Packets/ByteArrayExtensions.cs
+95
-10
DataSegment.cs
PcapDotNet/src/PcapDotNet.Packets/DataSegment.cs
+12
-0
DnsResourceData.cs
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsResourceData.cs
+53
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomDnsExtensions.cs
View file @
be380b07
...
@@ -150,6 +150,9 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -150,6 +150,9 @@ namespace PcapDotNet.Packets.TestUtils
(
random
.
Next
(-
180
,
180
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
),
(
random
.
Next
(-
180
,
180
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
),
(
random
.
Next
(-
500
,
50000
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
));
(
random
.
Next
(-
500
,
50000
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
));
case
DnsType
.
Aaaa
:
return
new
DnsResourceDataIpV6
(
random
.
NextIpV6Address
());
default
:
default
:
return
new
DnsResourceDataAnything
(
random
.
NextDataSegment
(
random
.
Next
(
100
)));
return
new
DnsResourceDataAnything
(
random
.
NextDataSegment
(
random
.
Next
(
100
)));
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets/ByteArrayExtensions.cs
View file @
be380b07
...
@@ -7,6 +7,7 @@ using PcapDotNet.Base;
...
@@ -7,6 +7,7 @@ using PcapDotNet.Base;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Http
;
using
PcapDotNet.Packets.Http
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV6
;
namespace
PcapDotNet.Packets
namespace
PcapDotNet.Packets
{
{
...
@@ -316,6 +317,22 @@ namespace PcapDotNet.Packets
...
@@ -316,6 +317,22 @@ namespace PcapDotNet.Packets
offset
+=
UInt48
.
SizeOf
;
offset
+=
UInt48
.
SizeOf
;
return
result
;
return
result
;
}
}
/// <summary>
/// Reads 16 bytes from a specific offset as a UInt128 with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public
static
UInt128
ReadUInt128
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
UInt128
value
=
ReadUInt128
(
buffer
,
offset
);
if
(
IsWrongEndianity
(
endianity
))
value
=
HostToNetworkOrder
(
value
);
return
value
;
}
/*
/*
/// <summary>
/// <summary>
/// Reads 8 bytes from a specific offset as an int with a given endianity.
/// Reads 8 bytes from a specific offset as an int with a given endianity.
...
@@ -418,6 +435,18 @@ namespace PcapDotNet.Packets
...
@@ -418,6 +435,18 @@ namespace PcapDotNet.Packets
return
new
IpV4TimeOfDay
(
buffer
.
ReadUInt
(
ref
offset
,
endianity
));
return
new
IpV4TimeOfDay
(
buffer
.
ReadUInt
(
ref
offset
,
endianity
));
}
}
/// <summary>
/// Reads 16 bytes from a specific offset as an IPv6 address with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
public
static
IpV6Address
ReadIpV6Address
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
return
new
IpV6Address
(
buffer
.
ReadUInt128
(
offset
,
endianity
));
}
/// <summary>
/// <summary>
/// Writes the given value to the buffer.
/// Writes the given value to the buffer.
/// </summary>
/// </summary>
...
@@ -606,6 +635,20 @@ namespace PcapDotNet.Packets
...
@@ -606,6 +635,20 @@ namespace PcapDotNet.Packets
offset
+=
UInt48
.
SizeOf
;
offset
+=
UInt48
.
SizeOf
;
}
}
/// <summary>
/// Writes the given value to the buffer using the given endianity.
/// </summary>
/// <param name="buffer">The buffer to write the value to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
/// <param name="value">The value to write.</param>
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
UInt128
value
,
Endianity
endianity
)
{
if
(
IsWrongEndianity
(
endianity
))
value
=
HostToNetworkOrder
(
value
);
Write
(
buffer
,
offset
,
value
);
}
/// <summary>
/// <summary>
/// Writes a string to a byte array in a specific offset using the given encoding.
/// Writes a string to a byte array in a specific offset using the given encoding.
/// Increments the offset by the number of bytes written.
/// Increments the offset by the number of bytes written.
...
@@ -723,6 +766,18 @@ namespace PcapDotNet.Packets
...
@@ -723,6 +766,18 @@ namespace PcapDotNet.Packets
buffer
.
Write
(
ref
offset
,
value
.
MillisecondsSinceMidnightUniversalTime
,
endianity
);
buffer
.
Write
(
ref
offset
,
value
.
MillisecondsSinceMidnightUniversalTime
,
endianity
);
}
}
/// <summary>
/// Writes the given value to the buffer using the given endianity.
/// </summary>
/// <param name="buffer">The buffer to write the value to.</param>
/// <param name="offset">The offset in the buffer to start writing.</param>
/// <param name="value">The value to write.</param>
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
IpV6Address
value
,
Endianity
endianity
)
{
buffer
.
Write
(
offset
,
value
.
ToValue
(),
endianity
);
}
// public static void WriteCarriageReturnLinefeed(this byte[] buffer, int offset)
// public static void WriteCarriageReturnLinefeed(this byte[] buffer, int offset)
// {
// {
// buffer.Write(ref offset, AsciiBytes.CarriageReturn);
// buffer.Write(ref offset, AsciiBytes.CarriageReturn);
...
@@ -801,6 +856,25 @@ namespace PcapDotNet.Packets
...
@@ -801,6 +856,25 @@ namespace PcapDotNet.Packets
return
result
;
return
result
;
}
}
private
static
UInt128
HostToNetworkOrder
(
UInt128
value
)
{
UInt128
result
;
unsafe
{
UInt128
*
resultPtr
=
&
result
;
byte
*
resultBytePtr
=
(
byte
*)
resultPtr
;
UInt128
*
valuePtr
=
&
value
;
byte
*
valueBytePtr
=
(
byte
*)
valuePtr
;
for
(
int
i
=
0
;
i
!=
UInt128
.
SizeOf
;
++
i
)
resultBytePtr
[
i
]
=
valueBytePtr
[
UInt128
.
SizeOf
-
i
-
1
];
}
return
result
;
}
private
static
short
ReadShort
(
byte
[]
buffer
,
int
offset
)
private
static
short
ReadShort
(
byte
[]
buffer
,
int
offset
)
{
{
unsafe
unsafe
...
@@ -845,16 +919,16 @@ namespace PcapDotNet.Packets
...
@@ -845,16 +919,16 @@ namespace PcapDotNet.Packets
}
}
}
}
// private static long ReadLong
(byte[] buffer, int offset)
private
static
UInt128
ReadUInt128
(
byte
[]
buffer
,
int
offset
)
//
{
{
//
unsafe
unsafe
//
{
{
//
fixed (byte* ptr = &buffer[offset])
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
//
{
{
// return *((long
*)ptr);
return
*((
UInt128
*)
ptr
);
//
}
}
//
}
}
//
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
short
value
)
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
short
value
)
{
{
...
@@ -899,5 +973,16 @@ namespace PcapDotNet.Packets
...
@@ -899,5 +973,16 @@ namespace PcapDotNet.Packets
}
}
}
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
UInt128
value
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
*((
UInt128
*)
ptr
)
=
value
;
}
}
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/DataSegment.cs
View file @
be380b07
...
@@ -6,6 +6,7 @@ using System.Text;
...
@@ -6,6 +6,7 @@ using System.Text;
using
PcapDotNet.Base
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV6
;
namespace
PcapDotNet.Packets
namespace
PcapDotNet.Packets
{
{
...
@@ -262,6 +263,17 @@ namespace PcapDotNet.Packets
...
@@ -262,6 +263,17 @@ namespace PcapDotNet.Packets
return
Buffer
.
ReadIpV4TimeOfDay
(
StartOffset
+
offset
,
endianity
);
return
Buffer
.
ReadIpV4TimeOfDay
(
StartOffset
+
offset
,
endianity
);
}
}
/// <summary>
/// Reads 4 bytes from a specific offset in the segment as an IpV4Address with a given endianity.
/// </summary>
/// <param name="offset">The offset in the segment to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns>
internal
IpV6Address
ReadIpV6Address
(
int
offset
,
Endianity
endianity
)
{
return
Buffer
.
ReadIpV6Address
(
StartOffset
+
offset
,
endianity
);
}
/// <summary>
/// <summary>
/// Converts the given 16 bits sum to a checksum.
/// Converts the given 16 bits sum to a checksum.
/// Sums the two 16 bits in the 32 bits value and if the result is bigger than a 16 bits value repeat.
/// Sums the two 16 bits in the 32 bits value and if the result is bigger than a 16 bits value repeat.
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsResourceData.cs
View file @
be380b07
...
@@ -6,6 +6,7 @@ using System.Reflection;
...
@@ -6,6 +6,7 @@ using System.Reflection;
using
System.Text
;
using
System.Text
;
using
PcapDotNet.Base
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV6
;
namespace
PcapDotNet.Packets.Dns
namespace
PcapDotNet.Packets.Dns
{
{
...
@@ -2035,4 +2036,56 @@ namespace PcapDotNet.Packets.Dns
...
@@ -2035,4 +2036,56 @@ namespace PcapDotNet.Packets.Dns
return
new
DnsResourceDataGeographicalPosition
(
longtitude
,
latitude
,
altitude
);
return
new
DnsResourceDataGeographicalPosition
(
longtitude
,
latitude
,
altitude
);
}
}
}
}
/// <summary>
/// <pre>
/// +-----+-------+
/// | bit | 0-127 |
/// +-----+-------+
/// | 0 | IP |
/// +-----+-------+
/// </pre>
/// </summary>
[
DnsTypeRegistration
(
Type
=
DnsType
.
Aaaa
)]
public
sealed
class
DnsResourceDataIpV6
:
DnsResourceDataSimple
,
IEquatable
<
DnsResourceDataIpV6
>
{
public
DnsResourceDataIpV6
()
:
this
(
IpV6Address
.
Zero
)
{
}
public
DnsResourceDataIpV6
(
IpV6Address
data
)
{
Data
=
data
;
}
public
IpV6Address
Data
{
get
;
private
set
;
}
public
bool
Equals
(
DnsResourceDataIpV6
other
)
{
return
other
!=
null
&&
Data
.
Equals
(
other
.
Data
);
}
public
override
bool
Equals
(
DnsResourceData
other
)
{
return
Equals
(
other
as
DnsResourceDataIpV6
);
}
internal
override
int
GetLength
()
{
return
IpV6Address
.
SizeOf
;
}
internal
override
void
WriteDataSimple
(
byte
[]
buffer
,
int
offset
)
{
buffer
.
Write
(
offset
,
Data
,
Endianity
.
Big
);
}
internal
override
DnsResourceData
CreateInstance
(
DataSegment
data
)
{
if
(
data
.
Length
!=
IpV6Address
.
SizeOf
)
return
null
;
return
new
DnsResourceDataIpV6
(
data
.
ReadIpV6Address
(
0
,
Endianity
.
Big
));
}
}
}
}
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