有时打印垃圾 [英] Printing Garbage Sometimes

查看:58
本文介绍了有时打印垃圾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用嗅探器.当我使用printf进行控制台时,在屏幕上没有任何垃圾;当我将其打印到日志文件时,有时会得到垃圾,并且它似乎是长度至少为9个字符的序列号.这就是打印到我的文本文件的内容.

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.

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



printf后跟(log)文本文件...
printf("\ n序列号:%lu \ n",ntohl(tcp_header-> seq_number));
myfile<< "\ n序列号:"<< ntohl(tcp_header-> seq_number);



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);

推荐答案

ȈéÛ¸ ^ | P?úð9—
ȈéÛ¸^|Púð9—



printf后跟(log)文本文件...
printf("\ n序列号:%lu \ n",ntohl(tcp_header-> seq_number));
myfile<< "\ n序列号:"<< ntohl(tcp_header-> seq_number);



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);


最可能的原因是控制台将用空格(或null)替换非常规字符.但是对于文本文件,它将尝试将其呈现为Unicode文本.因此,您的问题不是不是它没有显示在控制台上,而是您可能没有正确解释数据.否则它可能是安全的连接,因此数据将几乎没有意义(并因此变得像垃圾一样).
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).


检查您的输出语句.两者都打印一个字符串(序列号"),一个无符号的长整数(定义为返回ulong的ntohl())和换行符("\ n"),仅此而已.您将以两行截然不同的行显示我们的输出,即上述序列的输出和一些垃圾.显然,您显示的语句不会产生垃圾输出,而其他一些语句则会产生垃圾输出.您没有显示所有相关信息,所以没有任何人可以帮助您.

现在,您已将"\ n"添加到myfile<<声明,您只是在模仿printf中的内容.但是,该简单添加不能解释为什么文件中存在垃圾.添加换行"只会给您换行.文件中多余的输出来自某个地方.
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.


这篇关于有时打印垃圾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆