static void check_uint32_wrapper(void) { int ret; hi_handle_t *hi_handle; uint32_t key = 23; int data = 666, *val; void *data_ptr; fputs(" o check uint32_t wrapper functions tests ...", stdout); ret = hi_init_uint32_t(&hi_handle, 23); assert(ret == 0); for (key = 0; key < 23; key++) { ret = hi_insert_uint32_t(hi_handle, key, &data); assert(ret == 0); ret = hi_get_uint32_t(hi_handle, key, &data_ptr); assert(ret == 0); val = data_ptr; assert(*val == data); } ret = hi_fini(hi_handle); assert(ret == 0); puts(" passed"); }
int oui_hash_init(void) { uint32_t a; int rc; if ((rc = hi_init_uint32_t(&oui_hash_handle, ARRAY_SIZE(vendor_db))) != 0) { err("Could not initialize OUI hash table"); return (rc); } for (a = 0; a < ARRAY_SIZE(vendor_db); a++) { if ((rc = hi_insert_uint32_t(oui_hash_handle, vendor_db[a].id, vendor_db[a].vendor)) != 0) { oui_hash_destroy(); err("Could not insert OUI hash table"); return (rc); } } return(0); }
int main (int argc, char *argv[]) { char opt; /* short options: character */ char optstr[] = "hp:c:P:r:stuvlf:"; int port; /* port number */ int cport = 4740; /* target collector port number */ int protocol = IPFIX_PROTO_TCP; int do_log = 0; /* flag to stre whether logging to stdout was enabled */ /** set default options */ port = 4739; datadir = NULL; snprintf( progname, sizeof(progname), "%s", basename( argv[0]) ); /* --- command line parsing --- */ int cisset = 0; while( ( opt = getopt( argc, argv, optstr ) ) != EOF ) { switch ( opt ) { case 'o': if ((sourceid=atoi(optarg)) <0) { fprintf( stderr, "Invalid -o argument!\n" ); exit(1); } break; case 'p': if ((port=atoi(optarg)) <0) { fprintf( stderr, "Invalid -p argument!\n" ); exit(1); } break; case 'v': verbose_level ++; break; case 'l': do_log = 1; break; case 'P': if ((cport=atoi(optarg)) <0) { fprintf( stderr, "Invalid -P argument!\n" ); exit(1); } break; case 'r': if ((degrade=atoi(optarg)) <0) { fprintf( stderr, "Invalid -r argument!\n" ); exit(1); } break; case 'c': if (chost) free(chost); /* executed in case of multiple "-c <collectorhost>" */ chost = strdup(optarg); cisset = 1; break; case 'f': if (datadir) free(datadir); /* executed in case of multiple "-f <datadir>" */ datadir = strdup(optarg); break; case 's': protocol = IPFIX_PROTO_SCTP; break; case 't': protocol = IPFIX_PROTO_TCP; break; case 'u': protocol = IPFIX_PROTO_UDP; break; case 'h': default: usage(progname); exit(1); } } if (!chost && !datadir && !do_log) { fprintf( stderr, "You must specify either an IPFIX target collector host or a datadir or enable log to stdout. Type option '-h' for help.\n"); exit(1); } /** init hashtable structures */ hi_init_uint32_t(&indegree, 1000); hi_init_uint32_t(&outdegree, 1000); hi_init_uint32_t(&flows, 1000); hi_init_str (&templates, 100); /** init logging */ mlog_set_vlevel( verbose_level ); /** init ipfix lib */ if ( ipfix_init() <0 ) { fprintf( stderr, "ipfix_init() failed: %s\n", strerror(errno) ); exit(1); } if ( ipfix_add_vendor_information_elements( ipfix_ft_fokus ) <0 ) { fprintf( stderr, "ipfix_add_ie() failed: %s\n", strerror(errno) ); exit(1); } /** init ipfix import/export */ if ( ipfix_open( &ipfixh, sourceid, IPFIX_VERSION ) <0 ) { fprintf( stderr, "ipfix_open() failed: %s\n", strerror(errno) ); exit(1); } /** signal handler */ signal( SIGKILL, exit_func ); signal( SIGTERM, exit_func ); signal( SIGINT, exit_func ); /** initialize callback methods */ /** activate stdout log output * if "-l" was specified on cmd line */ if (do_log) { (void) ipfix_col_start_msglog( stdout ); } /** activate file export * if "-f <datadir>" was specified on cmd line */ if (datadir) { (void) ipfix_col_init_fileexport( datadir ); } if (chost) { if ( ipfix_add_collector( ipfixh, chost, cport, protocol ) <0 ) { fprintf( stderr, "ipfix_add_collector(%s,%d) failed: %s\n", chost, cport, strerror(errno)); exit(1); } /** activate callback for re-export */ if ( (g_colinfo=calloc( 1, sizeof(ipfix_col_info_t))) ==NULL) { fprintf( stderr, "a calloc failed while initializing callback methods.\n" ); return -1; } g_colinfo->export_newsource = export_newsource_cb; g_colinfo->export_newmsg = export_newmsg_cb; g_colinfo->export_trecord = export_trecord_cb; g_colinfo->export_drecord = export_drecord_cb; g_colinfo->export_cleanup = export_cleanup_cb; g_colinfo->data = NULL; if ( ipfix_col_register_export( g_colinfo ) <0 ) { fprintf( stderr, "ipfix_col_register_export() failed: %s\n", strerror(errno) ); exit(1); } } /** open ipfix collector port(s) */ if ( ipfix_col_listen( &ntcp_s, &tcp_s, IPFIX_PROTO_TCP, port, AF_INET, 10 ) <0 ) { fprintf( stderr, "[%s] ipfix_listen(tcp) failed.\n", progname ); return -1; } /** event loop */ (void) mpoll_loop( -1 ); exit(1); }