Module: SNMP::SMI

Defined in:
ext/smi.c

Instance Method Summary collapse

Instance Method Details

#load_smi_moduleObject

Reads the named file as an SMI module. Returns an array containing the module name and a Hash with OID symbols as keys and the numeric OIDs as values.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'ext/smi.c', line 45

static VALUE
fsmi_load_smi_module(VALUE self, VALUE filename)
{
  int init_ret;
  char* load_ret;
  char* cfilename;
  SmiModule* module;
  VALUE module_name;
  VALUE oid_hash;

  init_ret = smiInit(NULL); 
  if (init_ret != 0) {
    rb_raise(rb_eRuntimeError, "libsmi init error: %d", init_ret);
  }
  
  cfilename = STR2CSTR(filename);
  load_ret = smiLoadModule(cfilename);
  
  if (load_ret == NULL) {
    rb_raise(rb_eRuntimeError, "%s for module '%s'", strerror(errno), cfilename);
  }
  
  module = smiGetFirstModule();
  if (module == NULL) {
      rb_raise(rb_eRuntimeError, "No module found in %s", cfilename);
  }
  
  module_name = rb_str_new2(module->name);
  oid_hash = get_oid_hash(module);
  
  return rb_ary_new3(2, module_name, oid_hash);
}