summaryrefslogtreecommitdiff
path: root/lib/stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stream.c')
-rw-r--r--lib/stream.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/lib/stream.c b/lib/stream.c
index 4c237563a5..809e749fb9 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -373,6 +373,47 @@ stream_getw_from (struct stream *s, size_t from)
return w;
}
+/* Get next 3-byte from the stream. */
+u_int32_t
+stream_get3_from (struct stream *s, size_t from)
+{
+ u_int32_t l;
+
+ STREAM_VERIFY_SANE(s);
+
+ if (!GETP_VALID (s, from + 3))
+ {
+ STREAM_BOUND_WARN (s, "get 3byte");
+ return 0;
+ }
+
+ l = s->data[from++] << 16;
+ l |= s->data[from++] << 8;
+ l |= s->data[from];
+
+ return l;
+}
+
+u_int32_t
+stream_get3 (struct stream *s)
+{
+ u_int32_t l;
+
+ STREAM_VERIFY_SANE(s);
+
+ if (STREAM_READABLE (s) < 3)
+ {
+ STREAM_BOUND_WARN (s, "get 3byte");
+ return 0;
+ }
+
+ l = s->data[s->getp++] << 16;
+ l |= s->data[s->getp++] << 8;
+ l |= s->data[s->getp++];
+
+ return l;
+}
+
/* Get next long word from the stream. */
u_int32_t
stream_getl_from (struct stream *s, size_t from)
@@ -502,6 +543,28 @@ stream_get_ipv4 (struct stream *s)
return l;
}
+float
+stream_getf (struct stream *s)
+{
+ union {
+ float r;
+ uint32_t d;
+ } u;
+ u.d = stream_getl (s);
+ return u.r;
+}
+
+double
+stream_getd (struct stream *s)
+{
+ union {
+ double r;
+ uint64_t d;
+ } u;
+ u.d = stream_getq (s);
+ return u.r;
+}
+
/* Copy to source to stream.
*
* XXX: This uses CHECK_SIZE and hence has funny semantics -> Size will wrap
@@ -568,6 +631,25 @@ stream_putw (struct stream *s, u_int16_t w)
/* Put long word to the stream. */
int
+stream_put3 (struct stream *s, u_int32_t l)
+{
+ STREAM_VERIFY_SANE (s);
+
+ if (STREAM_WRITEABLE (s) < 3)
+ {
+ STREAM_BOUND_WARN (s, "put");
+ return 0;
+ }
+
+ s->data[s->endp++] = (u_char)(l >> 16);
+ s->data[s->endp++] = (u_char)(l >> 8);
+ s->data[s->endp++] = (u_char)l;
+
+ return 3;
+}
+
+/* Put long word to the stream. */
+int
stream_putl (struct stream *s, u_int32_t l)
{
STREAM_VERIFY_SANE (s);
@@ -611,6 +693,28 @@ stream_putq (struct stream *s, uint64_t q)
}
int
+stream_putf (struct stream *s, float f)
+{
+ union {
+ float i;
+ uint32_t o;
+ } u;
+ u.i = f;
+ return stream_putl (s, u.o);
+}
+
+int
+stream_putd (struct stream *s, double d)
+{
+ union {
+ double i;
+ uint64_t o;
+ } u;
+ u.i = d;
+ return stream_putq (s, u.o);
+}
+
+int
stream_putc_at (struct stream *s, size_t putp, u_char c)
{
STREAM_VERIFY_SANE(s);
@@ -644,6 +748,23 @@ stream_putw_at (struct stream *s, size_t putp, u_int16_t w)
}
int
+stream_put3_at (struct stream *s, size_t putp, u_int32_t l)
+{
+ STREAM_VERIFY_SANE(s);
+
+ if (!PUT_AT_VALID (s, putp + 3))
+ {
+ STREAM_BOUND_WARN (s, "put");
+ return 0;
+ }
+ s->data[putp] = (u_char)(l >> 16);
+ s->data[putp + 1] = (u_char)(l >> 8);
+ s->data[putp + 2] = (u_char)l;
+
+ return 3;
+}
+
+int
stream_putl_at (struct stream *s, size_t putp, u_int32_t l)
{
STREAM_VERIFY_SANE(s);