diff options
Diffstat (limited to 'usr.sbin/ppp/mbuf.c')
-rw-r--r-- | usr.sbin/ppp/mbuf.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/usr.sbin/ppp/mbuf.c b/usr.sbin/ppp/mbuf.c index 2d1df62..5bd58dc 100644 --- a/usr.sbin/ppp/mbuf.c +++ b/usr.sbin/ppp/mbuf.c @@ -234,7 +234,8 @@ m_prepend(struct mbuf *bp, const void *ptr, size_t len, size_t extra) head = m_get(len + extra, bp ? bp->m_type : MB_UNKNOWN); head->m_offset = extra; head->m_len -= extra; - memcpy(MBUF_CTOP(head), ptr, len); + if (ptr) + memcpy(MBUF_CTOP(head), ptr, len); head->m_next = bp; return head; @@ -398,3 +399,19 @@ m_settype(struct mbuf *bp, int type) MemMap[type].octets += bp->m_size; } } + +struct mbuf * +m_append(struct mbuf *m, const void *v, size_t sz) +{ + if (m) { + while (m->m_next) + m = m->m_next; + if (m->m_size - m->m_len > sz) + m->m_len += sz; + else + m->m_next = m_prepend(NULL, v, sz, 0); + } else + m = m_prepend(NULL, v, sz, 0); + + return m; +} |