Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a sniffer. When I use printf to console, I get no garbage on the screen, When I prin to my logfile I get garbage sometimes, and it seems to be on sequence numbers that are at least 9 characters in length. This is what is printing to my text file.

CSS
Sequence Number:  617122025
   »$ȈéÛ¸^|Púð9—


The printf followed by the (log) text file...
printf("\n Sequence Number : %lu\n", ntohl(tcp_header->seq_number));
myfile << "\n Sequence Number: "<< ntohl(tcp_header->seq_number);
Posted
Comments
Chuck O'Toole 31-Oct-11 13:35pm    
Examine your output statements. Both print a string ("sequence number") an unsigned long integer (ntohl() is defined to return ulong) and a newline ("\n") and that's all. You show us output with two distinct lines, the output from the above sequence and some junk. Clearly, the statements you show are not producing the junk output, some other statements are. You are not showing all the relevant information so there's nothing anybody can do to help you.
Member 7766180 31-Oct-11 13:38pm    
Right again Chuck. Here is the complete package...
printf("\n Sequence Number : %lu\n", ntohl(tcp_header->seq_number));
myfile << "\n Sequence Number: "<< ntohl(tcp_header->seq_number);
myfile << "\n ";

I just need the last line to be a spacer. Am I doing it wrong?
Member 7766180 31-Oct-11 13:44pm    
This works...
myfile << "\n Sequence Number: "<< ntohl(tcp_header->seq_number)<< "\n";
Member 7766180 31-Oct-11 13:50pm    
Chuck, Put this in a solution so that I may give you credit.

Most likely cause is that the console will just replace non-regular characters with space (or null). But with the text file, it tries to render it as Unicode text. So your problem is not that it is not showing up on the console, but rather you may not be interpreting the data correctly. Or it may be a secure connection and thus the data will be mostly meaningless (and thus garbage like).
 
Share this answer
 
v2
Comments
Member 7766180 31-Oct-11 13:34pm    
Thank you. I am using ANSI. So how can I fix this? I am not on a secure connection.
Nish Nishant 31-Oct-11 13:38pm    
It is possible that tcp_header->seq_number is returning an invalid value. And thus ntohl will return some random value too.
Member 7766180 31-Oct-11 13:41pm    
See above I forgot to include a line. The problem is that it doesn't always print garbage. Just sometimes. I just need a space.
Nish Nishant 31-Oct-11 13:43pm    
Yes but my point was that the u_long returned may be corresponding to some arbitrary Unicode character and thus the text file interprets it incorrectly as a character (when it is not).
Member 7766180 31-Oct-11 13:47pm    
Thank you. I understand what you are saying. How long are sequence numbers? I'm getting anywhere from 6 to 9 digits.
Examine your output statements. Both print a string ("sequence number") an unsigned long integer (ntohl() is defined to return ulong) and a newline ("\n") and that's all. You show us output with two distinct lines, the output from the above sequence and some junk. Clearly, the statements you show are not producing the junk output, some other statements are. You are not showing all the relevant information so there's nothing anybody can do to help you.

Now that you've added the "\n" to the myfile<< statement, you are just mimicing what's in the printf. However, that simple addition does not explain why you have garbage in the file. Adding "newline" just gives you, well, a new line. That extra output in the file comes from somewhere.
 
Share this answer
 
v2
Comments
Member 7766180 31-Oct-11 20:52pm    
Chuck, I have no idea where the garbage comes from. It seems to be working now. There are no other lines in sight!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900