G
gustavo.samour
Hi,
I am writing a very basic raw ethernet sniffer based on what I found
in Andreas Schaufler's raw ethernet article:
http://aschauf.landshut.org/fh/linux/udp_vs_raw/ch01s03.html
I'm trying to print the output of each ethernet frame in both
hexadecimal and character representations. I'm new at network
programming in C. Here's a code snippet:
while(1)
{
length = recvfrom(s, buffer, ETH_FRAME_LEN, 0, NULL, NULL);
if (length == -1) {
printf("Error receiving ethernet frame...\n");
}
else {
printf("Hex:\n\n");
for (int i = 0; i < length; i++)
{
printf("%x" buffer);
}
printf("\n\nChar:\n\n");
for (int i = 0; i < length; i++)
{
printf("%c" buffer);
}
}
}
Most of the characters I get are shown in two digit hexadecimal
representation like this "A0". But sometimes I get something like
"FFFFFFFF" or "FFFFFFA0". Why does this happen? I also compared the
results of using the Linux wireshark sniffer and my program, and
noticed different hexadecimal values for the frames. I know wireshark
is correct, so what am I doing wrong? Any help is appreciated.
Note: I posted this in alt.comp.lang.c before and someone named
"mimus" said the "FFFFFFFF" behavior could be a signed/unsigned
problem. How can I tell?
I am writing a very basic raw ethernet sniffer based on what I found
in Andreas Schaufler's raw ethernet article:
http://aschauf.landshut.org/fh/linux/udp_vs_raw/ch01s03.html
I'm trying to print the output of each ethernet frame in both
hexadecimal and character representations. I'm new at network
programming in C. Here's a code snippet:
while(1)
{
length = recvfrom(s, buffer, ETH_FRAME_LEN, 0, NULL, NULL);
if (length == -1) {
printf("Error receiving ethernet frame...\n");
}
else {
printf("Hex:\n\n");
for (int i = 0; i < length; i++)
{
printf("%x" buffer);
}
printf("\n\nChar:\n\n");
for (int i = 0; i < length; i++)
{
printf("%c" buffer);
}
}
}
Most of the characters I get are shown in two digit hexadecimal
representation like this "A0". But sometimes I get something like
"FFFFFFFF" or "FFFFFFA0". Why does this happen? I also compared the
results of using the Linux wireshark sniffer and my program, and
noticed different hexadecimal values for the frames. I know wireshark
is correct, so what am I doing wrong? Any help is appreciated.
Note: I posted this in alt.comp.lang.c before and someone named
"mimus" said the "FFFFFFFF" behavior could be a signed/unsigned
problem. How can I tell?