예제 #1
0
파일: tap.c 프로젝트: jimbelton/jools
void
tap_plan(unsigned tests, unsigned flags, FILE * output)
{
    LOCK;

    tap_flags = flags;
    tap_init(output != NULL ? output : stdout);

    if (have_plan != 0) {
        fprintf(stderr, "You tried to plan twice!\n");
        test_died = 1;
        UNLOCK;
        exit(255);
    }

    if (tests == 0) {
        fprintf(stderr, "You said to run 0 tests!  You've got to run something.\n");
        test_died = 1;
        UNLOCK;
        exit(255);
    }

    have_plan = 1;
    _expected_tests(tests);

    UNLOCK;
}
예제 #2
0
int
network_plt_init(void)
{ 
    if (config.network_type == NetworkType_IPTunnelling) {
        error("IP Tunnelling networking is not supported on Windows");
        return 0;
    }

    if (config.bridgename == NULL) {
        error("Bridge name not configured");
        return 0;
    }

    if (config.macaddress) {
        /* Parse supplied MAC address */
        if (!network_macaddress_parse(config.macaddress, network_hwaddr)) {
            error("Unable to parse '%s' as a MAC address", config.macaddress);
            return 0;
        }
    } else {
        network_hwaddr[0] = 0x06;
        network_hwaddr[1] = 0x02;
        network_hwaddr[2] = 0x03;
        network_hwaddr[3] = 0x04;
        network_hwaddr[4] = 0x05;
        network_hwaddr[5] = 0x06;
    }

    tap_handle = tap_init(config.bridgename);
    if (tap_handle == NULL) {
        return 0;
    } else {
        return 1;
    }
}
예제 #3
0
파일: tap.c 프로젝트: jimbelton/jools
static int
diagv(const char *fmt, va_list ap)
{
    int len;

    tap_init(stdout);
    fputs("# ", tap_out);
    len = vfprintf(tap_out, fmt, ap);
    fputs("\n", tap_out);

    return len + 3;
}
예제 #4
0
파일: tap.c 프로젝트: jimbelton/jools
/*
 * Note that the plan is to skip all tests
 */
void
plan_skip_all(const char * reason)
{
    LOCK;

    tap_init(stdout);
    skip_all = 1;

    fprintf(tap_out, "1..0");

    if(reason != NULL) {
        fprintf(tap_out, " # Skip %s", reason);
    }

    fprintf(tap_out, "\n");
    UNLOCK;
}
예제 #5
0
void
epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
	  void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
	  register_cb cb,
	  gpointer client_data,
	  void (*report_failure)(const char *, va_list),
	  void (*report_open_failure)(const char *, int, gboolean),
	  void (*report_read_failure)(const char *, int),
	  void (*report_write_failure)(const char *, int))
{
	init_report_err(report_failure, report_open_failure,
	    report_read_failure, report_write_failure);

	/* initialize memory allocation subsystem */
	ep_init_chunk();
	se_init_chunk();

	/* initialize the GUID to name mapping table */
	guids_init();

	except_init();
#ifdef HAVE_LIBGNUTLS
	gnutls_global_init();
#elif defined(HAVE_LIBGCRYPT)
	gcry_check_version(NULL);
#endif
	tvbuff_init();
	tap_init();
	prefs_init();
	proto_init(register_all_protocols_func, register_all_handoffs_func,
	    cb, client_data);
	packet_init();
	dfilter_init();
	final_registration_all_protocols();
	host_name_lookup_init();
	expert_init();
	oids_init();
#ifdef HAVE_LUA_5_1
	wslua_init(NULL);
#endif
#ifdef HAVE_GEOIP
	geoip_db_init();
#endif

}
예제 #6
0
void
epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
          void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
          register_cb cb,
          gpointer client_data,
          void (*report_failure_fcn_p)(const char *, va_list),
          void (*report_open_failure_fcn_p)(const char *, int, gboolean),
          void (*report_read_failure_fcn_p)(const char *, int),
          void (*report_write_failure_fcn_p)(const char *, int))
{
    init_report_err(report_failure_fcn_p, report_open_failure_fcn_p,
                    report_read_failure_fcn_p, report_write_failure_fcn_p);

    /* initialize memory allocation subsystems */
    emem_init();
    wmem_init();

    /* initialize the GUID to name mapping table */
    guids_init();

    except_init();
#ifdef HAVE_LIBGCRYPT
    /* initialize libgcrypt (beware, it won't be thread-safe) */
    gcry_check_version(NULL);
    gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
    gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
#ifdef HAVE_LIBGNUTLS
    gnutls_global_init();
#endif
    tap_init();
    prefs_init();
    expert_init();
    proto_init(register_all_protocols_func, register_all_handoffs_func,
               cb, client_data);
    packet_init();
    dfilter_init();
    final_registration_all_protocols();
    /*host_name_lookup_init();*//* We load the hostname file in cf_open, no need to do it here? */
    expert_packet_init();
#ifdef HAVE_LUA
    wslua_init(cb, client_data);
#endif
}
예제 #7
0
파일: tap.c 프로젝트: jimbelton/jools
/*
 * Note that there's no plan.
 */
void
plan_no_plan(void)
{

    LOCK;

    tap_init(stdout);

    if(have_plan != 0) {
        fprintf(stderr, "You tried to plan twice!\n");
        test_died = 1;
        UNLOCK;
        exit(255);
    }

    have_plan = 1;
    no_plan = 1;

    UNLOCK;
}
예제 #8
0
파일: tape.c 프로젝트: SMTDDR/droidsound
/* FIXME: This should be passed through a struct.  */
int tape_init(const tape_init_t *init)
{
    if (tape_log == LOG_ERR) {
        tape_log = log_open("Tape");
    }

    tape_internal_init();
    tape_image_init();

    lib_free(tape_image_dev1);
    tape_image_dev1 = lib_calloc(1, sizeof(tape_image_t));

    tap_init(init);

    tape_init_vars(init);
    tape_traps_install();

    tape_is_initialized = 1;
    return 0;
}
예제 #9
0
파일: output_tap.c 프로젝트: elfixit/pom-ng
int addon_tap_init(struct addon_plugin *a) {

	struct output_tap_priv *priv = tap_init();
	if (!priv)
		return POM_ERR;

	addon_plugin_set_priv(a, priv);

	if (addon_plugin_add_param(a, "ifname", "pom0", priv->p_ifname) != POM_OK)
		goto err;

	if (addon_plugin_add_param(a, "persistent", "no", priv->p_persistent) != POM_OK)
		goto err;

	return POM_OK;

err:
	output_tap_cleanup(priv);

	return POM_ERR;
}
예제 #10
0
void
epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
	  void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
	  register_cb cb,
	  gpointer client_data)
{
	/* initialize memory allocation subsystem */
	wmem_init();

	/* initialize the GUID to name mapping table */
	guids_init();

        /* initialize name resolution (addr_resolv.c) */
        addr_resolv_init();

	except_init();
#ifdef HAVE_LIBGCRYPT
	/* initialize libgcrypt (beware, it won't be thread-safe) */
	gcry_check_version(NULL);
	gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
	gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
#ifdef HAVE_LIBGNUTLS
	gnutls_global_init();
#endif
	tap_init();
	prefs_init();
	expert_init();
	packet_init();
	proto_init(register_all_protocols_func, register_all_handoffs_func,
	    cb, client_data);
	packet_cache_proto_handles();
	dfilter_init();
	final_registration_all_protocols();
	print_cache_field_handles();
	expert_packet_init();
#ifdef HAVE_LUA
	wslua_init(cb, client_data);
#endif
}
예제 #11
0
파일: output_tap.c 프로젝트: elfixit/pom-ng
int output_tap_init(struct output *o) {

	struct output_tap_priv *priv = tap_init();

	if (!priv)
		return POM_ERR;

	output_set_priv(o, priv);

	struct registry_instance *inst = output_get_reg_instance(o);
	priv->perf_pkts_out = registry_instance_add_perf(inst, "pkts_out", registry_perf_type_counter, "Number of packets processed", "pkts");
	priv->perf_bytes_out = registry_instance_add_perf(inst, "bytes_out", registry_perf_type_counter, "Number of bytes processed", "bytes");

	if (!priv->perf_pkts_out || !priv->perf_bytes_out)
		goto err;

	struct registry_param *p = registry_new_param("ifname", "pom0", priv->p_ifname, "Name of the interface to create", 0);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	p = registry_new_param("persistent", "no", priv->p_persistent, "Create a persistent interface", 0);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	p = registry_new_param("filter", "", priv->p_filter, "Filter", REGISTRY_PARAM_FLAG_NOT_LOCKED_WHILE_RUNNING);
	if (output_add_param(o, p) != POM_OK)
		goto err;

	registry_param_set_callbacks(p, priv, output_tap_filter_parse, output_tap_filter_update);
	
	return POM_OK;
err:
	output_tap_cleanup(priv);
	return POM_ERR;

}
예제 #12
0
파일: epan.c 프로젝트: crondaemon/wireshark
gboolean
epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
	  void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
	  register_cb cb,
	  gpointer client_data)
{
	volatile gboolean status = TRUE;

	/* initialize memory allocation subsystem */
	wmem_init();

	/* initialize the GUID to name mapping table */
	guids_init();

	/* initialize name resolution (addr_resolv.c) */
	addr_resolv_init();

	except_init();
#ifdef HAVE_LIBGCRYPT
	/* initialize libgcrypt (beware, it won't be thread-safe) */
	gcry_check_version(NULL);
	gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
	gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
#endif
#ifdef HAVE_LIBGNUTLS
	gnutls_global_init();
#endif
	TRY {
		tap_init();
		prefs_init();
		expert_init();
		packet_init();
		capture_dissector_init();
		proto_init(register_all_protocols_func, register_all_handoffs_func,
		    cb, client_data);
		packet_cache_proto_handles();
		dfilter_init();
		final_registration_all_protocols();
		print_cache_field_handles();
		expert_packet_init();
		export_pdu_init();
#ifdef HAVE_LUA
		wslua_init(cb, client_data);
#endif
	}
	CATCH(DissectorError) {
		/*
		 * This is probably a dissector, or something it calls,
		 * calling REPORT_DISSECTOR_ERROR() in a registration
		 * routine or something else outside the normal dissection
		 * code path.
		 */
		const char *exception_message = GET_MESSAGE;
		static const char dissector_error_nomsg[] =
		    "Dissector writer didn't bother saying what the error was";

		report_failure("Dissector bug: %s",
			       exception_message == NULL ?
				 dissector_error_nomsg : exception_message);
		if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
			abort();
		status = FALSE;
	}
	ENDTRY;
	return status;
}
예제 #13
0
파일: phost.c 프로젝트: Milstein/trema
int main(int argc, char **argv)
{
    char dev_if[16];
    int opt;
    int err = 0;
    int daemonize = 0;
    int log_level = LOG_WARN;
    char *log_file = NULL;

    memset(dev_if, '\0', sizeof(dev_if));
    strncpy(dev_if, PHOST_DEFAULT_TAP_DEVICE, sizeof(dev_if) - 1);

    phost_set_program_name(basename(argv[0]));

    /* parse options */
    while(1){
        opt = getopt(argc, argv, "Dd:i:p:l:n:v");
        if(opt < 0){
            break;
        }

        switch(opt){
        case 'D':
            daemonize = 1;
            break;
        case 'd':
            if(optarg){
                if(atoi(optarg) < LOG_LEVEL_MAX){
                    log_level = atoi(optarg);
                }
                else{
                    phost_print_usage();
                    exit(1);
                }
            }
            else{
                err |= 1;
            }
            break;
        case 'i':
            if(optarg){
                memset(dev_if, '\0', sizeof(dev_if));
                strncpy(dev_if, optarg, sizeof(dev_if) - 1);
            }
            else{
                err |= 1;
            }
            break;
        case 'p':
            if(optarg){
                memset(pid_dir, '\0', sizeof(pid_dir));
                strncpy(pid_dir, optarg, sizeof(pid_dir) - 1);
            }
            else{
                err |= 1;
            }
            break;
        case 'l':
            if(optarg){
                memset(log_dir, '\0', sizeof(log_dir));
                strncpy(log_dir, optarg, sizeof(log_dir) - 1);
            }
            else{
                err |= 1;
            }
            break;
        case 'n':
            if(optarg){
                memset(host_name, '\0', sizeof(host_name));
                strncpy(host_name, optarg, sizeof(host_name) - 1);
            }
            else{
                err |= 1;
            }
            break;
        case 'v':
            log_file = LOG_OUT_STDOUT;
            log_level = LOG_DEBUG;
            break;
        default:
            err |= 1;
        }
    }

    if(err){
        phost_print_usage();
        exit(1);
    }

    if(log_file == NULL){
        log_file = (char*)malloc(sizeof(char)*(strlen(log_dir)+strlen(PHOST_LOG_FILE)+strlen(dev_if)+3));
        sprintf(log_file, "%s/%s.%s", log_dir, PHOST_LOG_FILE, dev_if);
    }

    /* check if this process is run with root privilege */
    if(getuid() != 0){
        fprintf(stderr, "[ERROR] `%s' must be run with root privilege.\n", program_name);
        exit(1);
    }

    /* register signal handler */
    signal(SIGINT, phost_handle_signals);
    signal(SIGTERM, phost_handle_signals);
    signal(SIGPIPE, SIG_IGN);
    signal(SIGUSR1, SIG_IGN);
    signal(SIGUSR2, SIG_IGN);

    /* initializations */
    if(log_init(log_level, log_file) < 0){
        fprintf(stderr, "[ERROR] cannot initialize logger.\n");
        exit(1);
    }

    if(daemonize && (phost_daemonize() < 0)){
        fprintf(stderr, "[ERROR] cannot daemonize.\n");
        exit(1);
    }

    if(strncmp(dev_if, "tap", 3) != 0){
        if(ethdev_init(dev_if) < 0){
            fprintf(stderr, "[ERROR] cannot initialize Ethernet device (%s).\n", dev_if);
            exit(1);
        }
        trx_init(ethdev_read, ethdev_send);
    }
    else{
        if(tap_init(dev_if) < 0){
            fprintf(stderr, "[ERROR] cannot create tap device (%s).\n", dev_if);
            exit(1);
        }
        trx_init(tap_read, tap_send);
    }

    phost_set_global_params();
    phost_create_pid_file(host_name);

    cmdif_init(dev_if, stats_udp_send_update);
    arp_init(host_mac_addr, host_ip_addr);
    ipv4_init(host_ip_addr, host_ip_mask);
    udp_init(stats_udp_recv_update);

    pkt_dump = (char*)malloc(sizeof(char)*PKT_BUF_SIZE*2);

    while(run){
        phost_run();
        cmdif_run();
        arp_age_entries();
    }

    free(pkt_dump);

    cmdif_close();
    tap_close();
    phost_delete_pid_file(host_name);
    phost_unset_global_params();
    log_close();

    return 0;
}