blob: f7a94ea3744f38d83e4476da9cb7b276e71fc49d [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
35 /* Put pointer. */
36 unsigned long putp;
37
38 /* Get pointer. */
39 unsigned long getp;
40
41 /* End of pointer. */
42 unsigned long endp;
43
44 /* Data size. */
45 unsigned long size;
46};
47
48/* First in first out queue structure. */
49struct stream_fifo
50{
51 unsigned long count;
52
53 struct stream *head;
54 struct stream *tail;
55};
56
57/* Utility macros. */
58#define STREAM_PNT(S) ((S)->data + (S)->getp)
59#define STREAM_SIZE(S) ((S)->size)
60#define STREAM_REMAIN(S) ((S)->size - (S)->putp)
61#define STREAM_DATA(S) ((S)->data)
62
63/* Stream prototypes. */
64struct stream *stream_new (size_t);
65void stream_free (struct stream *);
66
67unsigned long stream_get_getp (struct stream *);
68unsigned long stream_get_putp (struct stream *);
69unsigned long stream_get_endp (struct stream *);
70unsigned long stream_get_size (struct stream *);
71u_char *stream_get_data (struct stream *);
72
73void stream_set_getp (struct stream *, unsigned long);
74void stream_set_putp (struct stream *, unsigned long);
75
76void stream_forward (struct stream *, int);
77
78void stream_put (struct stream *, void *, size_t);
79int stream_putc (struct stream *, u_char);
80int stream_putc_at (struct stream *, unsigned long, u_char);
81int stream_putw (struct stream *, u_int16_t);
82int stream_putw_at (struct stream *, unsigned long, u_int16_t);
83int stream_putl (struct stream *, u_int32_t);
84int stream_putl_at (struct stream *, unsigned long, u_int32_t);
85int stream_put_ipv4 (struct stream *, u_int32_t);
86int stream_put_in_addr (struct stream *, struct in_addr *);
paul02ff83c2004-06-11 11:27:03 +000087int stream_put_prefix (struct stream *, struct prefix *);
paul718e3742002-12-13 20:15:29 +000088
89void stream_get (void *, struct stream *, size_t);
90u_char stream_getc (struct stream *);
91u_char stream_getc_from (struct stream *, unsigned long);
92u_int16_t stream_getw (struct stream *);
93u_int16_t stream_getw_from (struct stream *, unsigned long);
94u_int32_t stream_getl (struct stream *);
95u_int32_t stream_get_ipv4 (struct stream *);
96
97#undef stream_read
98#undef stream_write
99int stream_read (struct stream *, int, size_t);
100int stream_read_unblock (struct stream *, int, size_t);
101int stream_write (struct stream *, u_char *, size_t);
102
103u_char *stream_pnt (struct stream *);
104void stream_reset (struct stream *);
105int stream_flush (struct stream *, int);
106int stream_empty (struct stream *);
107
108/* Stream fifo. */
109struct stream_fifo *stream_fifo_new ();
110void stream_fifo_push (struct stream_fifo *fifo, struct stream *s);
111struct stream *stream_fifo_pop (struct stream_fifo *fifo);
112struct stream *stream_fifo_head (struct stream_fifo *fifo);
113void stream_fifo_clean (struct stream_fifo *fifo);
114void stream_fifo_free (struct stream_fifo *fifo);
115
116#endif /* _ZEBRA_STREAM_H */