blob: c7e4ffbf1f4f3e27287355f8e1714a983e330a06 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * Packet interface
3 * Copyright (C) 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_STREAM_H
24#define _ZEBRA_STREAM_H
25
paul02ff83c2004-06-11 11:27:03 +000026#include "prefix.h"
27
paul718e3742002-12-13 20:15:29 +000028/* Stream buffer. */
29struct stream
30{
31 struct stream *next;
32
33 unsigned char *data;
34
paul718e3742002-12-13 20:15:29 +000035 /* Get pointer. */
36 unsigned long getp;
37
38 /* End of pointer. */
39 unsigned long endp;
40
41 /* Data size. */
42 unsigned long size;
43};
44
45/* First in first out queue structure. */
46struct stream_fifo
47{
48 unsigned long count;
49
50 struct stream *head;
51 struct stream *tail;
52};
53
54/* Utility macros. */
55#define STREAM_PNT(S) ((S)->data + (S)->getp)
56#define STREAM_SIZE(S) ((S)->size)
paul9985f832005-02-09 15:51:56 +000057#define STREAM_REMAIN(S) ((S)->size - (S)->endp)
paul718e3742002-12-13 20:15:29 +000058#define STREAM_DATA(S) ((S)->data)
59
60/* Stream prototypes. */
61struct stream *stream_new (size_t);
62void stream_free (struct stream *);
63
64unsigned long stream_get_getp (struct stream *);
paul718e3742002-12-13 20:15:29 +000065unsigned long stream_get_endp (struct stream *);
66unsigned long stream_get_size (struct stream *);
67u_char *stream_get_data (struct stream *);
68
69void stream_set_getp (struct stream *, unsigned long);
paul9985f832005-02-09 15:51:56 +000070void stream_forward_getp (struct stream *, int);
71void stream_forward_endp (struct stream *, int);
paul718e3742002-12-13 20:15:29 +000072
73void stream_put (struct stream *, void *, size_t);
74int stream_putc (struct stream *, u_char);
75int stream_putc_at (struct stream *, unsigned long, u_char);
76int stream_putw (struct stream *, u_int16_t);
77int stream_putw_at (struct stream *, unsigned long, u_int16_t);
78int stream_putl (struct stream *, u_int32_t);
79int stream_putl_at (struct stream *, unsigned long, u_int32_t);
80int stream_put_ipv4 (struct stream *, u_int32_t);
81int stream_put_in_addr (struct stream *, struct in_addr *);
paul02ff83c2004-06-11 11:27:03 +000082int stream_put_prefix (struct stream *, struct prefix *);
paul718e3742002-12-13 20:15:29 +000083
84void stream_get (void *, struct stream *, size_t);
85u_char stream_getc (struct stream *);
86u_char stream_getc_from (struct stream *, unsigned long);
87u_int16_t stream_getw (struct stream *);
88u_int16_t stream_getw_from (struct stream *, unsigned long);
89u_int32_t stream_getl (struct stream *);
90u_int32_t stream_get_ipv4 (struct stream *);
91
92#undef stream_read
93#undef stream_write
94int stream_read (struct stream *, int, size_t);
95int stream_read_unblock (struct stream *, int, size_t);
96int stream_write (struct stream *, u_char *, size_t);
97
98u_char *stream_pnt (struct stream *);
99void stream_reset (struct stream *);
100int stream_flush (struct stream *, int);
101int stream_empty (struct stream *);
102
103/* Stream fifo. */
104struct stream_fifo *stream_fifo_new ();
105void stream_fifo_push (struct stream_fifo *fifo, struct stream *s);
106struct stream *stream_fifo_pop (struct stream_fifo *fifo);
107struct stream *stream_fifo_head (struct stream_fifo *fifo);
108void stream_fifo_clean (struct stream_fifo *fifo);
109void stream_fifo_free (struct stream_fifo *fifo);
110
111#endif /* _ZEBRA_STREAM_H */