609 |
return q; |
return q; |
610 |
} |
} |
611 |
/*-----------------------------------------------------------------------------------*/ |
/*-----------------------------------------------------------------------------------*/ |
612 |
|
|
613 |
|
|
614 |
|
struct pbuf * |
615 |
|
pbuf_unref(struct pbuf *f) |
616 |
|
{ |
617 |
|
struct pbuf *p, *q; |
618 |
|
DEBUGF(PBUF_DEBUG, ("pbuf_unref: %p \n", f)); |
619 |
|
/* first pbuf is of type PBUF_REF? */ |
620 |
|
if (f->flags == PBUF_FLAG_REF) |
621 |
|
{ |
622 |
|
/* allocate a pbuf (w/ payload) fully in RAM */ |
623 |
|
p = pbuf_alloc(PBUF_RAW, f->len, PBUF_RAM); |
624 |
|
if (p != 0) |
625 |
|
{ |
626 |
|
int i; |
627 |
|
unsigned char *src, *dst; |
628 |
|
/* copy pbuf struct */ |
629 |
|
p->next = f->next; |
630 |
|
src = f->payload; |
631 |
|
dst = p->payload; |
632 |
|
i = 0; |
633 |
|
/* copy payload to RAM pbuf */ |
634 |
|
while(i < p->len) |
635 |
|
{ |
636 |
|
*dst = *src; |
637 |
|
dst++; |
638 |
|
src++; |
639 |
|
} |
640 |
|
f->next = NULL; |
641 |
|
/* de-allocate PBUF_REF */ |
642 |
|
pbuf_free(f); |
643 |
|
f = p; |
644 |
|
DEBUGF(PBUF_DEBUG, ("pbuf_unref: succesful %p \n", f)); |
645 |
|
} |
646 |
|
else |
647 |
|
{ |
648 |
|
/* deallocate chain */ |
649 |
|
pbuf_free(f); |
650 |
|
f = NULL; |
651 |
|
DEBUGF(PBUF_DEBUG, ("pbuf_unref: failed\n", f)); |
652 |
|
return NULL; |
653 |
|
} |
654 |
|
} |
655 |
|
/* p = previous pbuf == first pbuf */ |
656 |
|
p = f; |
657 |
|
/* q = current pbuf */ |
658 |
|
q = f->next; |
659 |
|
while (q != NULL) |
660 |
|
{ |
661 |
|
q = q->next; |
662 |
|
} |
663 |
|
return f; |
664 |
|
} |