* Apply function f to the data in an mbuf chain starting "off" bytes from * the beginning, continuing for "len" bytes. */
| 1221 | * the beginning, continuing for "len" bytes. |
| 1222 | */ |
| 1223 | int |
| 1224 | m_apply(struct mbuf *m, int off, int len, |
| 1225 | int (*f)(void *, void *, u_int), void *arg) |
| 1226 | { |
| 1227 | u_int count; |
| 1228 | int rval; |
| 1229 | |
| 1230 | KASSERT(off >= 0, ("m_apply, negative off %d", off)); |
| 1231 | KASSERT(len >= 0, ("m_apply, negative len %d", len)); |
| 1232 | while (off > 0) { |
| 1233 | KASSERT(m != NULL, ("m_apply, offset > size of mbuf chain")); |
| 1234 | if (off < m->m_len) |
| 1235 | break; |
| 1236 | off -= m->m_len; |
| 1237 | m = m->m_next; |
| 1238 | } |
| 1239 | while (len > 0) { |
| 1240 | KASSERT(m != NULL, ("m_apply, offset > size of mbuf chain")); |
| 1241 | count = min(m->m_len - off, len); |
| 1242 | rval = (*f)(arg, mtod(m, caddr_t) + off, count); |
| 1243 | if (rval) |
| 1244 | return (rval); |
| 1245 | len -= count; |
| 1246 | off = 0; |
| 1247 | m = m->m_next; |
| 1248 | } |
| 1249 | return (0); |
| 1250 | } |
| 1251 | |
| 1252 | /* |
| 1253 | * Return a pointer to mbuf/offset of location in mbuf chain. |
no test coverage detected