summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorangelos <angelos@openbsd.org>2000-03-02 21:40:49 +0000
committerangelos <angelos@openbsd.org>2000-03-02 21:40:49 +0000
commit8147e0b03a6e98e9c473b08850eb91f5bdd9719f (patch)
treebf1e92979d5ff97c1b2fa7e8b409adaad3cfa2ba
parentAdd prototype for m_getptr() (diff)
downloadwireguard-openbsd-8147e0b03a6e98e9c473b08850eb91f5bdd9719f.tar.xz
wireguard-openbsd-8147e0b03a6e98e9c473b08850eb91f5bdd9719f.zip
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.c38
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