diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 6d66245c5bce..009b812b0bcf 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -714,13 +714,26 @@ m_print(const struct mbuf *m) int m_fixhdr(struct mbuf *m0) { - struct mbuf *m = m0; - int len = 0; + int len; - while (m) { - len += m->m_len; - m = m->m_next; - } + len = m_length(m0, NULL); m0->m_pkthdr.len = len; - return len; + return (len); +} + +int +m_length(struct mbuf *m0, struct mbuf **last) +{ + struct mbuf *m; + int len; + + len = 0; + for (m = m0; m != NULL; m = m->m_next) { + len += m->m_len; + if (m->m_next == NULL) + break; + } + if (last != NULL) + *last = m; + return (len); } diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index a791d356a804..b4bd624a29d9 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -489,6 +489,7 @@ struct mbuf *m_getcl(int, short, int); struct mbuf *m_gethdr(int, short); struct mbuf *m_gethdr_clrd(int, short); struct mbuf *m_getm(struct mbuf *, int, int, short); +int m_length(struct mbuf *m, struct mbuf **l); struct mbuf *m_prepend(struct mbuf *, int, int); void m_print(const struct mbuf *m); struct mbuf *m_pulldown(struct mbuf *, int, int, int *);