© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•6mo ago•
5 replies
Marcig

ssh c# implementation exaplanation of some shenanigans

i have a couple of questions regarding this code,
the first one being it reads 8 bytes from the socket, which contains the packet_length (4 bytes) and the padding_length (1 byte)

why then is required to calculate

the bytes to read, if the packetLength itself is
the length of the packet in bytes, not including 'mac' or the 'packet_length' field itself.
the length of the packet in bytes, not including 'mac' or the 'packet_length' field itself.
, so, if that is the case why is it necessary to remove the
blockSize + 4
blockSize + 4
, and even then, why is this necessary, the socket.Receive() shouldn't offset the stream from the last position it was when it was read?

`
uint bytesToRead = packetLength - blockSize + 4;
uint bytesToRead = packetLength - blockSize + 4;


and also this, why is needed to substract one also, like if packetLength is 7 and the paddingLength is 2, the payload length should be 5, althought this variable remains unused til later i guess
uint payloadLength = packetLength - paddingLength - 1;
uint payloadLength = packetLength - paddingLength - 1;
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Parameter Shenanigans
C#CC# / help
3y ago
✅ Proper implementation of API
C#CC# / help
3y ago
❔ C# Design Pattern to Map to Implementation
C#CC# / help
3y ago
Practicing OOP in c#, is this logical implementation of an Interface?
C#CC# / help
2y ago