K
Kifah Abbad
Hi guys,
i found a proggie, to convert packets captured (by libpcap) to hex
format...to pass them to dnet-application.
Now the proggie shows results as following:
4500003ca92e00002001c96a0a0a0a0b0a0a0a0a08007ca40100cfb76162636465666768696a6b6c6d6e6f7071727374757677616263646566676869
(please go to bottom for code)
While i need the result to look as follows:
\x45\x00\x00\x3c\xa9\x2e\x00\x00\x20\x01\xc9\x6a\x0a\x0a\x0a\x0b\x0a\x0a\x0a\x0a\x08\x00\x7c\xa4\x01\x00\xcf\xb7\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x61\x62\x63\x64\x65\x66\x67\x68\x69
I tried to manipulate the values, but it still showed the numbers as a
block of 4 (for example \x4500) instead of a block of 2 (for example
\x45\x00).
Here is the code of the proggie, maybe someone would help me align it
as i want to?
///////////////
void
print_hex(u_char *packet, u_short len)
{
int i, s_cnt;
u_short *p;
p = (u_short *)packet;
s_cnt = len / sizeof(u_short);
for (i = 0; --s_cnt >= 0; i++)
{
if ((!(i % 60)))
{
if (i != 0)
{
printf("\n");
}
}
printf("%04x", ntohs(*(p++)));
}
if (len & 1)
{
if ((!(i % 8)))
{
//printf("\n%02x\t", (i * 2));
}
printf("%02x ", *(u_char *)p);
}
printf("\n");
}
i found a proggie, to convert packets captured (by libpcap) to hex
format...to pass them to dnet-application.
Now the proggie shows results as following:
4500003ca92e00002001c96a0a0a0a0b0a0a0a0a08007ca40100cfb76162636465666768696a6b6c6d6e6f7071727374757677616263646566676869
(please go to bottom for code)
While i need the result to look as follows:
\x45\x00\x00\x3c\xa9\x2e\x00\x00\x20\x01\xc9\x6a\x0a\x0a\x0a\x0b\x0a\x0a\x0a\x0a\x08\x00\x7c\xa4\x01\x00\xcf\xb7\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x61\x62\x63\x64\x65\x66\x67\x68\x69
I tried to manipulate the values, but it still showed the numbers as a
block of 4 (for example \x4500) instead of a block of 2 (for example
\x45\x00).
Here is the code of the proggie, maybe someone would help me align it
as i want to?
///////////////
void
print_hex(u_char *packet, u_short len)
{
int i, s_cnt;
u_short *p;
p = (u_short *)packet;
s_cnt = len / sizeof(u_short);
for (i = 0; --s_cnt >= 0; i++)
{
if ((!(i % 60)))
{
if (i != 0)
{
printf("\n");
}
}
printf("%04x", ntohs(*(p++)));
}
if (len & 1)
{
if ((!(i % 8)))
{
//printf("\n%02x\t", (i * 2));
}
printf("%02x ", *(u_char *)p);
}
printf("\n");
}