ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi Guys,
I'm writing some code for calculation of the checksum using the normal TCP checksum calculation algorithm in a T/TCP header .I've got two quetions here :-
1.Do all the fields need to be converted into Networkbyteorder or can I directly covert all of them into Hexadecimal format because thats what I would use later on in the program?
2.How do I handle the data part of it?for example if my data is just a simple string "Hello world " in the data part of the T/TCP header and I need to convert that into hex before I can calculate the checksum how exactly do I go about doing it?
Note: Theres very little difference btw the T/TCP header and the TCP header ; just a couple of extra fields in the options part.
I'm using Redhat 9.0 and compiling using gcc and writing code in C++.Any suggestions are greatly appreciated .
Thanks
Arvind.
Originally posted by live_dont_exist 1.Do all the fields need to be converted into Networkbyteorder or can I directly covert all of them into Hexadecimal format because thats what I would use later on in the program?
Use network byte order. Hexadecimal is just for presentation, right? You don't change the values?
Quote:
2.How do I handle the data part of it?for example if my data is just a simple string "Hello world " in the data part of the T/TCP header and I need to convert that into hex before I can calculate the checksum how exactly do I go about doing it?
It's just data. No conversion. I'm wondering what you mean by hex conversion here.
Hi ,
Thanks a lot for replying . What I meant by converting data into hex was something like this :-
I have my TCP header :-
So I go tcp->source = 8080; tcp->dest=1000 etc etc etc...
So to calculate the checksum I convert everything into Hex and add it and take a 1's complement of the end result and then store it in the header . During this process I come across the data as well . So after 20 bytes of my TCP header I have data which I have to convert into Hex so I can add it to the other hex entries and get a final result .Its something like this :-
So now I add 1F90 + 3E8 + some hex(data) and get a result...in 32 bit hex ..I take a 1's complement over here and store the result in the checksum field and then send the packet out .So the question here is ; how do I manipulate the data ; how do I know what to add?...because in the header I know the values ; I dont know about data ...hope this clarifies matters.I can write a decimal to hex function for all the integers in TCP header but what about data.
Thanks
Arvind
yeah ... i guess you do need to include data if it is a TCP header checksum...if it had been an IP header checksum I was doing I wouldn't need to include it.
thnx
Arvind
thnx mate...but already looked at that page...thnx again though...do let me know if you think of something . Was just discussing this with a colleague and she says you got to convert it into ASCII and then into binary and then into hex . This sounds okay but is there a shorter way to do it. because this seems to be an awfully long route to take.
thnx
Arvind
You don't have to convert to ascii->hex->binary... That's preposterous. I recommend you do take a closer look at the link alred posted earlier. The calculation of the checksum is right there. Remember that the tcp protocol do not differentiate between integers, characters, floats, doubles or so... they are all bytes...
hi,
so what you are saying here is that I really dont need to be concerned about whether it an int or char or binary ; I can just go ahead and add .So for eg if I hardcode tcp->source=8080 and write tcp->dest=1000 ; I can just go ahead and say tcp->source & tcp->dest without being too concerned about the types ; the final result will automatically be okay..is my understanding correct?
thnx
Arvind
You have to take into account the size of the members of the structure... tcp->source and tcp->dest are already 16bit, so you can safely add these two together.. Take a look at this page which describes the TCP checksumming: http://www.ietf.org/rfc/rfc1071.txt
Hi,
I've managed to write code where I've initialized all the headers and managed to convert the first 2 values into Hex but how do I add them in Hex? Heres what I'm talking about:-
First of all, the string "123456789ABCDEF" (assuming this is ascii), will not be sent as 01 02 03 04 05 and so on... but according to its value in the ascii table: 31 32 33 34 35 and so on... Therefore, converting the values into the string representation, will not yield the result you are expecting.
For example your buffer looks like this "in the machine":
"1f90" --> 31 66 39 30
Lady colleague, female student, you say potato, i say poteter. Sorry mate, but this still looks like someones homework assignment. Think about it... it looks like a typical exercise in network programming. "Write an application thats fills out a tcp header structure and prints it on screen." No offence intended to OT.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.