Memory Utility Routines
[The Net-SNMP library]


マクロ定義

#define SNMP_MAXPATH   1024
#define SNMP_MAXBUF   (1024 * 4)
#define SNMP_MAXBUF_MEDIUM   1024
#define SNMP_MAXBUF_SMALL   512
#define SNMP_MAXBUF_MESSAGE   1500
#define SNMP_MAXOID   64
#define SNMP_MAX_CMDLINE_OIDS   128
#define SNMP_FILEMODE_CLOSED   0600
#define SNMP_FILEMODE_OPEN   0644
#define BYTESIZE(bitsize)   ((bitsize + 7) >> 3)
#define ROUNDUP8(x)   ( ( (x+7) >> 3 ) * 8 )
#define SNMP_STRORNULL(x)   ( x ? x : "(null)")
#define SNMP_FREE(s)   do { if (s) { free((void *)s); s=NULL; } } while(0)
 Frees a pointer only if it is !NULL and sets its value to NULL
#define SNMP_SWIPE_MEM(n, s)   do { if (n) free((void *)n); n = s; s=NULL; } while(0)
 Frees pointer n only if it is !NULL, sets n to s and sets s to NULL
#define SNMP_MALLOC_STRUCT(s)   (struct s *) calloc(1, sizeof(struct s))
 Mallocs memory of sizeof(struct s), zeros it and returns a pointer to it.
#define SNMP_MALLOC_TYPEDEF(td)   (td *) calloc(1, sizeof(td))
 Mallocs memory of sizeof(t), zeros it and returns a pointer to it.
#define SNMP_ZERO(s, l)   do { if (s) memset(s, 0, l); } while(0)
 Zeros l bytes of memory starting at s.
#define TOUPPER(c)   (c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c)
#define TOLOWER(c)   (c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c)
#define HEX2VAL(s)   ((isalpha(s) ? (TOLOWER(s)-'a'+10) : (TOLOWER(s)-'0')) & 0xf)
#define VAL2HEX(s)   ( (s) + (((s) >= 10) ? ('a'-10) : '0') )
#define SNMP_MAX(a, b)   ((a) > (b) ? (a) : (b))
 Computers the maximum of a and b.
#define SNMP_MIN(a, b)   ((a) > (b) ? (b) : (a))
 Computers the minimum of a and b.
#define SNMP_MACRO_VAL_TO_STR(s)   SNMP_MACRO_VAL_TO_STR_PRIV(s)
 Expands to string with value of the s.
#define SNMP_MACRO_VAL_TO_STR_PRIV(s)   #s
#define FALSE   0
#define TRUE   1
#define QUITFUN(e, l)
#define DIFFTIMEVAL(now, then, diff)
#define USM_LENGTH_OID_TRANSFORM   10
#define ISTRANSFORM(ttype, toid)
#define ENGINETIME_MAX   2147483647
#define ENGINEBOOT_MAX   2147483647

型定義

typedef void * marker_t

関数

int snmp_realloc (u_char **buf, size_t *buf_len)
 This function increase the size of the buffer pointed at by *buf, which is initially of size *buf_len.
void free_zero (void *buf, size_t size)
 zeros memory before freeing it.
u_char * malloc_random (size_t *size)
 Returns pointer to allocaed & set buffer on success, size contains number of random bytes filled.
u_char * malloc_zero (size_t size)
int memdup (u_char **to, const u_char *from, size_t size)
 Duplicates a memory block.
u_int binary_to_hex (const u_char *input, size_t len, char **output)
 converts binary to hexidecimal
int netsnmp_hex_to_binary (u_char **buf, size_t *buf_len, size_t *offset, int allow_realloc, const char *hex, const char *delim)
 convert an ASCII hex string (with specified delimiters) to binary
int snmp_hex_to_binary (u_char **buf, size_t *buf_len, size_t *offset, int allow_realloc, const char *hex)
 convert an ASCII hex string to binary
int hex_to_binary2 (const u_char *input, size_t len, char **output)
 hex_to_binary2
int snmp_decimal_to_binary (u_char **buf, size_t *buf_len, size_t *out_len, int allow_realloc, const char *decimal)
int snmp_strcat (u_char **buf, size_t *buf_len, size_t *out_len, int allow_realloc, const u_char *s)
char * netsnmp_strdup_and_null (const u_char *from, size_t from_len)
 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
void dump_chunk (const char *debugtoken, const char *title, const u_char *buf, int size)
char * dump_snmpEngineID (const u_char *buf, size_t *buflen)
marker_t atime_newMarker (void)
 create a new time marker.
void atime_setMarker (marker_t pm)
 set a time marker.
long atime_diff (marker_t first, marker_t second)
 Returns the difference (in msec) between the two markers
u_long uatime_diff (marker_t first, marker_t second)
 Returns the difference (in u_long msec) between the two markers
u_long uatime_hdiff (marker_t first, marker_t second)
 Returns the difference (in u_long 1/100th secs) between the two markers (functionally this is what sysUpTime needs)
int atime_ready (marker_t pm, int deltaT)
 Test: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).
int uatime_ready (marker_t pm, unsigned int deltaT)
 Test: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).
int marker_tticks (marker_t pm)
 Return the number of timeTicks since the given marker
int timeval_tticks (struct timeval *tv)
char * netsnmp_getenv (const char *name)
 Non Windows: Returns a pointer to the desired environment variable or NULL if the environment variable does not exist.
int netsnmp_addrstr_hton (char *ptr, size_t len)

マクロ定義

#define DIFFTIMEVAL ( now,
then,
diff   ) 

値:

{                                                       \
        now.tv_sec--;                                   \
        now.tv_usec += 1000000L;                        \
        diff.tv_sec  = now.tv_sec  - then.tv_sec;       \
        diff.tv_usec = now.tv_usec - then.tv_usec;      \
        if (diff.tv_usec > 1000000L){                   \
                diff.tv_usec -= 1000000L;               \
                diff.tv_sec++;                          \
        }                                               \
}

tools.h131 行で定義されています。

#define ISTRANSFORM ( ttype,
toid   ) 

値:

tools.h150 行で定義されています。

#define QUITFUN ( e,
 ) 

値:

if ( (e) != SNMPERR_SUCCESS) {  \
                rval = SNMPERR_GENERR;  \
                goto l ;                \
        }

tools.h118 行で定義されています。

#define SNMP_FREE (  )     do { if (s) { free((void *)s); s=NULL; } } while(0)

Frees a pointer only if it is !NULL and sets its value to NULL

tools.h53 行で定義されています。

参照元 _sess_read()build_oid_segment()clear_callback()clear_context()clear_lookup_cache()convert_v2pdu_to_v1()create_user_from_session()dump_chunk()fprint_description()fprint_objid()fprint_value()fprint_variable()free_agent_snmp_session()get_module_node()get_node()get_set_cache()init_mib()netsnmp_addrcache_add()netsnmp_agent_check_packet()netsnmp_agent_check_parse()netsnmp_cache_reqinfo_extract()netsnmp_cache_reqinfo_insert()netsnmp_config_remember_free_list()netsnmp_create_handler()netsnmp_fixup_mib_directory()netsnmp_free_agent_request_info()netsnmp_free_all_list_data()netsnmp_free_cachemap()netsnmp_free_delegated_cache()netsnmp_free_list_data()netsnmp_getenv()netsnmp_handler_free()netsnmp_handler_registration_free()netsnmp_iterator_delete_table()netsnmp_reassign_requests()netsnmp_register_agent_nsap()netsnmp_register_old_api()netsnmp_row_merge_helper_handler()netsnmp_sess_log_error()netsnmp_set_mib_directory()netsnmp_set_row_column()netsnmp_sprint_realloc_objid()netsnmp_sprint_realloc_objid_tree()netsnmp_subtree_free()netsnmp_subtree_join()netsnmp_subtree_split()netsnmp_table_build_oid_from_index()netsnmp_table_data_delete_row()netsnmp_table_data_delete_table()netsnmp_table_data_set_helper_handler()netsnmp_table_dataset_delete_data()netsnmp_tcontainer_create_table()netsnmp_tcontainer_delete_table()netsnmp_tdata_clone_row()netsnmp_tdata_delete_row()netsnmp_tdata_delete_table()netsnmp_wrap_up_request()parse_octet_hint()read_objid()shutdown_mib()snmp_add_var()snmp_free_pdu()snmp_free_var()snmp_sess_close()snmp_unregister_callback()snmpv3_make_report()snmpv3_parse()table_helper_handler()unregister_all_config_handlers()unregister_config_handler()unregister_mibs_by_session().

#define SNMP_MACRO_VAL_TO_STR (  )     SNMP_MACRO_VAL_TO_STR_PRIV(s)

Expands to string with value of the s.

If s is macro, the resulting string is value of the macro. Example: define TEST 1234 SNMP_MACRO_VAL_TO_STR(TEST) expands to "1234" SNMP_MACRO_VAL_TO_STR(TEST+1) expands to "1234+1"

tools.h99 行で定義されています。

#define SNMP_MALLOC_STRUCT (  )     (struct s *) calloc(1, sizeof(struct s))

Mallocs memory of sizeof(struct s), zeros it and returns a pointer to it.

tools.h64 行で定義されています。

参照元 netsnmp_config_remember_in_list()netsnmp_create_subtree_cache()netsnmp_register_callback()snmp_alarm_register()snmp_alarm_register_hr().

#define SNMP_MALLOC_TYPEDEF ( td   )     (td *) calloc(1, sizeof(td))

Mallocs memory of sizeof(t), zeros it and returns a pointer to it.

tools.h68 行で定義されています。

参照元 add_subtree()get_context_lookup_cache()init_agent_snmp_session()netsnmp_baby_steps_handler_get()netsnmp_cache_create()netsnmp_container_get_null()netsnmp_container_iterator_get()netsnmp_container_table_handler_get()netsnmp_create_data_list()netsnmp_create_delegated_cache()netsnmp_create_handler()netsnmp_create_table_data()netsnmp_create_table_data_row()netsnmp_create_table_data_set()netsnmp_create_watcher_info()netsnmp_ds_register_config()netsnmp_ds_register_premib()netsnmp_get_new_stash_cache()netsnmp_get_or_add_local_cachid()netsnmp_get_scalar_group_handler()netsnmp_handler_registration_create()netsnmp_iterator_create_table()netsnmp_mark_row_column_writable()netsnmp_mode_end_call_add_mode_callback()netsnmp_oid_stash_create_sized_node()netsnmp_register_auto_data_table()netsnmp_register_loghandler()netsnmp_register_mib_table_row()netsnmp_register_num_file_instance()netsnmp_register_old_api()netsnmp_register_save_list()netsnmp_register_table_data_set()netsnmp_row_merge_status_get()netsnmp_set_row_column()netsnmp_stash_to_next_helper()netsnmp_table_container_register()netsnmp_table_data_create_row()netsnmp_table_data_set_create_newrowstash()netsnmp_table_data_set_helper_handler()netsnmp_table_iterator_helper_handler()netsnmp_table_set_add_default_row()netsnmp_tcontainer_create_table()netsnmp_tdata_create_row()netsnmp_tdata_create_table()save_set_cache()snmp_varlist_add_variable()table_helper_handler().

#define SNMP_MAX ( a,
 )     ((a) > (b) ? (a) : (b))

Computers the maximum of a and b.

tools.h85 行で定義されています。

参照元 netsnmp_config_parse_table_set()netsnmp_create_subtree_cache()netsnmp_register_table_data_set().

#define SNMP_MIN ( a,
 )     ((a) > (b) ? (b) : (a))

Computers the minimum of a and b.

tools.h89 行で定義されています。

参照元 netsnmp_config_parse_table_set()netsnmp_oid_find_prefix()netsnmp_register_table_data_set()netsnmp_scalar_group_helper_handler()netsnmp_scalar_helper_handler()netsnmp_stash_to_next_helper()netsnmp_table_data_helper_handler().

#define SNMP_SWIPE_MEM ( n,
 )     do { if (n) free((void *)n); n = s; s=NULL; } while(0)

Frees pointer n only if it is !NULL, sets n to s and sets s to NULL

tools.h57 行で定義されています。

#define SNMP_ZERO ( s,
 )     do { if (s) memset(s, 0, l); } while(0)

Zeros l bytes of memory starting at s.

tools.h72 行で定義されています。


関数

long atime_diff ( marker_t  first,
marker_t  second 
)

Returns the difference (in msec) between the two markers

tools.c795 行で定義されています。

参照元 atime_ready()marker_tticks().

marker_t atime_newMarker ( void   ) 

create a new time marker.

NOTE: Caller must free time marker when no longer needed.

tools.c771 行で定義されています。

参照元 atime_ready()marker_tticks()uatime_ready().

int atime_ready ( marker_t  pm,
int  deltaT 
)

Test: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).

tools.c850 行で定義されています。

参照先 atime_diff()atime_newMarker().

参照元 netsnmp_cache_check_expired().

void atime_setMarker ( marker_t  pm  ) 

set a time marker.

tools.c782 行で定義されています。

u_int binary_to_hex ( const u_char *  input,
size_t  len,
char **  output 
)

converts binary to hexidecimal

引数:
*input Binary data.
len Length of binary data.
**output NULL terminated string equivalent in hex.
戻り値:
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.

tools.c287 行で定義されています。

参照先 VAL2HEX.

参照元 dump_chunk().

void free_zero ( void *  buf,
size_t  size 
)

zeros memory before freeing it.

引数:
*buf Pointer at bytes to free.
size Number of bytes in buf.

tools.c185 行で定義されています。

参照元 hex_to_binary2()malloc_random().

int hex_to_binary2 ( const u_char *  input,
size_t  len,
char **  output 
)

hex_to_binary2

引数:
*input Printable data in base16.
len Length in bytes of data.
**output Binary data equivalent to input.
戻り値:
SNMPERR_GENERR on failure, otherwise length of allocated string.
Input of an odd length is right aligned.

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.

tools.c324 行で定義されています。

参照先 free_zero()HEX2VALNULL.

u_char* malloc_random ( size_t *  size  ) 

Returns pointer to allocaed & set buffer on success, size contains number of random bytes filled.

buf is NULL and *size set to KMT error value upon failure.

引数:
size Number of bytes to malloc() and fill with random bytes.
戻り値:
a malloced buffer

tools.c205 行で定義されています。

参照先 free_zero()NULL.

int marker_tticks ( marker_t  pm  ) 

Return the number of timeTicks since the given marker

tools.c898 行で定義されています。

参照先 atime_diff()atime_newMarker().

参照元 timeval_tticks().

int memdup ( u_char **  to,
const u_char *  from,
size_t  size 
)

Duplicates a memory block.

Copies a existing memory location from a pointer to another, newly malloced, pointer.

引数:
to Pointer to allocate and copy memory to.
from Pointer to copy memory from.
size Size of the data to be copied.
戻り値:
SNMPERR_SUCCESS on success, SNMPERR_GENERR on failure.

tools.c236 行で定義されています。

参照先 NULL.

参照元 convert_v2pdu_to_v1()create_user_from_session()netsnmp_handler_registration_create()netsnmp_handler_registration_dup()netsnmp_instance_int_handler()netsnmp_instance_long_handler()netsnmp_instance_num_file_handler()netsnmp_instance_ulong_handler()netsnmp_register_old_api()netsnmp_set_row_column()netsnmp_table_data_clone_row()netsnmp_table_data_copy_row()netsnmp_table_data_set_clone_row()netsnmp_table_set_add_default_row()netsnmp_tdata_clone_row()netsnmp_tdata_copy_row()netsnmp_watcher_helper_handler()send_trap_to_sess()snmpd_parse_config_trapsess().

char* netsnmp_getenv ( const char *  name  ) 

Non Windows: Returns a pointer to the desired environment variable or NULL if the environment variable does not exist.

Windows: Returns a pointer to the desired environment variable if it exists. If it does not, the variable is looked up in the registry in HKCU\Net-SNMP or HKLM\Net-SNMP (whichever it finds first) and stores the result in the environment variable. It then returns a pointer to environment variable.

tools.c926 行で定義されています。

参照先 NULLSNMP_FREE.

参照元 get_configuration_directory()get_persistent_directory()init_mib()netsnmp_fixup_mib_directory()netsnmp_get_mib_directory()read_config_files()read_config_store().

int netsnmp_hex_to_binary ( u_char **  buf,
size_t *  buf_len,
size_t *  offset,
int  allow_realloc,
const char *  hex,
const char *  delim 
)

convert an ASCII hex string (with specified delimiters) to binary

引数:
buf address of a pointer (pointer to pointer) for the output buffer. If allow_realloc is set, the buffer may be grown via snmp_realloc to accomodate the data.
buf_len pointer to a size_t containing the initial size of buf.
offset On input, a pointer to a size_t indicating an offset into buf. The binary data will be stored at this offset. On output, this pointer will have updated the offset to be the first byte after the converted data.
allow_realloc If true, the buffer can be reallocated. If false, and the buffer is not large enough to contain the string, an error will be returned.
hex pointer to hex string to be converted. May be prefixed by "0x" or "0X".
delim point to a string of allowed delimiters between bytes. If not specified, any non-hex characters will be an error.
戻り値:
1 success
0 error

tools.c425 行で定義されています。

参照先 NULLsnmp_realloc().

参照元 snmp_hex_to_binary().

char* netsnmp_strdup_and_null ( const u_char *  from,
size_t  from_len 
)

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

tools.c255 行で定義されています。

参照先 NULL.

参照元 netsnmp_table_data_set_helper_handler().

int snmp_hex_to_binary ( u_char **  buf,
size_t *  buf_len,
size_t *  offset,
int  allow_realloc,
const char *  hex 
)

convert an ASCII hex string to binary

覚え書き:
This is a wrapper which calls netsnmp_hex_to_binary with a delimiter string of " ".
See netsnmp_hex_to_binary for parameter descriptions.

戻り値:
1 success
0 error

tools.c485 行で定義されています。

参照先 netsnmp_hex_to_binary().

参照元 create_user_from_session()snmp_add_var().

int snmp_realloc ( u_char **  buf,
size_t *  buf_len 
)

This function increase the size of the buffer pointed at by *buf, which is initially of size *buf_len.

Contents are preserved **AT THE BOTTOM END OF THE BUFFER**. If memory can be (re-)allocated then it returns 1, else it returns 0.

引数:
buf pointer to a buffer pointer
buf_len pointer to current size of buffer in bytes
覚え書き:
The current re-allocation algorithm is to increase the buffer size by whichever is the greater of 256 bytes or the current buffer size, up to a maximum increase of 8192 bytes.

tools.c121 行で定義されています。

参照先 NULL.

参照元 _sprint_hexstring_line()asn_realloc()dump_realloc_oid_to_string()netsnmp_hex_to_binary()snmp_add_var()snmp_decimal_to_binary()snmp_strcat()sprint_realloc_asciistring()sprint_realloc_ipaddress()sprint_realloc_networkaddress()sprint_realloc_octet_string().

u_long uatime_diff ( marker_t  first,
marker_t  second 
)

Returns the difference (in u_long msec) between the two markers

tools.c812 行で定義されています。

参照元 uatime_ready().

u_long uatime_hdiff ( marker_t  first,
marker_t  second 
)

Returns the difference (in u_long 1/100th secs) between the two markers (functionally this is what sysUpTime needs)

tools.c830 行で定義されています。

参照元 netsnmp_marker_uptime().

int uatime_ready ( marker_t  pm,
unsigned int  deltaT 
)

Test: Has (marked time plus delta) exceeded current time (in msec) ? Returns 0 if test fails or cannot be tested (no marker).

tools.c872 行で定義されています。

参照先 atime_newMarker()uatime_diff().


net-snmpに対してSat Sep 5 13:14:30 2009に生成されました。  doxygen 1.4.7