dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

buf.h
Go to the documentation of this file.
1 /*
2  * buf.h
3  *
4  * Buffer manipulation routines.
5  *
6  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7  *
8  * $Id: buf.h,v 1.6 2001/03/15 08:33:05 dugsong Exp $
9  */
10 
11 #ifndef BUF_H
12 #define BUF_H
13 
14 typedef struct buf {
15  u_char *base;
16  int size;
17  int offset;
18  int end;
19 } *buf_t;
20 
21 /* Initialize buffer. */
22 void buf_init(buf_t buf, u_char *data, int len);
23 
24 /* Allocate buffer. */
25 buf_t buf_new(int size);
26 
27 /* Free buffer. */
28 void buf_free(buf_t buf);
29 
30 /* Return pointer to buffer data. */
31 #define buf_ptr(b) ((b)->base + (b)->offset)
32 
33 /* Return length of buffer data. */
34 #define buf_len(b) ((b)->end - (b)->offset)
35 
36 /* Return remaining length of unused buffer. */
37 #define buf_left(b) ((b)->size - (b)->offset)
38 
39 /* Return size of buffer. */
40 #define buf_size(b) ((b)->size)
41 
42 /* Return offset in buffer. */
43 #define buf_tell(b) ((b)->offset)
44 
45 /* Reposition buffer offset. */
46 int buf_seek(buf_t buf, int offset, int whence);
47 #define buf_skip(b, l) buf_seek(b, l, SEEK_CUR)
48 #define buf_rewind(b) buf_seek(b, 0, SEEK_SET)
49 
50 /* Read from buffer. */
51 int buf_get(buf_t buf, void *dst, int len);
52 
53 /* Write to buffer. */
54 int buf_put(buf_t buf, void *src, int len);
55 int buf_putf(buf_t buf, const char *fmt, ...);
56 
57 /* Finalize buffer. */
58 void buf_end(buf_t buf);
59 
60 /* Locate byte string in buffer. */
61 int buf_index(buf_t buf, void *ptr, int len);
62 int buf_rindex(buf_t buf, void *ptr, int len);
63 
64 /* Compare buffer to byte string. */
65 int buf_cmp(buf_t buf, void *ptr, int len);
66 
67 /* Tokenize buffer, like strtok(3). */
68 buf_t buf_tok(buf_t buf, void *sep, int len);
69 
70 /* Get a sub-buffer from buffer. */
71 buf_t buf_getbuf(buf_t buf, int offset, int len);
72 
73 /* Get a word from buffer. */
74 buf_t buf_getword(buf_t buf, void *sep, int len);
75 
76 /* Convert buffer to allocated string. */
77 char * buf_strdup(buf_t buf);
78 
79 /* ASCII string test. */
80 int buf_isascii(buf_t buf);
81 
82 #endif /* BUF_H */
buf_getbuf
buf_t buf_getbuf(buf_t buf, int offset, int len)
Definition: buf.c:199
buf::size
int size
Definition: buf.h:16
buf_strdup
char * buf_strdup(buf_t buf)
Definition: buf.c:235
buf_free
void buf_free(buf_t buf)
Definition: buf.c:51
buf_getword
buf_t buf_getword(buf_t buf, void *sep, int len)
Definition: buf.c:218
buf::offset
int offset
Definition: buf.h:17
buf_init
void buf_init(buf_t buf, u_char *data, int len)
Definition: buf.c:24
buf::base
u_char * base
Definition: buf.h:15
buf_isascii
int buf_isascii(buf_t buf)
Definition: buf.c:253
buf_tok
buf_t buf_tok(buf_t buf, void *sep, int len)
Definition: buf.c:167
buf_new
buf_t buf_new(int size)
Definition: buf.c:32
buf
Definition: buf.h:14
buf_putf
int buf_putf(buf_t buf, const char *fmt,...)
Definition: buf.c:106
buf_index
int buf_index(buf_t buf, void *ptr, int len)
Definition: buf.c:128
buf_cmp
int buf_cmp(buf_t buf, void *ptr, int len)
Definition: buf.c:158
buf_end
void buf_end(buf_t buf)
Definition: buf.c:121
buf_put
int buf_put(buf_t buf, void *src, int len)
Definition: buf.c:93
buf_rindex
int buf_rindex(buf_t buf, void *ptr, int len)
Definition: buf.c:143
buf_t
struct buf * buf_t
buf::end
int end
Definition: buf.h:18
buf_get
int buf_get(buf_t buf, void *dst, int len)
Definition: buf.c:74
buf_seek
int buf_seek(buf_t buf, int offset, int whence)
Definition: buf.c:60