Date: Fri, 20 May 2005 20:16:25 -0700 (PDT) From: Daniel Valencia <fetrovsky@yahoo.com> To: freebsd-net@freebsd.org Subject: Re: sending MAC packets --- again, and again Message-ID: <20050521031625.77340.qmail@web53907.mail.yahoo.com> In-Reply-To: 6667
next in thread | raw e-mail | index | archive | help
Hello all,
I know this may sound funny, but I'm still wrestling
with libpcap because I send packets and I cannot read
them. I tried also some example code of a toy sniffer
from a tutorial to pcap, and it behaves just like my
code. As my code is pretty compact, I'm posting it
here.
I'm sending from another machine (i'm using a hub this
time) an Ethernet message with the payload " la lara
la la la la " using broadcast to/from addresses.
tcpdump in the sniffing machine tells me that the
message is in the wire, but my sniffer just stalls and
eventually will report a totally unrelated message.
Same thing happens with the other pcap example I
borrowed. Sending machine is 4.11-RELEASE, listening
machine is 5.4-RELEASE.
Any help will be grately appreciated!
Thanks
- Daniel
#include <iostream>
#include <pcap.h>
void printhexdigit( int val, int pos )
{
int dig = (val & (0xf << pos)) >> pos;
std::cout << (dig>9)? 'a'+dig-0xa: '0'+dig;
}
int main()
{
pcap_t *handle;
pcap_pkthdr header;
char errbuf[PCAP_ERRBUF_SIZE];
errbuf[0] = 0;
handle = pcap_open_live( "xl0", BUFSIZ, 1, 0,
errbuf );
if( errbuf[0] )
std::cout << errbuf << std::endl;
const u_char *q = pcap_next( handle, &header
);
std::cout << "sniffed a packet of length " <<
header.len << std::endl;
for( int i = 0; i < header.len; i++ )
{
std::cout << ((i % 0x10)? ((i % 8)? "
": " - "): "\n");
printhexdigit( q[i], 1 );
printhexdigit( q[i], 0 );
}
std::cout << std::endl;
return 0;
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050521031625.77340.qmail>
