我需要帮助,我正在尝试使用memcpy在内核空间复制标头,但屏幕只是变黑,似乎不喜欢我的memcpy。请有人帮助我。

        remaining = ntohs(iphead->tot_len) - 20; //(remaining = total size of ip packet - size of meta header)
 while(remaining != 0) {
    currentHead = (struct iphdr *) pos; //save the first 'real' header
    if(currentHead == NULL)
        goto fail;
    nskb = dev_alloc_skb(ntohs(currentHead->tot_len) + MAC_LENGTH );
    if(nskb == NULL)
        goto fail; //We can't allocate that memory so we leave
    if(nskb->tail + MAC_LENGTH + ntohs(currentHead->tot_len) <= nskb->end){

        nskb->data = skb_put(nskb, (MAC_LENGTH + ntohs(currentHead->tot_len))); // allocated all the memory we need
        memcpy(nskb->data,(*skb)->mac_header, MAC_LENGTH); //Put the mac header in place
        nskb->mac_header = nskb->data; //Save the mac header location
        nskb->network_header = nskb->data + MAC_LENGTH; //Move the pointer to where the network header will be
        memcpy(nskb->network_header, pos, ntohs(currentHead->tot_len)); //save the ip + payload

        nskb->data = nskb->network_header;

最佳答案

pos是真的有效吗?哪个memcpy给您带来了问题?我假设这是Linux内核吗?

关于c - memcpy-memcpy之后内核崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6033912/

10-10 09:07