Re: sending MAC packets --- again, and again

From: Daniel Valencia (fetrovsky_at_yahoo.com)
Date: 05/21/05

  • Next message: Darren Pilgrim: "RE: iwi(4) not working"
    Date: Fri, 20 May 2005 20:16:25 -0700 (PDT)
    To: freebsd-net@freebsd.org
    
    

    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
    _______________________________________________
    freebsd-net@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-net
    To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"


  • Next message: Darren Pilgrim: "RE: iwi(4) not working"

    Relevant Pages


  • Quantcast