Skip to content

Commit

Permalink
Fix encoding/decoding options 43 and 82
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Oct 20, 2023
1 parent 0c5e967 commit 782508f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions dhcptest.d
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ struct VLList(Type)
if (type != Type.raw)
{
result ~= type.to!ubyte;
result ~= (2 + value.representation.length).to!ubyte;
result ~= value.representation.length.to!ubyte;
}
result ~= value.representation;
return result;
Expand All @@ -514,10 +514,10 @@ struct VLList(Type)
while (bytes.length >= 2)
{
auto len = bytes[1];
if (len < 2 || len > bytes.length)
if (2 + len > bytes.length)
break;
suboptions ~= inout Suboption(cast(Type)bytes[0], cast(inout(char)[])bytes[2..len]);
bytes = bytes[len..$];
suboptions ~= inout Suboption(cast(Type)bytes[0], cast(inout(char)[])bytes[2 .. 2 + len]);
bytes = bytes[2 + len .. $];
}
if (bytes.length)
suboptions ~= inout Suboption(Type.raw, cast(inout(char)[]) bytes);
Expand Down Expand Up @@ -579,19 +579,19 @@ unittest
`raw="\0"`
);
test(
[0x01, 0x05, 'f', 'o', 'o'],
[0x01, 0x03, 'f', 'o', 'o'],
`agentCircuitID="foo"`
);
test(
[0x01, 0x05, 'f', 'o', 'o', 0x42],
[0x01, 0x03, 'f', 'o', 'o', 0x42],
`agentCircuitID="foo", raw="B"`
);
test(
[0x01, 0x05, 'f', 'o', 'o', 0x02, 0x05, 'b', 'a', 'r'],
[0x01, 0x03, 'f', 'o', 'o', 0x02, 0x03, 'b', 'a', 'r'],
`agentCircuitID="foo", agentRemoteID="bar"`
);
test(
[0x03, 0x05, 'f', 'o', 'o'],
[0x03, 0x03, 'f', 'o', 'o'],
`3="foo"`
);
}
Expand Down Expand Up @@ -1007,7 +1007,7 @@ void sendPacket(Socket socket, Address addr, string targetIP, ubyte[] mac, DHCPP
}

auto sent = socket.sendTo(data, addr);
enforce(sent > 0, "sendto error");
errnoEnforce(sent > 0, "sendto error");
enforce(sent == data.length, "Sent only %d/%d bytes".format(sent, data.length));
}

Expand Down

0 comments on commit 782508f

Please sign in to comment.