From d5dc926f18eb9a25b2e188e3cf6e4d7b76b15bcc Mon Sep 17 00:00:00 2001 From: Amol Lad Date: Thu, 11 Mar 2021 15:57:55 +1300 Subject: [PATCH] nhrpd: Add zbuf routine to peek at contents Signed-off-by: Reuben Dowle --- nhrpd/zbuf.c | 12 ++++++++++++ nhrpd/zbuf.h | 1 + 2 files changed, 13 insertions(+) diff --git a/nhrpd/zbuf.c b/nhrpd/zbuf.c index 7f1475cc69..1a4a7b3996 100644 --- a/nhrpd/zbuf.c +++ b/nhrpd/zbuf.c @@ -230,3 +230,15 @@ void zbuf_copy(struct zbuf *zdst, struct zbuf *zsrc, size_t len) return; memcpy(dst, src, len); } + +void zbuf_copy_peek(struct zbuf *zdst, struct zbuf *zsrc, size_t len) +{ + const void *src; + void *dst; + + dst = zbuf_pushn(zdst, len); + src = zbuf_pulln(zsrc, 0); + if (!dst || !src) + return; + memcpy(dst, src, len); +} diff --git a/nhrpd/zbuf.h b/nhrpd/zbuf.h index e6f7101d63..d4a7c15a95 100644 --- a/nhrpd/zbuf.h +++ b/nhrpd/zbuf.h @@ -190,6 +190,7 @@ static inline void zbuf_put_be32(struct zbuf *zb, uint32_t val) } void zbuf_copy(struct zbuf *zb, struct zbuf *src, size_t len); +void zbuf_copy_peek(struct zbuf *zdst, struct zbuf *zsrc, size_t len); void zbufq_init(struct zbuf_queue *); void zbufq_reset(struct zbuf_queue *); -- 2.39.5