Tcpv4 checksum written title
* the target:
* write a function to calculate contains ipv4 packet checksum of TCP packets, and return to include the correct checksum ipv4 packet
* required:
* only need to combine together to ipv4 and TCP checksum calculation, ipv4 fragments need not tube, do not need to handle other types of other combination of checksum of packets, such as: no need to worry about ipv6, no need to worry about the udp, icmp don't tube,
* incoming TCP ipv4 packet inside checksum could be right or wrong, the caller needs to return only one other content is the same, but the checksum correct TCP ipv4 packet
* function input is a with the length of the byte array, output is a function with the length of the byte array,
* optional features, check the correctness of the input packets,
* if the written test chose not to implement this feature, then the caller will ensure that the input binary meet ipv4 together with TCP binary array of effective packages, promise not to use ipv4 fragments could function,
* if those who choose to implement the written test functions, the caller may enter any binary content, the written test at this time people should put all the errors are printed to standard output, the program should not appear in the process of running out of memory, the subscript crossing the line and other unforeseen situation,
* use of programming languages can can meet the above requirements,
* need to write the function of automated unit testing, in order to prove the correctness of your function, automated unit test must be included at the back of the "input and output sample 1" a total of 1 example, automatic test of the input and output should be in your code, and the automatic judgment,
* this function should be done by your own independent, no part of this function is not allowed to copy other people's code,
* this function within a checksum calculation of each calculation steps, the checksum calculation itself does not allow direct call library implementation,
* function can modify the incoming byte array, also can not modify the incoming byte array,
* the function name as RecomputeChecksum,
* the readability of the code should have certain human ought to be able to easily find all the location of the actual code is executed, suggest to avoid using inheritance,
* the written test results check:
* all inspectors to run automated unit test, check whether you can compile and run the compiled as a result, the test results are in line with expectations, this step has written test failure problem,
* inspectors randomly changes an automated unit test of an input parameter, check the compiler after the operation, the results are running failure, this step has a problem the written test failure,
* inspectors to join a meeting demand and the written test example of don't know, check whether the results in line with expectations, if this part has a problem the written test fails,
* if the code doesn't compile run the written test failure,
* if automatic test run is not in conformity with the expected this written test failure,
* if automatic test does not contain the back of the input and output example 1 this written test failure,
* if automatic test input and output is not contained in the code of the written test failure,
* if did not meet the requirements of independent complete the written test failure,
* if not satisfied contain the implementation details of the requirements for each input bytes, the written test failure,
* if you cannot find called RecomputeChecksum function, the written test failure,
* if RecomputeChecksum function or type the number of input and output parameters don't meet the requirements, the written test failure,
* if the code readability is very bad, when reading the code is hard to understand the actual execution of the location of the code, the written test fails, the passed by inspectors to decide whether or not,
* artificial reading automated unit test code as well as the implementation code, check whether meet the goals and requirements,
* inside covering the details of the comprehensive automatic testing, the written test score there is a lot of points,
* check input packet is correct, any binary input can correct error handling, and the program will not be out of memory, the subscript cross-border unforeseen situations, such as the written test score there is a lot of points,
* code complexity is low, the code is easy to understand, written examination scores have a small amount of points,
* use golang language, written examination score plus a small amount of,
* code files use no bom encoding utf8, written test score points, a small amount of
* reference:
* ipv4 checksum https://tools.ietf.org/html/rfc1071
* TCP https://tools.ietf.org/html/rfc793
* TCP checksum https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_checksum_for_IPv4
* returned directly input function definition:
* go language version:
Func RecomputeChecksum (in byte []) (out byte []) {
Return in
}
* c language version:
Typedef struct Slice {
int len;
Unsigned char * data;
} Slice;
Slice RecomputeChecksum (Slice) in {
Slice the output={};
The output. Len=in. Len;
The output data=https://bbs.csdn.net/topics/in.data;
Return the output;
}
* c + + language and c language should be used fully consistent input/output interface, (on the input/output interface still use struct, don't use class)
* js language version: (passing the parameter types are Uint8Array type)
The function RecomputeChecksum (inPara) {
Var outBuffer=new Uint8Array (inPara. Length);
for (var i=0; i
}
Return outBuffer
}
* the input and output example:
* the input and output example 1 (behind using golang syntax) :
* input:
X45 byte [] {0, 0 x00 to 0 x00 to 0 x8c, 0 x28, 0 xd1, 0 x00 to 0 x00 to 0 XFF, 0 x06, 0 x00 to 0 x00 to 0 x73, 0 xef, 0 xd2, 0 x1b,
X15 0 xac, 0, 0 x00 to 0 x01, 0 x00 to 0 x50, 0 xe7, 0 xa3, 0 x93, 0 x2d, 0 xac, 0 XDB, 0 x9d, 0 x0e, 0 x0f, 0 x41,
X50 0, 0 x10, 0 XFF, 0 XFF, 0 x00 to 0 x00 to 0 x00 to 0 x00 to 0 x34, 0 x70, 0 x78, 0 x3b, 0 x70, 0 x61, x64, 0 0 x64,
X67 x69 0, 0 x6e, 0, 0, x2d x6c 0, 0 x65, 0 x66, 0 x74, 0 x3a, 0 x31, 0 x30, 0 x70, 0 x78, 0 x3b, 0 x70, 0 x61,
X69 x64 0, 0 x64, 0, 0, x6e x67 0, 0 x2d, 0 x72, 0 x69, 0 x67, 0 x68, 0 x74, 0 x3a, 0 x31, 0 x30, 0 x70, 0 x78,
X75 x3b 0, 0 x63, 0, 0 x72, 0 x73, 0 x6f, 0 x72, 0 x3a, x64, 0 0 x65, 0 x66, 0 x61, 0 x75, 0 x6c, 0 x74, 0 x3b,
X65 x6f 0, 0 x76, 0, 0 x72, 0 x66, 0 x6c, 0 x6f, 0 x77, 0 x3a, 0 x68, 0 x69, x64, 0 0 x64, 0 x65, 0 x6e, 0 x3b,
X69 x77 0, 0 x68, 0, 0 x74, 0 x65, 0 x2d, 0 x73, 0 x70, 0 x61, 0 x63, 0 x65, 0 x3a, 0 x6e, 0 x6f, 0 x77, 0 x72,
X70 0 x61, 0, 0 x7d, 0 x2e, 0 x63, 0 x2d, x64, 0 0 x72, 0 x6f, 0 x70, x64 0, 0 x6f,}
* output:
X45 byte [] {0, 0 x00 to 0 x00 to 0 x8c, 0 x28, 0 xd1, 0 x00 to 0 x00 to 0 XFF, 0 x06, 0 xa0, 0 x79, 0 x73, 0 xef, 0 xd2, 0 x1b,
X15 0 xac, 0, 0 x00 to 0 x01, 0 x00 to 0 x50, 0 xe7, 0 xa3, 0 x93, 0 x2d, 0 xac, 0 XDB, 0 x9d, 0 x0e, 0 x0f, 0 x41,
0 x50, 0 x10, 0 XFF, 0 XFF, 0 XFF, 0 xe6, 0 x00 to 0 x00 to 0 x34, 0 x70, 0 x78, 0 x3b, 0 x70, 0 x61, x64 0, 0 x64,
X67 x69 0, 0 x6e, 0, 0, x2d x6c 0, 0 x65, 0 x66, 0 x74, 0 x3a, 0 x31, 0 x30, 0 x70, 0 x78, 0 x3b, 0 x70, 0 x61,
X69 x64 0, 0 x64, 0, 0, x6e x67 0, 0 x2d, 0 x72, 0 x69, 0 x67, 0 x68, 0 x74, 0 x3a, 0 x31, 0 x30, 0 x70, 0 x78,
X75 x3b 0, 0 x63, 0, 0 x72, 0 x73, 0 x6f, 0 x72, 0 x3a, x64, 0 0 x65, 0 x66, 0 x61, 0 x75, 0 x6c, 0 x74, 0 x3b,
X65 x6f 0, 0 x76, 0, 0 x72, 0 x66, 0 x6c, 0 x6f, 0 x77, 0 x3a, 0 x68, 0 x69, x64, 0 0 x64, 0 x65, 0 x6e, 0 x3b,
X69 x77 0, 0 x68, 0, 0 x74, 0 x65, 0 x2d, 0 x73, 0 x70, 0 x61, 0 x63, 0 x65, 0 x3a, 0 x6e, 0 x6f, 0 x77, 0 x72,
X70 0 x61, 0, 0 x7d, 0 x2e, 0 x63, 0 x2d, x64, 0 0 x72, 0 x6f, 0 x70, x64 0, 0 x6f,}
` ` `