Example #1
0
/*
 * Initialize anything that must be initialized before dissecting
 * packets.
 *
 * This should be called at the beginning of the program; it does
 * not need to be called, and should not be called, for every
 * netdissect_options structure.
 */
int
nd_init(char *errbuf, size_t errbuf_size)
{
#ifdef _WIN32
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	/*
	 * Request Winsock 2.2; we expect Winsock 2.
	 */
	wVersionRequested = MAKEWORD(2, 2);
	err = WSAStartup(wVersionRequested, &wsaData);
	if (err != 0) {
		strlcpy(errbuf, "Attempting to initialize Winsock failed",
		    errbuf_size);
		return (-1);
	}
#endif /* _WIN32 */

#ifdef USE_LIBSMI
	/*
	 * XXX - should we just fail if this fails?  Some of the
	 * libsmi calls may fail.
	 */
	smiInit("tcpdump");
#endif

	/*
	 * Clears the error buffer, and uses it so we don't get
	 * "unused argument" warnings at compile time.
	 */
	strlcpy(errbuf, "", errbuf_size);
	return (0);
}
Example #2
0
/*
 * 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.
 */
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);
}