Home > other >  C + + network caught output is garbled
C + + network caught output is garbled

Time:09-30

Recently in developing a project network caught after data statistics, mainly according to the analysis of the market, from the payload data link layer, is the hexadecimal unsigned char types, the output of basic it is garbled,

Can you give some opinion?
Below is the output TCP frame the data inside the
Void PrintData (unsigned char * data, int Size)
{
Int I, j;
For (I=0; i {
If (I.=0 & amp; & 16 I %==0)//if one line of hex printing is complete...
{
Fprintf (logfile, "");
For (j=I - 16; j{
If (data [j] & gt;=32 & amp; & Data [j]
=128)Fprintf (logfile, "% c", (unsigned char) data [j]);//if its a number or alphabet

The else fprintf (logfile, ". ");//otherwise print a dot
}
Fprintf (logfile, "\ n");
}

If (I % 16==0) fprintf (logfile, "");
Fprintf (logfile, "% 02 x", (unsigned int) data [I]);

If (I==the Size - 1)//print the last Spaces
{
for(j=0; j<15 - I % 16; J++)
{
Fprintf (logfile, "");//extra Spaces
}

Fprintf (logfile, "");

For (j=I - I % 16; j<=I; J++)
{
If (data [j] & gt;=32 & amp; & Data [j]
=128){
Fprintf (logfile, "% c", (unsigned char) data [j]);
}
The else
{
Fprintf (logfile, ". ");
}
}

Fprintf (logfile, "\ n");
}
}
}
  • Related