~ubuntu-branches/ubuntu/gutsy/net-snmp/gutsy-security

« back to all changes in this revision

Viewing changes to man/netsnmp_util.3

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
ImportĀ upstreamĀ versionĀ 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.TH "Memory Utility Routines" 3 "19 Mar 2004" "net-snmp" \" -*- nroff -*-
 
2
.ad l
 
3
.nh
 
4
.SH NAME
 
5
Memory Utility Routines \- 
 
6
.SS "Defines"
 
7
 
 
8
.in +1c
 
9
.ti -1c
 
10
.RI "#define \fBSNMP_FREE\fP(s)   if (s) { free((void *)s); s=NULL; }"
 
11
.br
 
12
.RI "\fIFrees a pointer only if it is !NULL and sets its value to NULL.\fP"
 
13
.ti -1c
 
14
.RI "#define \fBSNMP_MALLOC_STRUCT\fP(s)   (struct s *) calloc(1, sizeof(struct s))"
 
15
.br
 
16
.RI "\fIMallocs memory of sizeof(struct s), zeros it and returns a pointer to it.\fP"
 
17
.ti -1c
 
18
.RI "#define \fBSNMP_MALLOC_TYPEDEF\fP(td)   (td *) calloc(1, sizeof(td))"
 
19
.br
 
20
.RI "\fIMallocs memory of sizeof(t), zeros it and returns a pointer to it.\fP"
 
21
.ti -1c
 
22
.RI "#define \fBSNMP_MAX\fP(a, b)   ((a) > (b) ? (a) : (b))"
 
23
.br
 
24
.RI "\fIComputers the maximum of a and b.\fP"
 
25
.ti -1c
 
26
.RI "#define \fBSNMP_MIN\fP(a, b)   ((a) > (b) ? (b) : (a))"
 
27
.br
 
28
.RI "\fIComputers the minimum of a and b.\fP"
 
29
.in -1c
 
30
.SS "Functions"
 
31
 
 
32
.in +1c
 
33
.ti -1c
 
34
.RI "int \fBsnmp_realloc\fP (u_char **buf, size_t *buf_len)"
 
35
.br
 
36
.RI "\fIThis function increase the size of the buffer pointed at by *buf, which is initially of size *buf_len.\fP"
 
37
.ti -1c
 
38
.RI "void \fBfree_zero\fP (void *buf, size_t size)"
 
39
.br
 
40
.RI "\fIzeros memory before freeing it.\fP"
 
41
.ti -1c
 
42
.RI "u_char * \fBmalloc_random\fP (size_t *size)"
 
43
.br
 
44
.RI "\fIReturns pointer to allocaed & set buffer on success, size contains number of random bytes filled.\fP"
 
45
.ti -1c
 
46
.RI "int \fBmemdup\fP (u_char **to, const u_char *from, size_t size)"
 
47
.br
 
48
.RI "\fIDuplicates a memory block.\fP"
 
49
.ti -1c
 
50
.RI "u_int \fBbinary_to_hex\fP (const u_char *input, size_t len, char **output)"
 
51
.br
 
52
.RI "\fIconverts binary to hexidecimal\fP"
 
53
.ti -1c
 
54
.RI "int \fBhex_to_binary2\fP (const u_char *input, size_t len, char **output)"
 
55
.br
 
56
.RI "\fIhex_to_binary2\fP"
 
57
.ti -1c
 
58
.RI "char * \fBnetsnmp_strdup_and_null\fP (const u_char *from, size_t from_len)"
 
59
.br
 
60
.RI "\fIcopies a (possible) unterminated string of a given length into a new buffer and null terminates it as well (new buffer MAY be one byte longer to account for this\fP"
 
61
.ti -1c
 
62
.RI "marker_t \fBatime_newMarker\fP (void)"
 
63
.br
 
64
.RI "\fIcreate a new time marker.\fP"
 
65
.ti -1c
 
66
.RI "void \fBatime_setMarker\fP (marker_t pm)"
 
67
.br
 
68
.RI "\fIset a time marker.\fP"
 
69
.ti -1c
 
70
.RI "long \fBatime_diff\fP (marker_t first, marker_t second)"
 
71
.br
 
72
.RI "\fIReturns the difference (in msec) between the two markers.\fP"
 
73
.ti -1c
 
74
.RI "u_long \fBuatime_diff\fP (marker_t first, marker_t second)"
 
75
.br
 
76
.RI "\fIReturns the difference (in u_long msec) between the two markers.\fP"
 
77
.ti -1c
 
78
.RI "u_long \fBuatime_hdiff\fP (marker_t first, marker_t second)"
 
79
.br
 
80
.RI "\fIReturns the difference (in u_long 1/100th secs) between the two markers (functionally this is what sysUpTime needs).\fP"
 
81
.ti -1c
 
82
.RI "int \fBatime_ready\fP (marker_t pm, int deltaT)"
 
83
.br
 
84
.RI "\fITest: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).\fP"
 
85
.ti -1c
 
86
.RI "int \fBuatime_ready\fP (marker_t pm, unsigned int deltaT)"
 
87
.br
 
88
.RI "\fITest: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).\fP"
 
89
.ti -1c
 
90
.RI "int \fBmarker_tticks\fP (marker_t pm)"
 
91
.br
 
92
.RI "\fIReturn the number of timeTicks since the given marker.\fP"
 
93
.in -1c
 
94
.SH "DEFINE DOCUMENTATION"
 
95
.PP 
 
96
.SS "#define DIFFTIMEVAL(now, then, diff)"
 
97
.PP
 
98
\fBValue:\fP
 
99
.PP
 
100
.nf
 
101
{                                                    \
 
102
        now.tv_sec--;                                   \
 
103
        now.tv_usec += 1000000L;                        \
 
104
        diff.tv_sec  = now.tv_sec  - then.tv_sec;       \
 
105
        diff.tv_usec = now.tv_usec - then.tv_usec;      \
 
106
        if (diff.tv_usec > 1000000L){                   \
 
107
                diff.tv_usec -= 1000000L;               \
 
108
                diff.tv_sec++;                          \
 
109
        }                                               \
 
110
}
 
111
.fi
 
112
.PP
 
113
Definition at line 112 of file tools.h.
 
114
.SS "#define ISTRANSFORM(ttype, toid)"
 
115
.PP
 
116
\fBValue:\fP
 
117
.PP
 
118
.nf
 
119
!snmp_oid_compare(ttype, USM_LENGTH_OID_TRANSFORM,         \
 
120
                usm ## toid ## Protocol, USM_LENGTH_OID_TRANSFORM)
 
121
.fi
 
122
.PP
 
123
Definition at line 131 of file tools.h.
 
124
.SS "#define QUITFUN(e, l)"
 
125
.PP
 
126
\fBValue:\fP
 
127
.PP
 
128
.nf
 
129
if ( (e) != SNMPERR_SUCCESS) {        \
 
130
                rval = SNMPERR_GENERR;  \
 
131
                goto l ;                \
 
132
        }
 
133
.fi
 
134
.PP
 
135
Definition at line 99 of file tools.h.
 
136
.SS "#define SNMP_FREE(s)   if (s) { free((void *)s); s=NULL; }"
 
137
.PP
 
138
Frees a pointer only if it is !NULL and sets its value to NULL.
 
139
.PP
 
140
Definition at line 53 of file tools.h.
 
141
.PP
 
142
Referenced by build_oid_segment(), fprint_description(), fprint_objid(), fprint_variable(), init_mib(), netsnmp_fixup_mib_directory(), netsnmp_free_all_list_data(), netsnmp_free_delegated_cache(), netsnmp_free_list_data(), netsnmp_handler_dup(), netsnmp_handler_free(), netsnmp_handler_registration_free(), netsnmp_register_old_api(), netsnmp_set_row_column(), netsnmp_table_build_oid_from_index(), netsnmp_table_data_delete_row(), netsnmp_table_data_set_helper_handler(), netsnmp_table_dataset_delete_data(), netsnmp_table_iterator_helper_handler(), read_objid(), shutdown_mib(), snmp_unregister_callback(), and unregister_config_handler().
 
143
.SS "#define SNMP_MALLOC_STRUCT(s)   (struct s *) calloc(1, sizeof(struct s))"
 
144
.PP
 
145
Mallocs memory of sizeof(struct s), zeros it and returns a pointer to it.
 
146
.PP
 
147
Definition at line 60 of file tools.h.
 
148
.PP
 
149
Referenced by snmp_alarm_register(), and snmp_alarm_register_hr().
 
150
.SS "#define SNMP_MALLOC_TYPEDEF(td)   (td *) calloc(1, sizeof(td))"
 
151
.PP
 
152
Mallocs memory of sizeof(t), zeros it and returns a pointer to it.
 
153
.PP
 
154
Definition at line 63 of file tools.h.
 
155
.PP
 
156
Referenced by netsnmp_create_data_list(), netsnmp_create_delegated_cache(), netsnmp_create_handler(), netsnmp_create_handler_registration(), netsnmp_create_table_data(), netsnmp_create_table_data_row(), netsnmp_create_table_data_set(), netsnmp_get_cache_handler(), netsnmp_mark_row_column_writable(), netsnmp_mode_end_call_add_mode_callback(), netsnmp_oid_stash_create_sized_node(), netsnmp_old_api_helper(), netsnmp_register_auto_data_table(), netsnmp_register_mib_table_row(), netsnmp_register_old_api(), netsnmp_register_save_list(), netsnmp_register_table_data_set(), netsnmp_set_row_column(), netsnmp_table_container_register(), netsnmp_table_data_set_helper_handler(), netsnmp_table_iterator_helper_handler(), netsnmp_table_set_add_default_row(), and table_helper_handler().
 
157
.SS "#define SNMP_MAX(a, b)   ((a) > (b) ? (a) : (b))"
 
158
.PP
 
159
Computers the maximum of a and b.
 
160
.PP
 
161
Definition at line 77 of file tools.h.
 
162
.PP
 
163
Referenced by netsnmp_register_table_data_set().
 
164
.SS "#define SNMP_MIN(a, b)   ((a) > (b) ? (b) : (a))"
 
165
.PP
 
166
Computers the minimum of a and b.
 
167
.PP
 
168
Definition at line 81 of file tools.h.
 
169
.PP
 
170
Referenced by netsnmp_oid_find_prefix(), netsnmp_register_table_data_set(), and netsnmp_table_data_helper_handler().
 
171
.SH "FUNCTION DOCUMENTATION"
 
172
.PP 
 
173
.SS "long atime_diff (marker_t first, marker_t second)"
 
174
.PP
 
175
Returns the difference (in msec) between the two markers.
 
176
.PP
 
177
Definition at line 745 of file tools.c.
 
178
.PP
 
179
Referenced by atime_ready(), and marker_tticks().
 
180
.SS "marker_t atime_newMarker (void)"
 
181
.PP
 
182
create a new time marker.
 
183
.PP
 
184
NOTE: Caller must free time marker when no longer needed. 
 
185
.PP
 
186
Definition at line 721 of file tools.c.
 
187
.PP
 
188
Referenced by atime_ready(), marker_tticks(), netsnmp_cache_helper_handler(), netsnmp_stash_cache_update(), and uatime_ready().
 
189
.SS "int atime_ready (marker_t pm, int deltaT)"
 
190
.PP
 
191
Test: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).
 
192
.PP
 
193
Definition at line 800 of file tools.c.
 
194
.PP
 
195
References atime_diff(), and atime_newMarker().
 
196
.PP
 
197
Referenced by netsnmp_cache_helper_handler(), netsnmp_stash_cache_update(), and release_cached_resources().
 
198
.SS "void atime_setMarker (marker_t pm)"
 
199
.PP
 
200
set a time marker.
 
201
.PP
 
202
Definition at line 732 of file tools.c.
 
203
.PP
 
204
Referenced by netsnmp_cache_helper_handler(), and netsnmp_stash_cache_update().
 
205
.SS "u_int binary_to_hex (const u_char * input, size_t len, char ** output)"
 
206
.PP
 
207
converts binary to hexidecimal
 
208
.PP
 
209
\fBParameters: \fP
 
210
.in +1c
 
211
.TP
 
212
\fB\fIinput\fP\fP
 
213
Binary data. 
 
214
.TP
 
215
\fB\fIlen\fP\fP
 
216
Length of binary data. 
 
217
.TP
 
218
\fB\fIoutput\fP\fP
 
219
NULL terminated string equivalent in hex.
 
220
.PP
 
221
\fBReturns: \fP
 
222
.in +1c
 
223
olen Length of output string not including NULL terminator.FIX Is there already one of these in the UCD SNMP codebase? The old one should be used, or this one should be moved to snmplib/snmp_api.c. 
 
224
.PP
 
225
Definition at line 287 of file tools.c.
 
226
.SS "void free_zero (void * buf, size_t size)"
 
227
.PP
 
228
zeros memory before freeing it.
 
229
.PP
 
230
\fBParameters: \fP
 
231
.in +1c
 
232
.TP
 
233
\fB\fIbuf\fP\fP
 
234
Pointer at bytes to free. 
 
235
.TP
 
236
\fB\fIsize\fP\fP
 
237
Number of bytes in buf. 
 
238
.PP
 
239
Definition at line 185 of file tools.c.
 
240
.PP
 
241
Referenced by hex_to_binary2(), and malloc_random().
 
242
.SS "int hex_to_binary2 (const u_char * input, size_t len, char ** output)"
 
243
.PP
 
244
hex_to_binary2
 
245
.PP
 
246
\fBParameters: \fP
 
247
.in +1c
 
248
.TP
 
249
\fB\fIinput\fP\fP
 
250
Printable data in base16. 
 
251
.TP
 
252
\fB\fIlen\fP\fP
 
253
Length in bytes of data. 
 
254
.TP
 
255
\fB\fIoutput\fP\fP
 
256
Binary data equivalent to input.
 
257
.PP
 
258
\fBReturns: \fP
 
259
.in +1c
 
260
SNMPERR_GENERR on failure, otherwise length of allocated string.Input of an odd length is right aligned.
 
261
.PP
 
262
FIX Another version of 'hex-to-binary' which takes odd length input strings. It also allocates the memory to hold the binary data. Should be integrated with the official hex_to_binary() function. 
 
263
.PP
 
264
Definition at line 324 of file tools.c.
 
265
.PP
 
266
References free_zero().
 
267
.SS "u_char* malloc_random (size_t * size)"
 
268
.PP
 
269
Returns pointer to allocaed & set buffer on success, size contains number of random bytes filled.
 
270
.PP
 
271
buf is NULL and *size set to KMT error value upon failure.
 
272
.PP
 
273
\fBParameters: \fP
 
274
.in +1c
 
275
.TP
 
276
\fB\fIsize\fP\fP
 
277
Number of bytes to malloc() and fill with random bytes.
 
278
.PP
 
279
\fBReturns: \fP
 
280
.in +1c
 
281
a malloced buffer 
 
282
.PP
 
283
Definition at line 205 of file tools.c.
 
284
.PP
 
285
References free_zero().
 
286
.SS "int marker_tticks (marker_t pm)"
 
287
.PP
 
288
Return the number of timeTicks since the given marker.
 
289
.PP
 
290
Definition at line 848 of file tools.c.
 
291
.PP
 
292
References atime_diff(), and atime_newMarker().
 
293
.SS "int memdup (u_char ** to, const u_char * from, size_t size)"
 
294
.PP
 
295
Duplicates a memory block.
 
296
.PP
 
297
Copies a existing memory location from a pointer to another, newly malloced, pointer.
 
298
.PP
 
299
\fBParameters: \fP
 
300
.in +1c
 
301
.TP
 
302
\fB\fIto\fP\fP
 
303
Pointer to allocate and copy memory to. 
 
304
.TP
 
305
\fB\fIfrom\fP\fP
 
306
Pointer to copy memory from. 
 
307
.TP
 
308
\fB\fIsize\fP\fP
 
309
Size of the data to be copied.
 
310
.PP
 
311
\fBReturns: \fP
 
312
.in +1c
 
313
SNMPERR_SUCCESS on success, SNMPERR_GENERR on failure. 
 
314
.PP
 
315
\fBExamples: \fP
 
316
.in +1c
 
317
\fBdelayed_instance.c\fP.
 
318
.PP
 
319
Definition at line 236 of file tools.c.
 
320
.PP
 
321
Referenced by netsnmp_create_handler_registration(), netsnmp_handler_registration_dup(), netsnmp_register_old_api(), netsnmp_set_row_column(), netsnmp_table_data_clone_row(), netsnmp_table_data_set_clone_row(), and netsnmp_table_set_add_default_row().
 
322
.SS "char* netsnmp_strdup_and_null (const u_char * from, size_t from_len)"
 
323
.PP
 
324
copies a (possible) unterminated string of a given length into a new buffer and null terminates it as well (new buffer MAY be one byte longer to account for this
 
325
.PP
 
326
Definition at line 255 of file tools.c.
 
327
.PP
 
328
Referenced by netsnmp_table_data_set_helper_handler().
 
329
.SS "int snmp_realloc (u_char ** buf, size_t * buf_len)"
 
330
.PP
 
331
This function increase the size of the buffer pointed at by *buf, which is initially of size *buf_len.
 
332
.PP
 
333
Contents are preserved **AT THE BOTTOM END OF THE BUFFER**. If memory can be (re-)allocated then it returns 1, else it returns 0.
 
334
.PP
 
335
\fBParameters: \fP
 
336
.in +1c
 
337
.TP
 
338
\fB\fIbuf\fP\fP
 
339
pointer to a buffer pointer 
 
340
.TP
 
341
\fB\fIbuf_len\fP\fP
 
342
pointer to current size of buffer in bytes 
 
343
.PP
 
344
Definition at line 115 of file tools.c.
 
345
.PP
 
346
Referenced by sprint_realloc_asciistring(), sprint_realloc_hexstring(), sprint_realloc_ipaddress(), sprint_realloc_networkaddress(), and sprint_realloc_octet_string().
 
347
.SS "u_long uatime_diff (marker_t first, marker_t second)"
 
348
.PP
 
349
Returns the difference (in u_long msec) between the two markers.
 
350
.PP
 
351
Definition at line 762 of file tools.c.
 
352
.PP
 
353
Referenced by uatime_ready().
 
354
.SS "u_long uatime_hdiff (marker_t first, marker_t second)"
 
355
.PP
 
356
Returns the difference (in u_long 1/100th secs) between the two markers (functionally this is what sysUpTime needs).
 
357
.PP
 
358
Definition at line 780 of file tools.c.
 
359
.SS "int uatime_ready (marker_t pm, unsigned int deltaT)"
 
360
.PP
 
361
Test: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).
 
362
.PP
 
363
Definition at line 822 of file tools.c.
 
364
.PP
 
365
References atime_newMarker(), and uatime_diff().