diff options
Diffstat (limited to 'lib/stream.c')
| -rw-r--r-- | lib/stream.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/stream.c b/lib/stream.c index 0fc3c3b118..cc5898a6db 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -401,6 +401,21 @@ stream_getl_from (struct stream *s, size_t from) return l; } +/* Copy from stream at specific location to destination. */ +void +stream_get_from (void *dst, struct stream *s, size_t from, size_t size) +{ + STREAM_VERIFY_SANE(s); + + if (!GETP_VALID (s, from + size)) + { + STREAM_BOUND_WARN (s, "get from"); + return; + } + + memcpy (dst, s->data + from, size); +} + u_int32_t stream_getl (struct stream *s) { @@ -709,6 +724,38 @@ stream_put_in_addr (struct stream *s, struct in_addr *addr) return sizeof (u_int32_t); } +/* Put in_addr at location in the stream. */ +int +stream_put_in_addr_at (struct stream *s, size_t putp, struct in_addr *addr) +{ + STREAM_VERIFY_SANE(s); + + if (!PUT_AT_VALID (s, putp + 4)) + { + STREAM_BOUND_WARN (s, "put"); + return 0; + } + + memcpy (&s->data[putp], addr, 4); + return 4; +} + +/* Put in6_addr at location in the stream. */ +int +stream_put_in6_addr_at (struct stream *s, size_t putp, struct in6_addr *addr) +{ + STREAM_VERIFY_SANE(s); + + if (!PUT_AT_VALID (s, putp + 16)) + { + STREAM_BOUND_WARN (s, "put"); + return 0; + } + + memcpy (&s->data[putp], addr, 16); + return 16; +} + /* Put prefix by nlri type format. */ int stream_put_prefix (struct stream *s, struct prefix *p) |
