m.r226 m.r226 - 5 months ago 9
Linux Question

Error in capturing "MMM" DateTime format with libpcap

I have programmed a packet simulator in C# that produces some UDP packets and sends them to a given IP address. The simulator produces and sends packets successfully to my UBUNTU virtual machine but there is a problem in destination. In C# program, data format defined as :

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


and packets Are sent by :

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

}
}
}


But at Linux side, what i can capture is a bit different with what i have sent:

???? 26 18:17:10 10.0.72.45


The Month format defined as "MMM" (three letters month name)in C# program but what Lipcap captures is a four letters text as ????

What i need is to receive packets in defined format not with four ? sign.

Thanks in advance for any advice.

Answer

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.

Try passing in CultureInfo

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

If that fails, then it must be that libpcap can not access DateTimeFormatInfo.AbbreviatedMonthNames for some reason.