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