Author: colin Date: 2009-12-29 03:34:47 +0100 (Tue, 29 Dec 2009) New Revision: 34794 Changeset: http://dev.haiku-os.org/changeset/34794/haiku Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c Log: Enhancing the freebsd compat layer in preparation of including crypto support for the wlan stack. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2009-12-29 00:41:08 UTC (rev 34793) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/mbuf.h 2009-12-29 02:34:47 UTC (rev 34794) @@ -156,6 +156,7 @@ void m_adj(struct mbuf*, int); void m_align(struct mbuf*, int); +int m_append(struct mbuf*, int, c_caddr_t); void m_cat(struct mbuf*, struct mbuf*); void m_clget(struct mbuf*, int); void* m_cljget(struct mbuf*, int, int); Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h 2009-12-29 00:41:08 UTC (rev 34793) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/types.h 2009-12-29 02:34:47 UTC (rev 34794) @@ -16,5 +16,6 @@ typedef int boolean_t; +typedef __const char* c_caddr_t; #endif Modified: haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c 2009-12-29 00:41:08 UTC (rev 34793) +++ haiku/trunk/src/libs/compat/freebsd_network/fbsd_mbuf.c 2009-12-29 02:34:47 UTC (rev 34794) @@ -500,6 +500,52 @@ } /* + * Append the specified data to the indicated mbuf chain, + * Extend the mbuf chain if the new data does not fit in + * existing space. + * + * Return 1 if able to complete the job; otherwise 0. + */ +int +m_append(struct mbuf *m0, int len, c_caddr_t cp) +{ + struct mbuf *m, *n; + int remainder, space; + + for (m = m0; m->m_next != NULL; m = m->m_next) + ; + remainder = len; + space = M_TRAILINGSPACE(m); + if (space > 0) { + /* + * Copy into available space. + */ + if (space > remainder) + space = remainder; + bcopy(cp, mtod(m, caddr_t) + m->m_len, space); + m->m_len += space; + cp += space, remainder -= space; + } + while (remainder > 0) { + /* + * Allocate a new mbuf; could check space + * and allocate a cluster instead. + */ + n = m_get(M_DONTWAIT, m->m_type); + if (n == NULL) + break; + n->m_len = min(MLEN, remainder); + bcopy(cp, mtod(n, caddr_t), n->m_len); + cp += n->m_len, remainder -= n->m_len; + m->m_next = n; + m = n; + } + if (m0->m_flags & M_PKTHDR) + m0->m_pkthdr.len += len - remainder; + return (remainder == 0); +} + +/* * Defragment an mbuf chain, returning at most maxfrags separate * mbufs+clusters. If this is not possible NULL is returned and * the original mbuf chain is left in it's present (potentially