OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [lib/] [v2_0/] [include/] [tools.h] - Blame information for rev 201

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      ./lib/current/include/tools.h
4
//
5
//
6
//==========================================================================
7
//####ECOSGPLCOPYRIGHTBEGIN####
8
// -------------------------------------------
9
// This file is part of eCos, the Embedded Configurable Operating System.
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation; either version 2 or (at your option) any later version.
15
//
16
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
// for more details.
20
//
21
// You should have received a copy of the GNU General Public License along
22
// with eCos; if not, write to the Free Software Foundation, Inc.,
23
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
//
25
// As a special exception, if other files instantiate templates or use macros
26
// or inline functions from this file, or you compile this file and link it
27
// with other works to produce a work based on this file, this file does not
28
// by itself cause the resulting work to be covered by the GNU General Public
29
// License. However the source code for this file must still be made available
30
// in accordance with section (3) of the GNU General Public License.
31
//
32
// This exception does not invalidate any other reasons why a work based on
33
// this file might be covered by the GNU General Public License.
34
//
35
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
// at http://sources.redhat.com/ecos/ecos-license/
37
// -------------------------------------------
38
//####ECOSGPLCOPYRIGHTEND####
39
//####UCDSNMPCOPYRIGHTBEGIN####
40
//
41
// -------------------------------------------
42
//
43
// Portions of this software may have been derived from the UCD-SNMP
44
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
45
// California at Davis, which was originally based on the Carnegie Mellon
46
// University SNMP implementation.  Portions of this software are therefore
47
// covered by the appropriate copyright disclaimers included herein.
48
//
49
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50
// -------------------------------------------
51
//
52
//####UCDSNMPCOPYRIGHTEND####
53
//==========================================================================
54
//#####DESCRIPTIONBEGIN####
55
//
56
// Author(s):    hmt
57
// Contributors: hmt
58
// Date:         2000-05-30
59
// Purpose:      Port of UCD-SNMP distribution to eCos.
60
// Description:  
61
//              
62
//
63
//####DESCRIPTIONEND####
64
//
65
//==========================================================================
66
/********************************************************************
67
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
 
69
                          Derivative Work -
70
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
 
72
                         All Rights Reserved
73
 
74
Permission to use, copy, modify and distribute this software and its
75
documentation for any purpose and without fee is hereby granted,
76
provided that the above copyright notice appears in all copies and
77
that both that copyright notice and this permission notice appear in
78
supporting documentation, and that the name of CMU and The Regents of
79
the University of California not be used in advertising or publicity
80
pertaining to distribution of the software without specific written
81
permission.
82
 
83
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
86
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
*********************************************************************/
92
/*
93
 * tools.h
94
 */
95
 
96
#ifndef _TOOLS_H
97
#define _TOOLS_H
98
 
99
#ifdef __cplusplus
100
extern "C" {
101
#endif
102
 
103
 
104
 
105
/*
106
 * General acros and constants.
107
 */
108
#ifdef WIN32
109
#  define SNMP_MAXPATH MAX_PATH
110
#else
111
#  ifdef PATH_MAX
112
#    define SNMP_MAXPATH PATH_MAX
113
#  else
114
#    define SNMP_MAXPATH MAXPATHLEN
115
#  endif
116
#endif
117
 
118
#define SNMP_MAXBUF             (1024 * 4)
119
#define SNMP_MAXBUF_MEDIUM      1024
120
#define SNMP_MAXBUF_SMALL       512
121
 
122
#define SNMP_MAXBUF_MESSAGE     1500
123
 
124
#define SNMP_MAXOID             64
125
 
126
#define SNMP_FILEMODE_CLOSED    0600
127
#define SNMP_FILEMODE_OPEN      0644
128
 
129
#define BYTESIZE(bitsize)       ((bitsize + 7) >> 3)
130
#define ROUNDUP8(x)             ( ( (x+7) >> 3 ) * 8 )
131
 
132
 
133
 
134
#define SNMP_FREE(s)            if (s) { free((void *)s); s=NULL; }
135
 
136
                                        /* XXX Not optimal everywhere. */
137
#define SNMP_MALLOC_STRUCT(s)   (struct s *) calloc(1, sizeof(struct s))
138
#define SNMP_ZERO(s,l)          if (s) memset(s, 0, l);
139
 
140
 
141
#define TOUPPER(c)      (c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c)
142
#define TOLOWER(c)      (c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c)
143
 
144
#define HEX2VAL(s) \
145
        ((isalpha(s) ? (TOLOWER(s)-'a'+10) : (TOLOWER(s)-'0')) & 0xf)
146
#define VAL2HEX(s)      ( (s) + (((s) >= 10) ? ('a'-10) : '0') )
147
 
148
 
149
#define SNMP_MAX(a,b) ((a) > (b) ? (a) : (b))
150
#define SNMP_MIN(a,b) ((a) > (b) ? (b) : (a))
151
 
152
#ifndef FALSE
153
#define FALSE 0
154
#endif
155
#ifndef TRUE
156
#define TRUE  1
157
#endif
158
 
159
/*
160
 * QUIT the FUNction:
161
 *      e       Error code variable
162
 *      l       Label to goto to cleanup and get out of the function.
163
 *
164
 * XXX  It would be nice if the label could be constructed by the
165
 *      preprocessor in context.  Limited to a single error return value.
166
 *      Temporary hack at best.
167
 */
168
#define QUITFUN(e, l)                   \
169
        if ( (e) != SNMPERR_SUCCESS) {  \
170
                rval = SNMPERR_GENERR;  \
171
                goto l ;                \
172
        }
173
 
174
/*
175
 * DIFFTIMEVAL
176
 *      Set <diff> to the difference between <now> (current) and <then> (past).
177
 *
178
 * ASSUMES that all inputs are (struct timeval)'s.
179
 * Cf. system.c:calculate_time_diff().
180
 */
181
#define DIFFTIMEVAL(now, then, diff)                    \
182
{                                                       \
183
        now.tv_sec--;                                   \
184
        now.tv_usec += 1000000L;                        \
185
        diff.tv_sec  = now.tv_sec  - then.tv_sec;       \
186
        diff.tv_usec = now.tv_usec - then.tv_usec;      \
187
        if (diff.tv_usec > 1000000L){                   \
188
                diff.tv_usec -= 1000000L;               \
189
                diff.tv_sec++;                          \
190
        }                                               \
191
}
192
 
193
 
194
/*
195
 * ISTRANSFORM
196
 * ASSUMES the minimum length for ttype and toid.
197
 */
198
#define USM_LENGTH_OID_TRANSFORM        10
199
 
200
#define ISTRANSFORM(ttype, toid)                                        \
201
        !snmp_oid_compare(ttype, USM_LENGTH_OID_TRANSFORM,              \
202
                usm ## toid ## Protocol, USM_LENGTH_OID_TRANSFORM)
203
 
204
#define ENGINETIME_MAX  2147483647      /* ((2^31)-1) */
205
#define ENGINEBOOT_MAX  2147483647      /* ((2^31)-1) */
206
 
207
 
208
 
209
 
210
/*
211
 * Prototypes.
212
 */
213
void    free_zero (void *buf, size_t size);
214
 
215
u_char *malloc_random (size_t *size);
216
u_char *malloc_zero (size_t size);
217
int     memdup (u_char **to, const u_char *from, size_t size);
218
 
219
u_int   binary_to_hex (const u_char *input, size_t len, char **output);
220
int     hex_to_binary2 (const u_char *input, size_t len, char **output);
221
 
222
void    dump_chunk (const char *debugtoken, const char *title, const u_char *buf, int size);
223
char   *dump_snmpEngineID (const u_char *buf, size_t *buflen);
224
 
225
typedef void * marker_t;
226
marker_t atime_newMarker(void);
227
void atime_setMarker(marker_t pm);
228
int atime_ready( marker_t pm, int deltaT);
229
 
230
#ifdef __cplusplus
231
}
232
#endif
233
 
234
#endif /* _TOOLS_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.