1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

memcpy

Discussion in 'C' started by kami1219, Nov 9, 2009.

  1. kami1219

    kami1219 New Member

    Joined:
    Jul 10, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    Code:
    struct Buffer
    {
      unsigned char pkt[4092];
    };
    
    struct Buffer *start;
    start=(struct Buffer *)malloc(sizeof(struct Buffer));
    
    unsigned char *pkt=(unsigned char *)malloc(4092*(sizeof(unsigned char)));
    memcpy(&start->pkt,&pkt,len); //Where 'len' is the length of a packet that is stored in 'pkt'.
    
    OUTPUT: Segmentation fault

    This code does not show error when compiled but gives error on running.
    I tried all in the following but it give same segmentation fault error every time.
    memcpy(&start->pkt,&pkt,len);
    memcpy(start->pkt,&pkt,len);
    memcpy(start->pkt,pkt,len);

    It's a bit long code but I only need help in memcpy so that I have pasted the relevant lines. I need to copy the data that is in this 'pkt' to the 'start->pkt' of length 'len'. Appreciate any suggestions or help.
     
    Last edited: Nov 9, 2009
  2. kami1219

    kami1219 New Member

    Joined:
    Jul 10, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    I did not understand it but when i use sizeof(pkt) instead of len, error does not come. What can be the reason. I want to copy data from 'pkt' to 'start->pkt' but of length len and sizeof(pkt) and len are not same.
     

Share This Page