summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSubbaiah Venkata <svenkata@google.com>2012-03-24 13:10:19 -0700
committerAvneesh Sachdev <avneesh@opensourcerouting.org>2012-04-07 13:53:40 -0700
commitd531050b7bf0f93d4d29a7a2f7b745641778b483 (patch)
tree82e45741fa3883f6e25a38f2abef4eea107fd54f /lib
parentbed930fd70742af5ae138e0a5ee629dda296ea36 (diff)
lib: add stream_set_endp()
* lib/stream.[ch]: - Add stream_set_endp(). This can be used to trim data (for example, padding) at the end of a stream. - Fix swapped 'getp' and 'endp' parameters in STREAM_WARN_OFFSETS. From: Subbaiah Venkata <svenkata@google.com> Signed-off-by: Avneesh Sachdev <avneesh@opensourcerouting.org> Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/stream.c20
-rw-r--r--lib/stream.h1
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/stream.c b/lib/stream.c
index 983330ff..b226a25e 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -52,7 +52,7 @@
* using stream_put..._at() functions.
*/
#define STREAM_WARN_OFFSETS(S) \
- zlog_warn ("&(struct stream): %p, size: %lu, endp: %lu, getp: %lu\n", \
+ zlog_warn ("&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \
(S), \
(unsigned long) (S)->size, \
(unsigned long) (S)->getp, \
@@ -214,6 +214,20 @@ stream_set_getp (struct stream *s, size_t pos)
s->getp = pos;
}
+void
+stream_set_endp (struct stream *s, size_t pos)
+{
+ STREAM_VERIFY_SANE(s);
+
+ if (!GETP_VALID (s, pos))
+ {
+ STREAM_BOUND_WARN (s, "set endp");
+ pos = s->endp;
+ }
+
+ s->endp = pos;
+}
+
/* Forward pointer. */
void
stream_forward_getp (struct stream *s, size_t size)
@@ -934,9 +948,9 @@ stream_fifo_pop (struct stream_fifo *fifo)
if (fifo->head == NULL)
fifo->tail = NULL;
- }
- fifo->count--;
+ fifo->count--;
+ }
return s;
}
diff --git a/lib/stream.h b/lib/stream.h
index 3e4ba7b4..f10aa6d4 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -146,6 +146,7 @@ extern size_t stream_get_size (struct stream *);
extern u_char *stream_get_data (struct stream *);
extern void stream_set_getp (struct stream *, size_t);
+extern void stream_set_endp (struct stream *, size_t);
extern void stream_forward_getp (struct stream *, size_t);
extern void stream_forward_endp (struct stream *, size_t);