以下格式说明符在做什么? [英] What is the following format specifier doing?
本文介绍了以下格式说明符在做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
else
{
printf("\\%.3hho", *data);
}
我无法在网上或通过阅读 C 编程语言书籍找到有关如何破译它的信息.我在以下代码片段中看到了它.代码试图在 telnet 协议中执行密码嗅探.
I could not find information regarding on how to decipher it on the net or by reading the C programming language book. I saw it in the following code snippet. The code is trying to perform password sniffing in the telnet protocol.
if ((pktlen - sizeof(struct ipheader)) > dataoffset)
{
printf(" SrcIP: %s,", inet_ntoa(ip->iph_sourceip));
printf(" DstIP: %s,", inet_ntoa(ip->iph_destip));
printf(" Data: ");
u_char* data = (u_char*)tcp + dataoffset;
for (unsigned short s = 0; s < (ntohs(ip->iph_len) - (sizeof(struct ipheader) + dataoffset)); s++)
{
if (isprint(*data) != 0)
{
printf("%c", *data);
}
else
{
printf("\\%.3hho", *data);
}
data++;
}
printf("\n");
}
}
推荐答案
根据 CppReference:
转换说明符o
将无符号整数转换成八进制表示oooo,
Precision 指定出现的最小位数.<截断>
Precision specifies the minimum number of digits to appear. <truncated>
所以字符串 \\%.3hho
表示文字反斜杠(它被转义),加上格式说明符 %.3hho
:
So the string \\%.3hho
represents a literal backslash (it's escaped), plus the format specifier %.3hho
:
%...o
表示无符号整数的八进制表示.字母o
也表示此说明符的结尾hh
是 C99 规范,表示unsigned char
而不是unsigned int
,始终为单字节.3
表示精度为 3,所以至少 3 个八进制数字 (000 - 377)
%...o
indicates octal representation for unsigned integer. The lettero
also indicates the end of this specifierhh
is a C99 specification, indicatesunsigned char
instead ofunsigned int
, always a single byte.3
means the precision is 3, so at least 3 octal digits (000 - 377)
这篇关于以下格式说明符在做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文