Skip to content

Commit c1550dd

Browse files
committed
DHCP_MAGIC_COOKIE int --> uint
sizeof instead of constant value
1 parent ae3f79c commit c1550dd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

PcapDotNet/src/PcapDotNet.Packets/Dhcp/DhcpDatagram.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private static class Offset
7070
public const int OptionsWithMagicCookie = 240;
7171
}
7272

73-
internal const int DHCP_MAGIC_COOKIE = 0x63825363;
73+
internal const uint DHCP_MAGIC_COOKIE = 0x63825363;
7474

7575
/// <summary>
7676
/// RFC 2131.
@@ -223,9 +223,9 @@ public bool IsDhcp
223223
{
224224
get
225225
{
226-
if (Length >= Offset.Options + 4)
226+
if (Length >= Offset.Options + sizeof(uint))
227227
{
228-
return ReadInt(Offset.Options, Endianity.Big) == DHCP_MAGIC_COOKIE;
228+
return ReadUInt(Offset.Options, Endianity.Big) == DHCP_MAGIC_COOKIE;
229229
}
230230
else
231231
{
@@ -284,7 +284,7 @@ internal static int GetLength(bool isDhcp, IList<DhcpOption> options)
284284

285285
if (options != null)
286286
{
287-
length += options.Sum(p => 1 + (!(p is DhcpPadOption || p is DhcpEndOption) ? 1 : 0) + p.Length); //Type + Len? + Option
287+
length += options.Sum(option => sizeof(byte) + (!(option.OptionCode == DhcpOptionCode.Pad || option.OptionCode == DhcpOptionCode.End) ? sizeof(byte) : 0) + option.Length); // Type + Len? + Option
288288
}
289289

290290
return length;

0 commit comments

Comments
 (0)