diff options
author | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2000-03-02 21:40:50 +0000 |
---|---|---|
committer | Angelos D. Keromytis <angelos@cvs.openbsd.org> | 2000-03-02 21:40:50 +0000 |
commit | 864ccb16c3c0833a19497a00a5b961439d0852ad (patch) | |
tree | 4cf651476d21a8050a9f2f73c3992c9bf9d58e8b | |
parent | 689a91faeb5d3950c94e078abd27fcd31edd24d0 (diff) |
New function: m_getptr(), takes as argument an mbuf chain and an
offset, returns a pointer to them specific mbuf and the offset inside
it that corresponds to the offset argument (so one can find where the
n'th byte is in an mbuf).
-rw-r--r-- | sys/kern/uipc_mbuf.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index c63c3eabf0b..84f0d8efe9d 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf.c,v 1.19 1999/12/31 23:37:08 provos Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.20 2000/03/02 21:40:49 angelos Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */ /* @@ -721,6 +721,42 @@ bad: } /* + * Return a pointer to mbuf/offset of location in mbuf chain. + */ +struct mbuf * +m_getptr(struct mbuf *m, int loc, int *off) +{ + while (loc >= 0) + { + /* Normal end of search */ + if (m->m_len > loc) + { + *off = loc; + return m; + } + else + { + loc -= m->m_len; + + if (m->m_next == NULL) + { + if (loc == 0) + { + *off = m->m_len; /* Point at the end of valid data */ + return m; + } + else + return NULL; + } + else + m = m->m_next; + } + } + + return NULL; +} + +/* * Inject a new mbuf chain of length siz in mbuf chain m0 at * position len0. Returns a pointer to the first injected mbuf, or * NULL on failure (m0 is left undisturbed). Note that if there is |