Deleted Added
sdiff udiff text old ( 121326 ) new ( 131826 )
full compact
1/*
2 * Copyright (c) 1996-2003
3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * Author: Hartmut Brandt <harti@freebsd.org>
28 *
29 * $Begemot: libunimsg/atm/unimsg.h,v 1.3 2003/09/19 11:52:40 hbb Exp $
30 *
31 * This defines the structure of messages as handled by this library.
32 */
33#ifndef _NETNATM_UNIMSG_H_
34#define _NETNATM_UNIMSG_H_
35
36#include <sys/types.h>
37#ifdef _KERNEL
38#ifdef __FreeBSD__
39#include <sys/systm.h>
40#endif
41#else
42#include <string.h>
43#endif
44
45struct uni_msg {
46 u_char *b_wptr; /* tail pointer */
47 u_char *b_rptr; /* head pointer */
48 u_char *b_buf; /* data buffer */
49 u_char *b_lim; /* end of data buffer */
50};
51
52/* return the current length of the message */
53#define uni_msg_len(M) ((size_t)((M)->b_wptr - (M)->b_rptr))
54
55/* return the number of space behind the message */
56#define uni_msg_space(M) ((size_t)((M)->b_lim - (M)->b_wptr))
57
58/* return the amount of leading free space */
59#define uni_msg_leading(M) ((size_t)((M)->b_rptr - (M)->b_buf))
60
61/* return the maximum size of the message (length plus free space) */
62#define uni_msg_size(M) ((size_t)((M)->b_lim - (M)->b_buf));
63
64/* ensure that there is space for another S bytes. If reallocation fails
65 * free message and return -1 */
66#define uni_msg_ensure(M, S) \
67 ((uni_msg_space(M) >= (S)) ? 0 : uni_msg_extend(M, S))
68
69int uni_msg_append(struct uni_msg *, void *, size_t);
70int uni_msg_extend(struct uni_msg *, size_t);
71
72#define uni_msg_rptr(MSG, TYPE) ((TYPE)(void *)(MSG)->b_rptr)
73#define uni_msg_wptr(MSG, TYPE) ((TYPE)(void *)(MSG)->b_wptr)
74
75int uni_msg_prepend(struct uni_msg *, size_t);
76
77#ifndef _KERNEL
78
79struct uni_msg *uni_msg_alloc(size_t);
80struct uni_msg *uni_msg_build(void *, ...);
81void uni_msg_destroy(struct uni_msg *);
82u_int uni_msg_strip32(struct uni_msg *);
83u_int uni_msg_get32(struct uni_msg *);
84int uni_msg_append32(struct uni_msg *, u_int);
85int uni_msg_append8(struct uni_msg *, u_int);
86u_int uni_msg_trail32(const struct uni_msg *, int);
87struct uni_msg *uni_msg_dup(const struct uni_msg *);
88
89#endif /* _KERNEL */
90#endif