FreeBSD/sys/netipsec/ipsec_mbuf.c
/*
 * m_pad(m, n) pads <m> with <n> bytes at the end. The packet header
 * length is updated, and a pointer to the first byte of the padding
 * (which is guaranteed to be all in one mbuf) is returned.
 */
m_pad(m, n) pads  with  bytes at the end. The packet header
length is updated, and a pointer to the first byte of the padding
(which is guaranteed to be all in one mbuf) is returned.
m_pad ( m n ) pads with bytes at the end . The packet header length is updated and a pointer to the first byte of the padding ( which is guaranteed to be all in one mbuf ) is returned .
caddr_t
m_pad(struct mbuf *m, int n)
{
	register struct mbuf *m0, *m1;
	register int len, pad;
	caddr_t retval;
	if (n <= 0) {  
		DPRINTF(("%s: pad length invalid (%d)\n", __func__, n));
		m_freem(m);
		return NULL;
	}
	len = m->m_pkthdr.len;
	pad = n;
	m0 = m;
	while (m0->m_len < len) {
		len -= m0->m_len;
		m0 = m0->m_next;
	}
	if (m0->m_len != len) {
		DPRINTF(("%s: length mismatch (should be %d instead of %d)\n",
			__func__, m->m_pkthdr.len,
			m->m_pkthdr.len + m0->m_len - len));
		m_freem(m);
		return NULL;
	}
	for (m1 = m0; m1->m_next; m1 = m1->m_next) {
		if (m1->m_next->m_len != 0) {
			DPRINTF(("%s: length mismatch (should be %d instead "
				"of %d)\n", __func__,
				m->m_pkthdr.len,
				m->m_pkthdr.len + m1->m_next->m_len));
			m_freem(m);
			return NULL;
		}
		m0 = m1->m_next;
	}
	if (pad > M_TRAILINGSPACE(m0)) {
		MGET(m1, M_NOWAIT, MT_DATA);
		if (m1 == NULL) {
			m_freem(m0);
			DPRINTF(("%s: unable to get extra mbuf\n", __func__));
			return NULL;
		}
		m0->m_next = m1;
		m0 = m1;
		m0->m_len = 0;
	}
	retval = m0->m_data + m0->m_len;
	m0->m_len += pad;
	m->m_pkthdr.len += pad;
	return retval;
}
caddr_t m_pad ( struct mbuf * m , int n ) { register struct mbuf * m0 , * m1 ; register int len , pad ; caddr_t retval ; if ( n <= 0 ) { DPRINTF ( ( " \n " , __func__ , n ) ) ; m_freem ( m ) ; return NULL ; } len = m -> m_pkthdr . len ; pad = n ; m0 = m ; while ( m0 -> m_len < len ) { len -= m0 -> m_len ; m0 = m0 -> m_next ; } if ( m0 -> m_len != len ) { DPRINTF ( ( " \n " , __func__ , m -> m_pkthdr . len , m -> m_pkthdr . len + m0 -> m_len - len ) ) ; m_freem ( m ) ; return NULL ; } for ( m1 = m0 ; m1 -> m_next ; m1 = m1 -> m_next ) { if ( m1 -> m_next -> m_len != 0 ) { DPRINTF ( ( " " " \n " , __func__ , m -> m_pkthdr . len , m -> m_pkthdr . len + m1 -> m_next -> m_len ) ) ; m_freem ( m ) ; return NULL ; } m0 = m1 -> m_next ; } if ( pad > M_TRAILINGSPACE ( m0 ) ) { MGET ( m1 , M_NOWAIT , MT_DATA ) ; if ( m1 == NULL ) { m_freem ( m0 ) ; DPRINTF ( ( " \n " , __func__ ) ) ; return NULL ; } m0 -> m_next = m1 ; m0 = m1 ; m0 -> m_len = 0 ; } retval = m0 -> m_data + m0 -> m_len ; m0 -> m_len += pad ; m -> m_pkthdr . len += pad ; return retval ; }
m_pad(m, n) pads <m> with <n> bytes at the end.
m_pad ( m n ) pads <m > with <n > bytes at the end .
/* No stupid arguments. */ /* Check for zero-length trailing mbufs, and find the last one. */ /* Add an mbuf to the chain. */