Doh, forgot to include code...

On Fri, Jan 16, 2009 at 3:53 PM, Aaron Turner <synfina...@gmail.com> wrote:
> Hi Joseph,
>
> Your diagnosis is correct, bus errors are non-aligned memory accesses
> on strictly aligned systems like SPARC.  I wasn't aware that 64bit
> solaris was 8 byte aligned... *sigh*.  I'll have to write an
> additional autoconf check and hack up some code for that.   Basically
> de-referencing pointers/memory which isn't 8 byte aligned is bad.
>
> Actually, I'm surprised the bug is on line 560, I would of expected it
> on 555 where I process the sender IP address in the first packet in
> test/test.pcap since that starts at byte offset 28 (28 / 8 = 3.5, but
> 28 / 4 = 7).   If the issue really is line 560, that's a failure of a
> 4 byte memory alignment (pointer at byte offset 38). Basically what
> I'm saying is I that maybe 64bit Solaris/SPARC is 4 byte aligned after
> all.
>
> I've attached a bit of code which tests offsets 0, 3, 7 and 9.
> Compile it and on your system, it should crash w/ a bus error at 3 if
> it's 8 byte aligned and at 9 if it is 4 byte aligned.  If it doesn't
> crash on SPARC, then my test sucks. :)
>
> Anyways, the trick is to use a temporary variable, memcpy the data
> over, do the editing, and then memcpy() it back into the packet
> buffer.  A good example of this is src/common/get.c:get_ipv4().
> You'll see the #ifdef FORCE_ALIGN crap which deals with it.
>
> Please let me know what you find out... fixing this 4 byte memory
> alignment issue isn't a big deal.  Making Tcpreplay 8 byte alignment
> safe is a *lot* more work.
>
> Re: err.h... whoops... yeah, bad integration of the fragroute code on
> my part.  You did the correct fix.
>
> Re: fakepcap... Not sure why you're having issues with fakepcap
> though.   Seems like you're having some linker issue- I'd guess you
> have multiple versions of libpcap installed on your system?  If not,
> then what version do you have?
>
> Let me know what you find out.
>
> Regards,
> Aaron
>
> --
> Aaron Turner
> http://synfin.net/
> http://tcpreplay.synfin.net/ - Pcap editing and replay tools for Unix & 
> Windows
> They that can give up essential liberty to obtain a little temporary
> safety deserve neither liberty nor safety.  -- Benjamin Franklin
>
/* Code to check for 4 vs. 8 byte memory alignment issues */

#include <stdlib.h>
#include <stdio.h>


int
main(int argc, char *argv[])
{
    unsigned char a[16];
    unsigned int i;

    for (i = 0; i < 16; i++)
        a[i] = i;

    printf("trying offset 0:");
    fflush(NULL);
    i = *(unsigned int *)&a[0];
    printf(" i = %08x\n", htonl(i));
    fflush(NULL);

    printf("trying offset 3:");
    fflush(NULL);
    i = *(unsigned int *)&a[3];
    printf(" i = %08x\n", htonl(i));
    fflush(NULL);

    printf("trying offset 7:");
    fflush(NULL);
    i = *(unsigned int *)&a[7];
    printf(" i = %08x\n", htonl(i));
    fflush(NULL);

    printf("trying offset 9:");
    fflush(NULL);
    i = *(unsigned int *)&a[9];
    printf(" i = %08x\n", htonl(i));
    fflush(NULL);

    exit(0);
}
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Tcpreplay-users mailing list
Tcpreplay-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcpreplay-users
Support Information: http://tcpreplay.synfin.net/trac/wiki/Support

Reply via email to