#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0

    serializing memory contents in contiguous memory location


    I need some help from you regarding a particular problem.

    I am using libnet raw packet library (libnet_build_ethernet) for transferring data over the network. For this, I have to first convert all the data to u_char type and then serialize them to contiguous memory locations.

    Can anyone of you give me an idea how can I do that. I tried with
    something
    like following piece of code -

    ----------------------------------------------------------
    char *a;
    char *b;
    char *c;
    char *payload;

    struct test{
    int a;
    int b[2];
    int c;

    }test1;


    test1.a = 5;
    test1.b[0] = 6;
    test1.b[1]= 7;
    test1.c = 8;

    a = (char *)&test1.a;
    b = (char *)&test1.b;
    c = (char *)&test1.c;

    printf("%p %p %p\n", a, b, c);

    *payload = *a;
    *payload+1 = *b;
    *payload+3 = *c;

    //printf("%p %p %p %p\n", payload,a, b, c);
    ----------------------------------------------------------------

    but i come down with some problem like __dereferencing_frame_info (i dont
    know what does that mean, I am pretty new in this area.).

    Any help is greatly appreciated.

    Regards
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    i think part of the problem may be when you assign
    Code:
    b = (char *)&test1.b
    test1.b is an integer pointer, so when you pass it by reference i think you are actually getting the address of the pointer and not what it points to, yes? i think it should be
    Code:
    b = (char *)test1.b
    but i could be wrong.

    edit: i got this to compile:
    Code:
    #include <stdio.h>
    
    main()
    {
     char *a;
    char *b;
    char *c;
    char *payload;
    
    struct test{
    int a;
    int b[2];
    int c;
    
    }test1;
    
    
    test1.a = 5;
    test1.b[0] = 6;
    test1.b[1]= 7;
    test1.c = 8;
    
    a = (char *)&test1.a;
    b = (char *)test1.b;
    c = (char *)&test1.c;
    
    printf("%p %p %p\n", a, b, c);
    
    *payload = *a;
    *(payload + 1) = *b;
    *(payload + 3) = *c;
    }
    Last edited by infamous41md; August 1st, 2003 at 11:02 PM.
  4. #3
  5. Left due to despotic ad-min
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Posts
    1,044
    Rep Power
    13
    I agree with infamous .... the problem is being caused by your assignments.

    Usually "serialising" means something like "copy the data into a form that can then be sent over a socket or written to a file that can subsequently be read by another program". Implicit in that is defining a data format, that one program can write and another can read.

    My guess is that you need to write the data (eg with sprintf) into an array of char or unsigned char, in some format that another program can read when it receives it. Then pass that string to the library function that forward it on.

    To get more specifics on what your library is expecting, you will need to read it's documentation.
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    thanks for the definition grumpy, i wasnt exactly sure what that meant but i figured something along those lines. sockets and shellcode and whatnot is a royal pain to "serialize".
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0

    thanks for reply


    one of the possibilities I already have considered is sprintf. But it requires little more bandwidth, so I am trying for a more optimized solution. Anyway, I think I came to a solution. I defined a size for payload, and then the __dereferencing_frame_info error was gone.

    Thank you very much again.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    12
    Mehdi,

    You're still walking on thin ice with that approach. Unless you can guarantee the hardware platform at the other end of the connection (which you can't, even with the same operating system), binary data is a little risky. You have a couple of options.

    1. Use rpc. There is a slight learning curve, but there is a nice O'Reilly book on the subject. A couple of hours reading and you'll be off to the races. rpc will handle the serialization for you, and deal with different word orders at each end. It can take a day or two off of programming time.

    2. Serialize to text-only data. Yes, it eats bandwidth, but it's a lot easier to debug when something goes wrong. Since this is programming we're talking about, expect something to go wrong.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0
    Thanks for your suggestion Dowling. I really appreciate your advice. I will try to collect the book in the meantime.

    Regards

IMN logo majestic logo threadwatch logo seochat tools logo