Ejemplo n.º 1
0
/**
 * repad_net_init - Initialize all structures used to receive packets from network
 *
 * @param id	The id of thread which call this function
 *
 * @return	<0 for errors
 */
static int repad_net_init(long id) {
	int result_raw = 0, result_udp = 0, result_overlay = 0;

	repad_attr.th_network_threads[TH_RAW_SOCKET] = 0;
	repad_attr.th_network_threads[TH_UDP_SOCKET] = 0;
	repad_attr.th_network_threads[TH_OVERLAY_NET] = 0;

	/* Create a new prod_cons for receive packets from network */
	repad_attr.pc_receive_packets = pc_create(10, NULL, NULL, NULL,
			(void(*)(void*))skb_release);
	if (repad_attr.pc_receive_packets == NULL) {
		repad_printf(LOG_INFO, "Th%ld: ERROR: On create prod_cons for received packets\n");
		return -1;
	}

	/* Create HashMap for memory message */
	repad_attr.hm_memory_message = hmap_create(hmap_hash_mem_fn,
			hmap_eq_mem_fn, NULL, (void (*)(hmap_key_t))dll_destroy_all, 0, 0.0);
	if (repad_attr.hm_memory_message == NULL) {
		repad_printf(LOG_INFO, "Th%ld: ERROR: On create map for memory message\n");
		return -1;
	}

	/* Create list of packet with no match */
	repad_attr.list_pkt_without_match = dll_create(upwm_compare_packet, NULL);
	if (repad_attr.list_pkt_without_match == NULL) {
		repad_printf(LOG_INFO, "Th%ld: ERROR: On create list for packets without match\n");
		return -1;
	}

	/* Load ifaces informations */
	load_all_ifaces_info(&repad_attr.list_all_ifaces);
	repad_printf(LOG_INFO, "Th%ld: It was found %d interface(s)...\n",
				id, dll_get_num_elements(repad_attr.list_all_ifaces));

	/* Init raw socket */
	repad_printf(LOG_INFO, "Th%ld: raw_socket_enable=%s - udp_socket_enable=%s"
			" - overlay_enable=%s\n", id,
			strbool(repad_attr.bl_raw_socket_enable),
			strbool(repad_attr.bl_udp_socket_enable),
			strbool(repad_attr.bl_overlay_enable));
	if (repad_attr.bl_raw_socket_enable) {
		result_raw = repad_net_init_raw_socket(id);
	}

	/* Init UDP socket */
	if (repad_attr.bl_udp_socket_enable) {
		result_udp = repad_net_init_udp_socket(id);
	}

	/* Init overlay */
	if (repad_attr.bl_overlay_enable) {
		result_overlay = repad_net_init_overlay(id);
	}

	return ((result_raw >= 0) ? 0 :
			(result_udp >= 0) ? 0 :
			(result_overlay >= 0) ? 0 : -1);
}
int main (int argc, char **argv) {
    options opts;
    program_name = basename (argv[0]);
    scan_options (argc, argv, &opts);
    printf ("ignore_case = %s\n", strbool (opts.ignore_case));
    printf ("filenames_only = %s\n", strbool (opts.filenames_only));
    printf ("number_lines = %s\n", strbool (opts.number_lines));
    for (int argi = optind; argi < argc; ++argi) {
        printf ("operand[%d] = \"%s\"\n", argi, argv[argi]);
    }
    return exit_status;
}