15 * General acros and constants.
18 # define SNMP_MAXPATH MAX_PATH
21 # define SNMP_MAXPATH PATH_MAX
24 # define SNMP_MAXPATH MAXPATHLEN
26 # define SNMP_MAXPATH 1024 /* Should be safe enough */
31 #define SNMP_MAXBUF (1024 * 4)
32 #define SNMP_MAXBUF_MEDIUM 1024
33 #define SNMP_MAXBUF_SMALL 512
35 #define SNMP_MAXBUF_MESSAGE 1500
37 #define SNMP_MAXOID 64
39 #define SNMP_FILEMODE_CLOSED 0600
40 #define SNMP_FILEMODE_OPEN 0644
42 #define BYTESIZE(bitsize) ((bitsize + 7) >> 3)
43 #define ROUNDUP8(x) ( ( (x+7) >> 3 ) * 8 )
47 #define SNMP_FREE(s) if (s) { free((void *)s); s=NULL; }
50 * XXX Not optimal everywhere.
52 #define SNMP_MALLOC_STRUCT(s) (struct s *) calloc(1, sizeof(struct s))
53 #define SNMP_MALLOC_TYPEDEF(td) (td *) calloc(1, sizeof(td))
54 #define SNMP_ZERO(s,l) if (s) memset(s, 0, l);
57 #define TOUPPER(c) (c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c)
58 #define TOLOWER(c) (c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c)
61 ((isalpha(s) ? (TOLOWER(s)-'a'+10) : (TOLOWER(s)-'0')) & 0xf)
62 #define VAL2HEX(s) ( (s) + (((s) >= 10) ? ('a'-10) : '0') )
65 #define SNMP_MAX(a,b) ((a) > (b) ? (a) : (b))
66 #define SNMP_MIN(a,b) ((a) > (b) ? (b) : (a))
77 * e Error code variable
78 * l Label to goto to cleanup and get out of the function.
80 * XXX It would be nice if the label could be constructed by the
81 * preprocessor in context. Limited to a single error return value.
82 * Temporary hack at best.
84 #define QUITFUN(e, l) \
85 if ( (e) != SNMPERR_SUCCESS) { \
86 rval = SNMPERR_GENERR; \
92 * Set <diff> to the difference between <now> (current) and <then> (past).
94 * ASSUMES that all inputs are (struct timeval)'s.
95 * Cf. system.c:calculate_time_diff().
97 #define DIFFTIMEVAL(now, then, diff) \
100 now.tv_usec += 1000000L; \
101 diff.tv_sec = now.tv_sec - then.tv_sec; \
102 diff.tv_usec = now.tv_usec - then.tv_usec; \
103 if (diff.tv_usec > 1000000L){ \
104 diff.tv_usec -= 1000000L; \
112 * ASSUMES the minimum length for ttype and toid.
114 #define USM_LENGTH_OID_TRANSFORM 10
116 #define ISTRANSFORM(ttype, toid) \
117 !snmp_oid_compare(ttype, USM_LENGTH_OID_TRANSFORM, \
118 usm ## toid ## Protocol, USM_LENGTH_OID_TRANSFORM)
120 #define ENGINETIME_MAX 2147483647 /* ((2^31)-1) */
121 #define ENGINEBOOT_MAX 2147483647 /* ((2^31)-1) */
130 int snmp_realloc(u_char ** buf, size_t * buf_len);
132 void free_zero(void *buf, size_t size);
134 u_char *malloc_random(size_t * size);
135 u_char *malloc_zero(size_t size);
136 int memdup(u_char ** to, const u_char * from, size_t size);
138 u_int binary_to_hex(const u_char * input, size_t len,
140 int hex_to_binary2(const u_char * input, size_t len,
143 int snmp_decimal_to_binary(u_char ** buf, size_t * buf_len,
146 const char *decimal);
147 int snmp_hex_to_binary(u_char ** buf, size_t * buf_len,
148 size_t * out_len, int allow_realloc,
150 int snmp_strcat(u_char ** buf, size_t * buf_len,
151 size_t * out_len, int allow_realloc,
153 char *netsnmp_strdup_and_null(const u_char * from,
156 void dump_chunk(const char *debugtoken, const char *title,
157 const u_char * buf, int size);
158 char *dump_snmpEngineID(const u_char * buf, size_t * buflen);
160 typedef void *marker_t;
161 marker_t atime_newMarker(void);
162 void atime_setMarker(marker_t pm);
163 long atime_diff(marker_t first, marker_t second);
164 u_long uatime_diff(marker_t first, marker_t second); /* 1/1000th sec */
165 u_long uatime_hdiff(marker_t first, marker_t second); /* 1/100th sec */
166 int atime_ready(marker_t pm, int deltaT);
167 int uatime_ready(marker_t pm, unsigned int deltaT);
169 int marker_tticks(marker_t pm);
170 int timeval_tticks(struct timeval *tv);
175 #endif /* _TOOLS_H */