Beispiel #1
0
// newUri creates a session from a parsed uri.
func newUri(uri string, version SnmpVersion, parsed_uri *_Ctype_GURI) (session *_Ctype_GNetSnmp, err error) {
	var gerror *C.GError
	session = C.gnet_snmp_new_uri(parsed_uri, &gerror)

	// error handling
	if gerror != nil {
		err_string := C.GoString((*_Ctype_char)(gerror.message))
		C.g_clear_error(&gerror)
		return session, fmt.Errorf("%s: %s", libname(), err_string)
	}
	if session == nil {
		return session, fmt.Errorf("%s: unable to create session", libname())
	}
	session.version = (_Ctype_GNetSnmpVersion)(version)

	// results
	return session, nil
}
Beispiel #2
0
// newUri creates a session from a parsed uri.
func newUri(params *QueryParams, parsed_uri *_Ctype_GURI) (session *_Ctype_GNetSnmp, err error) {

	var gerror *C.GError
	session = C.gnet_snmp_new_uri(parsed_uri, &gerror)

	// error handling
	if gerror != nil {
		err_string := C.GoString((*_Ctype_char)(gerror.message))
		C.g_clear_error(&gerror)
		return session, fmt.Errorf("%s: newUri(): %s", libname(), err_string)
	}
	if session == nil {
		return session, fmt.Errorf("%s: newUri(): unable to create session", libname())
	}

	if params.Version == GNET_SNMP_V1 { // default in library is v2c
		C.gnet_snmp_set_version(session, 0)
	}
	C.gnet_snmp_set_timeout(session, (_Ctype_guint)(params.Timeout))
	C.gnet_snmp_set_retries(session, (_Ctype_guint)(params.Timeout))

	return session, nil
}