else
{
printf("\\%.3hho", *data);
}
我无法在网上或通过阅读 C 编程语言书籍找到有关如何破译它的信息。我在下面的代码片段中看到了它。该代码尝试在 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 :
Conversion specifier
o
converts a unsigned integer into octal representation oooo,
Precision specifies the minimum number of digits to appear. <truncated>
因此字符串 \\%.3hho
表示一个文字反斜杠(已转义),加上格式说明符 %.3hho
:
%...o
表示无符号整数的八进制表示。字母o
也表示此说明符的结尾hh
是 C99 规范,表示unsigned char
而不是unsigned int
,始终是单个字节.3
表示精度为 3,因此至少 3 个八进制数字 (000 - 377)
关于c - 下面的格式说明符在做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66020521/