gpt4 book ai didi

c# - 使用 libpcap 捕获 "MMM"DateTime 格式时出错

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:45:10 25 4
gpt4 key购买 nike

我用 C# 编写了一个数据包模拟器,它生成一些 UDP 数据包并将它们发送到给定的 IP 地址。模拟器生成数据包并将其成功发送到我的 UBUNTU 虚拟机,但目的地有问题。在C#程序中,数据格式定义为:

namespace PacketSimulator
{
static class Program
{
public static string DateFormat = "MMM dd HH:mm:ss";
.
.
}
}

数据包由:

发送
namespace PacketSimulator
{
class ConnectionInfo
{
public DateTime DATE_TIME;
public override string ToString()
{
return DATE_TIME.ToString(Program.DateFormat) + " " + "10.0.72.45 " + ....

}
}
}

但在 Linux 端,我可以捕获的内容与我发送的内容有点不同:

???? 26 18:17:10 10.0.72.45

在 C# 程序中,月份格式定义为“MMM”(三个字母的月份名称),但 Lipcap 捕获的是一个四个字母的文本,如 ????

我需要的是接收定义格式的数据包而不是四个?签名。

提前感谢您的任何建议。

最佳答案

MSDN:

The "MMM" custom format specifier represents the abbreviated name of the month. The localized abbreviated name of the month is retrieved from the DateTimeFormatInfo.AbbreviatedMonthNames property of the current or specified culture.

尝试传入 CultureInfo

return DATE_TIME.ToString(Program.DateFormat,CultureInfo.InvariantCulture) + " " + "10.0.72.45 " + ....

如果失败,则一定是 libpcap 出于某种原因无法访问 DateTimeFormatInfo.AbbreviatedMonthNames。

关于c# - 使用 libpcap 捕获 "MMM"DateTime 格式时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38036489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com