Calculate an Internet (aka IP, aka RFC791) checksum in C# -
Interestingly, I can get the implementation of internet checksum in almost every language except C #. Does anyone have an implementation to share?
Remember, this specifies that:
"The checksum field is complementary to the complementary amount of 16-bit words all 16-bit. For checksum computing purposes, checksum The value of the field is zero. "
More clarification can be found.
Something is available, but it's not really one big worry for me at this point.
Please include your tests! (Edit: Valid comments about checking someone else's code - but I am going out of the protocol and I do not have any test vectors nor unit tests to see if it is currently being used Yes, it matches!! -)
EDIT: Here are some unit tests with whom I came in. They test an extension method that repeats through the entire byte collection. If you get a test error, please comment.
[TestMethod ()] Public Zero InternetChecksum_SimplestValidValue_ShouldMatch () {IEnumerable & lt; Byte & gt; Value = new byte [1]; // should work for any length array = 0xFFFF; Actual real value = internet check (); Extraordinary (Expected, real); } [Test Smith ()] Public Zero InternetChecksum_ValidSingleByteExtreme_ShouldMatch () {IEnumerable & lt; Byte & gt; Value = new byte [] {0xFF}; Ushort Hope = 0xFF; Actual real value = internet check (); Extraordinary (Expected, real); } [Test Smith ()] Public Zero InternetChecksum_ValidMultiByteExtrema_ShouldMatch () {IEnumerable & lt; Byte & gt; Value = new byte [] {0x00, 0xFF}; Ushort Expectancy = 0xFF00; Actual real value = internet check (); Extraordinary (Expected, real); }
I knew that I was collecting it from anywhere elsewhere. .
Comments
Post a Comment